Hi!
As you might know, I'm making a tank action game. It's progressing very fast, thanks to this exellent engine (and excellent help here). I can drive around (the tank follows the terrain), shot at the other tanks and so on. Each tank is made up of three visible Shapes3D (and some invisible, but that doesn't matter): hull, turret and barrel. The turret can rotate around the Y-axis and the barrel can rotate around it's mount in the turret. There might be more later on such as rotating radars or I don't know. When a bullet comes near a tank (tested at the outermost TransformGroup) I test it first against every shapes bounds and then it's geometry, like this: (it is a method in the Tank class)
Before this I have tested against each nearby tanks bounds and sorted them so the nearest is tested first.
public boolean intersects(Ray3f ray, float distSq, HitResult res) {
Triangle tri = new Triangle();
Ray3f transRay = Ray3f.fromPool();
PickResult pr = new PickResult(hull, distSq);
transRay.set( ray );
pr.transform( transRay );
if (hull.getWorldBounds().intersects(ray) && game.picker.testGeometryIntersection(pr, transRay, distSq, tri) > 0) {
Ray3f.toPool(transRay);
res.setShape(hull);
res.setLocation("hull");
res.setTarget(this);
return true;
}
pr = new PickResult(turret, distSq);
transRay.set( ray );
pr.transform( transRay );
if (turret.getWorldBounds().intersects(ray) && game.picker.testGeometryIntersection(pr, transRay, distSq, tri) > 0) {
Ray3f.toPool(transRay);
res.setShape(turret);
res.setTarget(this);
res.setLocation("turret");
return true;
}
pr = new PickResult(barrel, distSq);
transRay.set( ray );
pr.transform( transRay );
if (barrel.getWorldBounds().intersects(ray) && game.picker.testGeometryIntersection(pr, transRay, distSq, tri) > 0) {
res.setShape(barrel);
res.setTarget(this);
res.setLocation("barrel");
Ray3f.toPool(transRay);
return true;
}
Ray3f.toPool(transRay);
return false;
}
With the HitResult object I get what part of the tank is hit, hull turret or barrel. But I also want to know if it was front, side, rear, top or bottom (because they have different armour). How should I do it?
* Do some math with the intersected face normal. This works half way, some details may have normals facing sideways even if they are on the front (or something).
* Split the model (I'm using wings 3d) into different sections. I guess I can live with three different areas: front, side and back. But it will still be 3 shapes for the hull and 3 for the turret. The barrel will count as side I think. It will be a lot of shapes. But it is my best guess so far.
Any more clever ideas? Can I set a material in the editor on a face level and read this somehow?