I even tried having the callback as just a function by itself and setup like in the demos and the impulse is always zero.
Here is Bullet setup:
Code: Select all
btDynamicsWorld *test;
void CPhysics::InitPhysics()
{
//collision configuration contains default setup for memory, collision setup
m_collisionConfiguration = new btDefaultCollisionConfiguration();
///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded)
m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
///the maximum size of the collision world. Make sure objects stay within these boundaries
///Don't make the world AABB size too large, it will harm simulation quality and performance
btVector3 worldAabbMin(-1000, -1000, -1000);
btVector3 worldAabbMax(1000, 1000, 1000);
m_overlappingPairCache = new btAxisSweep3(worldAabbMin, worldAabbMax, MAX_PROXIES);
///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded)
btSequentialImpulseConstraintSolver *sol = new btSequentialImpulseConstraintSolver;
m_solver = sol;
m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher, m_overlappingPairCache, m_solver, m_collisionConfiguration);
m_dynamicsWorld->setGravity(btVector3(0,-9.8f,0));
test = m_dynamicsWorld;
//gContactAddedCallback = CollisionCallback;
gContactProcessedCallback = ContactProcessed;
m_dynamicsWorld->setInternalTickCallback(&TickCallback);
m_dynamicsWorld->getSolverInfo().m_solverMode = SOLVER_RANDMIZE_ORDER | SOLVER_USE_WARMSTARTING;
CLogger::Instance()->WriteToLogFile("\nPhysics started...\n");
}
And the callback:
Code: Select all
void TickCallback(btDynamicsWorld *world, btScalar timeStep)
{
int numManifolds = test->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());
CEntity *ent1 = (CEntity *)obA->getUserPointer();
CEntity *ent2 = (CEntity *)obB->getUserPointer();
int numContacts = contactManifold->getNumContacts();
for (int j=0;j<numContacts;j++)
{
btManifoldPoint& pt = contactManifold->getContactPoint(j);
if (ent1->GetEntityType() == ENT_BLOCK && ent2->GetEntityType() == ENT_LEVEL)
CLogger::Instance()->WriteToLogFile("%f\n", pt.m_appliedImpulse);
if (ent2->GetEntityType() == ENT_BLOCK && ent1->GetEntityType() == ENT_LEVEL)
CLogger::Instance()->WriteToLogFile("%f\n", pt.m_appliedImpulse);
}
//you can un-comment out this line, and then all points are removed
//contactManifold->clearManifold();
}
}
Block is a rigid body and level is a btBvhTriangleMeshShape. Now I know I'm only checking for a block/level collision here but dropping one block on another is always zero too.