Compound Objects: Get colliding child-shape's userdata.

Post Reply
Karrok
Posts: 65
Joined: Fri May 13, 2011 1:11 pm

Compound Objects: Get colliding child-shape's userdata.

Post by Karrok »

Hi All,

I have a compound shape with a bunch of child shapes, for each child-shape I also attach a small user data object containing some specific data for that child shape.

As an (simplified..) example , imagine a compound shape made out of 4 tiles. Each tiles has some user data value giving a certain amount of points:

Code: Select all

------------------------------
|             ||             |     
| userData{4} || userData{1} |
|             ||             |
--------------++---------------
--------------++---------------
|             ||             |     
| userData{5} || userData{7} |
|             ||             |
-------------------------------

And per frame I check the dispatchers manifolds whether something is colliding with 1 or more of the tiles.
At the moment, say a ball, collides with 1 of the subshapes of the compound shape I need to get the userdata of that child-shape.

Q: how do I get that child-shape user data back from the collision manifolds?

ie:

Code: Select all

int numManifolds = m_collisionWorld->getDispatcher()->getNumManifolds();

    for (int i=0;i<numManifolds;i++)
    {
      btPersistentManifold* contactManifold = m_collisionWorld->getDispatcher()->getManifoldByIndexInternal(i);
      int numContacts = contactManifold->getNumContacts();

      btCollisionObject* object_A = static_cast<btCollisionObject*>(contactManifold->getBody0());

      // somehow get the childshape making the actual collision
      // get userdata from childshape.
      // do stuff with userdata

    }


edit: While it might be obvious for some readers that it would be easier to simply create 4 completely seperate boxes instead of a compound shape of boxes, for my application that won't fly sadly.
Post Reply