Collision notification
Posted: Sat Oct 14, 2006 9:09 am
Is there an ability to get notification (callback) when collision with particular object occurs?
It depends what you want to do with this:Jack wrote:Is there an ability to get notification (callback) when collision with particular object occurs?
Code: Select all
int numManifolds = collisionWorld->getDispatcher()->getNumManifolds();
for (i=0;i<numManifolds;i++)
{
btPersistentManifold* contactManifold = collisionWorld->getDispatcher()->getManifoldByIndexInternal(i);
btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0());
btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1());
contactManifold->refreshContactPoints(obA->m_worldTransform,obB->m_worldTransform);
int numContacts = contactManifold->getNumContacts();
for (int j=0;j<numContacts;j++)
{
btManifoldPoint& pt = contactManifold->getContactPoint(j);
glBegin(GL_LINES);
glColor3f(1, 0, 1);
btVector3 ptA = pt.getPositionWorldOnA();
btVector3 ptB = pt.getPositionWorldOnB();
glVertex3d(ptA.x(),ptA.y(),ptA.z());
glVertex3d(ptB.x(),ptB.y(),ptB.z());
glEnd();
}
//you can un-comment out this line, and then all points are removed
//contactManifold->clearManifold();
}
Code: Select all
staticBody->m_collisionFlags |= btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK;