I am detecting collision events by iterating over manifolds. Trouble is I get A LOT of collisions. In my test case, I have a single box which drops onto some terrain. Despite my best effort I still get 330 collisions detected by the following code
Code: Select all
// Iterate over contact manifolds / points:
int numManifolds = m_world->getDispatcher()->getNumManifolds();
for ( int i=0; i < numManifolds; ++i)
{
btPersistentManifold* contactManifold = m_world->getDispatcher()->getManifoldByIndexInternal(i);
btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0());
btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1());
int numContacts = contactManifold->getNumContacts();
if ( numContacts )
{
btManifoldPoint& pt = contactManifold->getContactPoint(0);
if ( pt.getLifeTime() > 1 )
continue;
int idA = 0;
int idB = 0;
if ( obA->getUserPointer() )
idA = *(int*)obA->getUserPointer();
if ( obB->getUserPointer() )
idB = *(int*)obB->getUserPointer();
// ACT ON COLLISION NOTIFICATION HERE
}
// Clear contact points to prevent new collisions
contactManifold->clearManifold();
}
Thanks
Simon