I am attempting to figure out when two objects collide.
What I want:
Ideally, whenever a collision actually occurs, Bullet would call a callback, giving me the option to ignore the collision or allow Bullet to continue with collision response (restitution, reaction, etc.).
Some things close and my analysis thereof:
I found two pages of interest:
- Page 1: http://www.bulletphysics.org/mediawiki- ... d_Triggers
Page 2: http://bulletphysics.org/mediawiki-1.5. ... _Filtering
Code: Select all
//dynamics->stepSimulation above
int numof_manifolds = collision_dispatcher->getNumManifolds();
for (int i=0;i<numof_manifolds;++i)
{
btPersistentManifold* contactManifold = collision_dispatcher->getManifoldByIndexInternal(i);
const btCollisionObject* obA = contactManifold->getBody0();
const btCollisionObject* obB = contactManifold->getBody1();
int numof_contacts = contactManifold->getNumContacts();
for (int j=0;j<numof_contacts;++j) {
btManifoldPoint& pt = contactManifold->getContactPoint(j);
if (pt.getDistance()<=0.0f) {
//->setUserPointer can be called when rigid bodies are created with an id that allows for their identification here
printf("Collided: %p %p\n",obA->getUserPointer(),obB->getUserPointer());
//getchar();
//const btVector3& ptA = pt.getPositionWorldOnA();
//const btVector3& ptB = pt.getPositionWorldOnB();
//const btVector3& normalOnB = pt.m_normalWorldOnB;
}
}
}
The other options on Page 1 would suffer from the same problem, I think. Maybe the contact method with gContactProcessedCallback could do what I want? On Page 2, I tried the last suggestion of deriving btCollisionDispatcher and overriding needsResponse, but this seems to be called at times when the two objects do not collide.
Suggestions, tips, comments, etc.?
Ian