[ODE] collision filtering

nathan@whatever.net nathan at whatever.net
Sun Dec 23 12:52:02 2001


You could call it clever or you could call it a hack, but I got around my
stack overflow by NOT doing collision detection on bodies that share a
common joint (not including transient contact joints).  This allows
interpenetrating joined bodies (which looks much nicer in my application)
without the impossible contact joints that would normally entail.

The 'shared joint' test could be done via user-data members of the bodies
whose geometry objects are passed to the collision callback, but I thought
it would be simpler and a bit more efficient to create a function in the
ODE API:

int dBodiesAreJoined (dBodyID b1, dBodyID b2) 
{
	// iterate over the list of joints to which b1 is attached
	dxJointNode *pJointNode = b1->firstjoint;
	while (pJointNode)
	{
		dxJoint *pJoint = pJointNode->joint;
		if (pJoint)
		{
			if ((b1 == pJoint->node[0].body) && (b2 == pJoint->node[1].body))
				return 1;

			if ((b1 == pJoint->node[1].body) && (b2 == pJoint->node[0].body))
				return 1;
		}
		pJointNode = pJointNode->next;
	}
	return 0; 
}

So now my collision callback starts with this:

	dBodyID Body1 = dGeomGetBody (o1), Body2 = dGeomGetBody (o2);

	if (dBodiesAreJoined (Body1, Body2))
		return;
	
Anyhow, I found this function useful so I thought I'd share it, and submit
it to Russ for consideration in the next revision of ODE.

Happy holidays, everyone!

Nate Waddoups
Redmond WA USA
http://www.natew.com