Hi,
I am looking for a way to know if a body with a collision shape is having a collision with another collision shape. Is there any method to get the answer as a boolean (True if it has one or several collisions), or a way to get the total number of collisions points?
How to know if a body is colliding
-
- Posts: 849
- Joined: Tue Sep 30, 2014 6:03 pm
- Location: San Francisco
Re: How to know if a body is colliding
One way to do it is to scan all of the contact manifolds after each step. So something like this:
Where the collision_dispatcher is the one you gave the btDiscreteDynamicsWorld when you created it.
Code: Select all
void updateContactMap(btCollisionDispatcher* collision_dispatcher) {
int num_manifolds = collision_dispatcher->getNumManifolds();
for (int i = 0; i < num_manifolds; ++i) {
btPersistentManifold* contact_manifold = collision_dispatcher->getManifoldByIndexInternal(i);
// sometimes you get a manifold with zero contacts so filter for that case
if (contact_manifold->getNumContacts() > 0) {
const btCollisionObject* object_A = contact_manifold->getBody0();
const btCollisionObject* object_B = contact_manifold->getBody1();
// ... do something
}
}
}