In the wiki, the first implementation of collision notification looks like this:
Code: Select all
//Assume world->stepSimulation or world->performDiscreteCollisionDetection has been called
int numManifolds = world->getDispatcher()->getNumManifolds();
for (int i=0;i<numManifolds;i++)
{
btPersistentManifold* contactManifold = world->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;
}
}
}
As far as I can tell, in the first line the number of contacts that are occurring is retrieved (this is for each pair of objects right?). It then iterates through each pair that is currently in contact. In each iteration, it retrieves the collision shapes that are involved in the collision (can I cast for a rigid body and use the userData pointer to find the application objects involved?). It then retrieves how many contact points are involved in the collision and retrieves where it is occurring and the object normal. I'm a little confused about this part. Why are there two points if it is a single contact location?
If I may ask, what have I missed and where am I wrong? Thanks.