Code: Select all
int numCollisions = dispatcher->getNumManifolds();
for (int i = 0; i < numCollisions; i++) {
btPersistentManifold* contactManifold = dispatcher->getManifoldByIndexInternal(i);
btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0());
btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1());
Actor* actorA = (Actor*)(obA->getUserPointer());
Actor* actorB = (Actor*)(obB->getUserPointer());
if (actorA == actorB) {
continue;
}
int numContacts = contactManifold->getNumContacts();
if (numContacts) {
// Average the contact points
SFVector3d finalContact(0.0, 0.0, 0.0);
btVector3 averageA(0.0, 0.0, 0.0);
btVector3 averageB(0.0, 0.0, 0.0);
for (int j = 0; j < numContacts; j++) {
btManifoldPoint& point = contactManifold->getContactPoint(j);
averageA += point.getPositionWorldOnA();
averageB += point.getPositionWorldOnB();
}
double finalX = ((averageA.getX() + averageB.getX())/numContacts) * 0.5;
double finalY = ((averageA.getY() + averageB.getY())/numContacts) * 0.5;
double finalZ = ((averageA.getZ() + averageB.getZ())/numContacts) * 0.5;
finalContact.Set(finalX, finalY, finalZ);
contactManifold->clearManifold();
// Call actors' event handlers
actorA->OnCollision(actorB, &finalContact);
actorB->OnCollision(actorA, &finalContact);
}
}
}
With a simple box, the difference between the character's Y and the contact point Y holds steady at around 0.4 when the character is standing on flat ground. But with a compound shape, we get values for the contact point Y that range from 0.35 to -1.24e-005.
I have implemented a number of watches and noticed something curious: the PersistentManifold will record the character-to-groundmesh collision pair twice: once with 1 contact point, and again with 4 contact points. The instance with 4 points always returns a reliable result, but the instance with 1 point tend to be one of those "1e-005" numbers. I've even seen the Manifold record a collision pair in which the character collides with itself---again, only something that happens with a compound shape. And finally (haha, I know), we tend to get an inexplicable memory leak when deallocating compound shapes. Any idea what's going on?