I have a slight update. I thought I'd share some code, perhaps that will help.
Here is my code which is pretty much copied from the wiki. As you see, I am looking for a true return value if object1 has a collision with object2, otherwise the function should return false. I first find the dispatcher of the world and query it for the count of manifolds. Then, for each manifold I find the two candidate objects which might be the two I am looking for. Then I figure out if the objects from the query really is the two objects I want to test. If they are not, skip this manifold and resume next. If they are the objects I am looking for, check if they have any contacts and if they have any contacts we return true and stop the test. If no contacts or no pairs are found, then there was no contact and I return false.
Code: Select all
bool CollisionHelper::TestCollision(btCollisionObject *object1, btCollisionObject *object2)
{
btDispatcher *dispatcher = mWorld->getDispatcher();
int numManifolds = dispatcher->getNumManifolds();
for (int i = 0; i < numManifolds; ++i)
{
btPersistentManifold* contactManifold = dispatcher->getManifoldByIndexInternal(i);
btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0());
btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1());
bool isMatchingPair = (object1 == obA && object2 == obB) || (object2 == obA && object1 == obB);
if (isMatchingPair)
{
int numContacts = contactManifold->getNumContacts();
if (numContacts > 0)
{
// If the pair we are interested in have at least one contact point,
// return true to indicate that there is a collision between object1 and object2.
return true;
}
}
}
// If the pair we are interested in was not found or had no contacts,
// return false to indicate that there is no collision between object1 and object2.
return false;
}
Using the debugger, I find that both object1 and object2 are found when iterating over the manifold points, but they are never found together as a pair. Visually I can tell that the bodies are colliding, using debug drawing. I have some far stretched idea that perhaps the pointer check is not safe to do as I have previously encountered that for instance virtual inheritance changes the pointer bases for the objects. I have set my collision group and masks accordingly on the bodies and before calling this function I also call performDiscreteCollisionDetection() on the world.
I have no idea how to solve this, it shouldn't have to be so hard. I can't come up with anything else that might do what I want to do. If you can, please let me know.