When I collide a CompoundShape with some other Objects, I want to know which childShape is colliding...
Can someone tell me how to do this?
Collision Feedback question
-
- Posts: 25
- Joined: Fri Sep 19, 2008 10:23 am
Re: Collision Feedback question
I think you can do this with a custom back function in the narrow phase. The collision object changes the m_collisionShape member in btCollisionShape when it calls the near collision callback function to the current chape in the compound (with m_rootCollisionShape pointing to the compound shape).
So you can access the current shape by just calling getCollisionShape() from the collision object. The code would like something like this;
I hope that this helps!
So you can access the current shape by just calling getCollisionShape() from the collision object. The code would like something like this;
Code: Select all
void
CustomNearCallback(
btBroadphasePair& collisionPair,
btCollisionDispatcher& dispatcher,
const btDispatcherInfo& dispatchInfo)
{
btCollisionObject* lpObj1 = NULL;
btCollisionObject* lpObj2 = NULL;
if (collisionPair.m_pProxy0)
lpObj1 = static_cast<btCollisionObject*>(collisionPair.m_pProxy0->m_clientObject);
if (collisionPair.m_pProxy1)
lpObj2 = static_cast<btCollisionObject*>(collisionPair.m_pProxy1->m_clientObject);
if ((NULL == lpObj1) || (NULL == lpObj2))
{
btCollisionDispatcher::defaultNearCallback(collisionPair, dispatcher, dispatchInfo);
return;
}
btCollisionShape* lpShape1 = lpObj1->getCollisionShape();
btCollisionShape* lpShape2 = lpObj2->getCollisionShape();
/* Do you processing based on the actual shape here */
btCollisionDispatcher::defaultNearCallback(collisionPair, dispatcher, dispatchInfo);
}