Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

11991 Posts in 1587 Topics- by 3508 Members - Latest Member: PienueDut

26. May 2012, 10:04:01 am
Xith3D CommunityGeneral CategorySupport (Moderator: Marvin Fröhlich)Hit locations
Pages: [1]
Print
Author Topic: Hit locations  (Read 392 times)
Gunslinger
Enjoying the stay
*
Offline Offline

Posts: 44


View Profile
« on: 04. February 2009, 12:54:35 pm »

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.

Code:
   
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?
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4381


May the 4th, be with you...


View Profile
« Reply #1 on: 04. February 2009, 02:30:54 pm »

I guess, the simplest way would be to compute the quadrant of the BoundingSphere, the ray is intersecting. Then you can say, if it is front, back, side, etc.

Can I set a material in the editor on a face level and read this somehow?

No. That's not possible in OpenGL. You can only set vertex colors or one material for the whole shape.

Marvin
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic