Compound Objects: Get colliding child-shape's userdata.
Posted: Fri Nov 29, 2013 2:22 pm
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:
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:
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.
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} |
| || |
-------------------------------
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
}