Collision data notification for only specific bodies
Posted: Tue Jun 08, 2010 1:59 am
I'm successfully setting the collision groups and masks of our rigid bodies to control which objects can collide with what others, so um... yay!
I'd like to have even more control over which of those contacts generate contacts. If I use the callback gContactProcessedCallback, then i get collision data for all objects that are in contact. Since we're sending all of our contact data to Lua each frame, this is way too many!
1) I could set the CF_CUSTOM_MATERIAL_CALLBACK flag on only the bodies I want contact data for, and use the other callback functions instead (gContactAddedCallback, gContactProcessedCallback, gContactDestroyedCallback). Reading the forums it sounds like these are too frequent for game use, and are really meant for modifying collision data - which I have no need for.
2) I've looked at the character demo, and read up on the forum posts about the btGhostObject, so I see that i could use this for only the game objects that I want the contact data for. But our player and bullets are dynamic objects, so does that mean I would need to create an associated btGhostObject for each one and somehow keep it synchronized with the dynamic body? I see that they could share the same collision shape, but would I get precise contacts and not just AABB overlaps?
3) I could use the btCollisionWorld::contactTest function for each object that wants notification each frame, but this only does AABB. I really do need the actual shape tested against the world.
4) I guess I might just set a "wantsContactData" flag on certain game objects and just check for that in the gContactProcessedCallback....
I'll probably just go for idea 4 since it have enough working to do it pretty quickly. Any advice or insight on the other methods would go a long way to helping me understand how to use the Bullet API efficiently. Particularly #3, since I need a sphere shape contact test with the world for other game logic purposes.
Thanks in advance,
-Tom
I'd like to have even more control over which of those contacts generate contacts. If I use the callback gContactProcessedCallback, then i get collision data for all objects that are in contact. Since we're sending all of our contact data to Lua each frame, this is way too many!
1) I could set the CF_CUSTOM_MATERIAL_CALLBACK flag on only the bodies I want contact data for, and use the other callback functions instead (gContactAddedCallback, gContactProcessedCallback, gContactDestroyedCallback). Reading the forums it sounds like these are too frequent for game use, and are really meant for modifying collision data - which I have no need for.
2) I've looked at the character demo, and read up on the forum posts about the btGhostObject, so I see that i could use this for only the game objects that I want the contact data for. But our player and bullets are dynamic objects, so does that mean I would need to create an associated btGhostObject for each one and somehow keep it synchronized with the dynamic body? I see that they could share the same collision shape, but would I get precise contacts and not just AABB overlaps?
3) I could use the btCollisionWorld::contactTest function for each object that wants notification each frame, but this only does AABB. I really do need the actual shape tested against the world.
4) I guess I might just set a "wantsContactData" flag on certain game objects and just check for that in the gContactProcessedCallback....
I'll probably just go for idea 4 since it have enough working to do it pretty quickly. Any advice or insight on the other methods would go a long way to helping me understand how to use the Bullet API efficiently. Particularly #3, since I need a sphere shape contact test with the world for other game logic purposes.
Thanks in advance,
-Tom