A little trick to contactPairTest statics and kinematics.

Post Reply
Jonathan
Posts: 36
Joined: Sun Feb 10, 2013 6:52 pm

A little trick to contactPairTest statics and kinematics.

Post by Jonathan »

I was trying to figure out the best way to determine if the player placed a static object that collided with another static object. This is a fairly infrequent and one time test when the player places an object. It seems like contactPairTest was the proper tool for the job, until I had issues with the callback not triggering when the collision objects were static/kinematic. Hopefully Erwin doesn't see this as a terrible hack, but, how else are we supposed to manually determine if two given objects are colliding?

I'm including this little trick for anybody to use. Hopefully it helps someone. :)

Code: Select all

void contactPairTestForced (btCollisionObject* colObjA , btCollisionObject* colObjB , btCollisionWorld::ContactResultCallback& callback)
{
	// We set the bodies to ACTIVE so the collision algorithim doesn't care that they are static/kinematic.
	auto colObjA_activation_state = colObjA->getActivationState ();
	auto colObjB_activation_state = colObjB->getActivationState ();
	colObjA->setActivationState (ACTIVE_TAG);
	colObjB->setActivationState (ACTIVE_TAG);

	dynamicsWorld->contactPairTest (colObjA , colObjB , callback); // If anybody uses this function, just rename dynamicsWorld to whatever yours is.

	colObjB->setActivationState (colObjB_activation_state);
	colObjA->setActivationState (colObjA_activation_state);
	// After testing the pair, we revert the bodies to their previous activation state.
}
Oh, and bullet complains "warning btCollisionDispatcher::needsCollision: static-static collision!" Seems to work fine though. :)
Post Reply