Rigid body callbacks
Posted: Fri Aug 12, 2011 5:46 am
Hi, I currently have 3 rigid bodies: groundRigidBody, playerRigidBody, and enemyRigidBody. I want to run a function when playerRigidBody and enemyRigidBody collide. I
read several articles on this forum that suggest iterating through all the contact points like in the callback example on the wiki:
This gives me all of the contact points and their locations, but how do I use this to find out if playerRigidBody and enemyRigidBody have collided? I guess what I want to say is something like, "if contact point was formed by playerRigidBody and enemyRigidBody then run function"
read several articles on this forum that suggest iterating through all the contact points like in the callback example on the wiki:
Code: Select all
int numManifolds = dynamicsWorld->getDispatcher()->getNumManifolds();
for (int i = 0; i < numManifolds; i++)
{
btPersistentManifold* contactManifold = dynamicsWorld->getDispatcher()->getManifoldByIndexInternal(i);
btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0());
btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1());
int numContacts = contactManifold->getNumContacts();
for (int j = 0; j < numContacts; j++)
{
btManifoldPoint& pt = contactManifold->getContactPoint(j);
if (pt.getDistance()<0.f)
{
const btVector3& ptA = pt.getPositionWorldOnA();
const btVector3& ptB = pt.getPositionWorldOnB();
const btVector3& normalOnB = pt.m_normalWorldOnB;
}
}
}