jME Collision -- Getting Collision Normals

I’m having a hard time figuring out how the collision detection in jME works. Right now I can detect collisions but what I really need for the proper collision response is the normal at the point of collision on the target.

Right now I’m using CalculateCollisions which populates CollisionResults. From here I’m not sure what to do.

The JavaDocs for CollisionResults are pretty weak.

My guess is to iterate through the results. For each collision use getTargetTris() to get an ArrayList of the triangles that were hit by the source object.

Here’s where I get stuck. What is the ArrayList made up of? Spatial? Triangles? Can I get the normals for the triangles easily?

Here’s what I’ve tried but it seems like I’m not getting any triangles even though a collision is detected.

   results = new TriangleCollisionResults() {
      public void processCollisions() {
         if (getNumber() > 0) {
            System.out.println("Num: " + getNumber());
            ArrayList triangles = new ArrayList();
            if((triangles = getCollisionData(0).getTargetTris()) == null){
               System.out.println("Null collision data");
               System.out.println("Triangles size: " + triangles.size()); //Triangles size is always 0
               for(int i=0; i<triangles.size(); ++i){
                  Triangle t = (Triangle)triangles.get(i);
            ship.velocity.x = ship.velocity.x * -1;
            ship.velocity.z = ship.velocity.z * -1;
         } else {

Thanks for any help!

oh… ://

Yes, its weird. Maybe its a limitation of the algo like mojo said, but how "small" of triangles are we talking? because it might be a rounding error. (I never got the problem personally…)


Weird! :?

You misunderstand me DP. I said that this is curious, because it’s the same problem seen in ODE collision.

It makes me wonder if it’s a limitation of the collision algorithm, and both we and ODE use the same alogrithm.

Thats an ODE limitation, it shouldn’t be a jme limitation. ODE has its own collision system where we have to send it the vertex data for it to solve collisions.

Maybe its float rounding problems that the problem?


You are somewhat treading on new territory here, as the collision stuff is new enough that there hasn’t been a lot of testing.

The interesting thing you mention is the size of the triangle affecting things. People were running into this same issue with ODE collisions. Smaller triangles - Good, larger - Bad. No idea why.

okay doke … I changed the dimensions on the box and the problem went away. I have an idea as what I was doing wrong but need to look into it a little more.

I took a look at the demo that does triangle level collision detection and managed to get mine working somewhat. Unless I’m doing something really odd there seems to be a bug.

I have a pyramid which is my ship and then some random boxes that you can fly around and bounce off of. For the biggest box, you can sometimes fly right through the box if you approach it at the right angle and at the right spot.

For the most part the collision detection works but for some reason at this one part of the box no collisions are being detected. It’s almost like one of the triangles on the box isn’t there.

Has anyone experienced this problem before??

Normally I know its something with my code but I don’t see how my code would allow the ship to fly through one of the triangles on the box.

Here’s the snippet of code where I do the check

   ship.findCollisions(rootNode, results);

   if (results.getNumber() > 0) { //If we have a collision between bounding boxes
      int[] indexBuffer = new int[3];
      collisionData = results.getCollisionData(0); //get the collision data
      if(results.getCollisionData(0).getSourceTris().size() > 0){ //If an actual triangle has collided (rather than just the bounding box) reverse the ships velocity and move it back one timestep
         ship.velocity.x = ship.velocity.x * -1;
         ship.velocity.z = ship.velocity.z * -1;

I just got a new computer and will be busy this week reformatting, reinstalling, etc. etc. you know the drill. Once I get everything back up and running I’ll look into the issue a little deeper and see if I can find out what exactly the problem is and whether its me or jME. My guess is its me cause it’s always me heh.