I random-generate some boxes and wait until all objects have gone to sleep, whereupon I want to read all static contact forces.
However, I seem to be getting consistently too few contacts.
I'm using the Wiki code snippet:
Code: Select all
int numManifolds = world->getDispatcher()->getNumManifolds();
for (int i=0;i<numManifolds;i++)
{
btPersistentManifold* contactManifold = world->getDispatcher()->getManifoldByIndexInternal(i);
btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0());
btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1());
int numContacts = contactManifold->getNumContacts();
for (int j=0;j<numContacts;j++)
{
btManifoldPoint& pt = contactManifold->getContactPoint(j);
if (pt.getDistance()<0.f)
{
const btVector3& ptA = pt.getPositionWorldOnA();
const btVector3& ptB = pt.getPositionWorldOnB();
const btVector3& normalOnB = pt.m_normalWorldOnB;
}
}
}
I've tried the above code both in the internal tick callback and after finishing a stepSimulation call; the results are identical. I've added code to wake the boxes up and simulate once, as well as 4 times, just in case the sleeping is causing the anomaly, but that changed nothing either.
I'm new to Bullet so there's probably something trivial I'm missing. Ideas?