Best way to do collision detection

jonathanblacknight

18-08-2010 14:28:08

Hi i need a very simple thing, when two rigid bodies collides, call a function or something, in bullet wiki:

http://www.bulletphysics.org/mediawiki- ... d_Triggers


//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;
}
}
}



This is the best way to perform this, or exists a better way to do?

shaolin

22-08-2010 11:19:56

This might help:

http://bulletphysics.org/Bullet/phpBB3/ ... f=9&t=3997

Read the second page. A detailed case by case strategy is discussed there.