m_appliedImpulse always zero

cobolt_dink
Posts: 72
Joined: Fri Apr 04, 2008 6:07 pm

m_appliedImpulse always zero

Post by cobolt_dink »

Trying to get the strength of the collision between two objects in the internal tick callback but the impulse is always zero. Code is pretty much ripped from the demos. Only difference is the dyamaics world used to get the number of manifolds is the one passed into the function instead of the globally created one. The callback is a function inside my physics class so the function has to be static so then I can't access the global dynamics world.

Any ideas? I am still using 2.70 if it makes any difference.

Code: Select all

void CPhysics::InternalTickCallback(btDynamicsWorld *world, btScalar timeStep)
{ 
   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& contactPoint = contactManifold->getContactPoint(j);
		 CLogger::Instance()->WriteToLogFile("%f", contactPoint.m_appliedImpulse);
      }
   }

}
mreuvers
Posts: 69
Joined: Sat May 10, 2008 8:39 am

Re: m_appliedImpulse always zero

Post by mreuvers »

"The callback is a function inside my physics class so the function has to be static so then I can't access the global dynamics world."
Can you post that piece of code as well?
cobolt_dink
Posts: 72
Joined: Fri Apr 04, 2008 6:07 pm

Re: m_appliedImpulse always zero

Post by cobolt_dink »

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.
cobolt_dink
Posts: 72
Joined: Fri Apr 04, 2008 6:07 pm

Re: m_appliedImpulse always zero

Post by cobolt_dink »

Rebuilt the project using 2.71 and the impulse is still always zero. Doesn't matter if its the internal tick callback or the contact processed callback.

I imagine the problem is in my physics setup code but I'm not sure what it is.
cobolt_dink
Posts: 72
Joined: Fri Apr 04, 2008 6:07 pm

Re: m_appliedImpulse always zero

Post by cobolt_dink »

Nobody knows why the impulse would be zero? Its kind of important for me to know how strong the collision was.
cobolt_dink
Posts: 72
Joined: Fri Apr 04, 2008 6:07 pm

Re: m_appliedImpulse always zero

Post by cobolt_dink »

Nobody at all has any idea?
ramsampath
Posts: 19
Joined: Fri Sep 05, 2008 8:54 pm

Re: m_appliedImpulse always zero

Post by ramsampath »

I use m_appliedImpulse on the btManifoldPoint from looping through the list from btDispatcher::getInternalManifoldPointer()...and it seems to be getting valid values and not 0.

but on browsing the bullet source code I can see a situation where the m_appliedImpulse can be 0.
my is observation is based on looking at the code - if i am wrong please correct me.

the btDynamicsWorld class seems to have m_solverInfo as its member and by default, m_solverInfo's member m_solverMode seems to be set to SOLVER_RANDMIZE_ORDER | SOLVER_CACHE_FRIENDLY | SOLVER_USE_WARMSTARTING by default. when I changed the m_solverMode to not include SOLVER_CACHE_FRIENDLY the m_appliedImpulse wasn't updated.

I did notice that the solution was was completely different if I didn't use the SOLVER_CACHE_FRIENDLY mode. Maybe someone can answer the details behind this.

Maybe, its not set by default in an earlier version of bullet...or maybe your code modifies it somehow ..!! (I am using bullet 2.70)..

In which case the btManifoldPoint's m_appliedImpulse does not seem to be set to any value (defaults to 0).

This might be what's happening in your case. But its just my thought..., kindly excuse me if I am wrong or if I am way off in my understanding of the code.

Ram.