Usually all Solid/Solid collisions generate physical contacts that keep them from interpenetrating. Sometimes this is not desired, either for performance reasons (fewer constraints means faster simulation) or for special effects. Contact groups can be used to enable forcefields that repel only a subset of objects, efficient ray casts that only collide with certain objects, invisible “trigger volumes” that generate collision events but don’t make physical contacts with anything, etc.

It is important to note the difference between “collision events” and “contacts” the way XPA defines them. Collision events occur whenever two Solids collide (but are only handled if at least one of the two Solids uses a collision event handler). Contacts are physical constraints that keep Solids from penetrating one another. Solids can use collision events and/or contacts. By default, every collision group generates contacts, and every Shape starts in group 0.

Every XPA Shape is in one (and only one) contact group. A contact group can be set to enable or disable contacts with other contact groups, including itself. For example, if groups 5 and 8 are set not to generate contacts, object A is in group 5, and object B is in group 8, objects A and B will pass through one another when they collide. XPA can use up to 32 different contact groups. Contact groups always work both ways between two groups: if group X makes contacts with group Y, group Y will make contacts with group X.

Warning: Because the contact group interactions are always two-way, be careful about the order in which you setup the groups. If you set group 3 not to make contacts with group 5, then set group 5 to make contacts with group 3, the two groups will make contacts.

Here is an example that shows how to create three objects: object A, object B, and object C. We will generate contacts only between objects A and B and objects B and C, but not between objects A and C:
// Create three Solids, each with a Shape in a different contact group.
SphereShapeData sphereData = new SphereShapeData();
Solid objectA = sim.CreateSolid();
sphereData.ContactGroup = 1;
objectA.AddShape(sphereData);
Solid objectB = sim.CreateSolid();
sphereData.ContactGroup = 2;
objectB.AddShape(sphereData);
Solid objectC = sim.CreateSolid();
sphereData.ContactGroup = 3;
objectC.AddShape(sphereData);
 
// Setup the contact groups.
sim.SetupContactGroups(1, 2, true);
sim.SetupContactGroups(2, 3, true);
sim.SetupContactGroups(1, 3, false); 


To setup an object that doesn’t make contacts with anything else, do the following:
BoxShapeData boxData = new BoxShapeData();
boxData.contactGroup = 15;
Solid trigger = sim.CreateSolid();
trigger.AddShape(boxData);
sim.SetupContactGroup(15, false); 


The “setupContactGroup” function sets up the interaction between a contact group and every other contact group at once, making it easy to create a trigger volume object that doesn’t affect anything else physically but can still generate collision events.

When using the RaycastSensor and VolumeSensor, keep in mind that contact groups can be used to make more efficient collision queries. Remember, the VolumeSensor takes a pointer to a “volume” Solid and checks which other Solids collide with that Solid. Simply use a contact group on the volume Solid’s Shape(s). The RaycastSensor has an explicit contact group that can be setup to limit which other groups it collides with.

Last edited Oct 12, 2006 at 7:10 PM by KleMiX, version 2

Comments

No comments yet.