Collision data notification for only specific bodies

Post Reply
magicchicken
Posts: 11
Joined: Tue Dec 09, 2008 9:42 pm

Collision data notification for only specific bodies

Post by magicchicken »

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
magicchicken
Posts: 11
Joined: Tue Dec 09, 2008 9:42 pm

Re: Collision data notification for only specific bodies

Post by magicchicken »

Well, more reading of the forums, and here's what I got:

1) In another post (http://www.bulletphysics.org/Bullet/php ... 072#p16072), Erwin even says that the gContactAddedCallback and friends aren't good for this purpose, because it happens during the collision detection process and it an unwise time to do game code (sending contact data to lua). But this is the only way to use the m_userPersistentData member of the contact manifold, which seemed like a great way to know whether or not a contact is new or not.

2) btGhostObject doesn't have functions for applying force, setting velocity, etc. So this cannot be replace the btRigidBody we use for our player and bullets. As how to keep it synchronized each frame to a dynamic object - I'd have to wait until the end of the frame to get the player's new transform, set that on the ghost object, and wait until the next frame for the overlapped pairs to be accurate. This frame lag shows that this isn't the right solution either.

I could use them for static triggers, but then I'd have two code paths for grabbing contact data - not horrible, but might take me more time to integrate.

3) I have no idea how to do a contactTest that isn't an AABB. I could really use help with this (we need a sphere based contact test).
dangerdaveCS
Posts: 14
Joined: Mon Jun 07, 2010 5:37 am

Re: Collision data notification for only specific bodies

Post by dangerdaveCS »

btCollisionWorld::contactTest doesnt just do AABB, it does any shape. I'm currently using it for spheres myself.

The Bullet source makes it look like it's just doing an AABB check, but if you look closely the aabbTest call is passed a btSingleContactCallback, which then processes the nearphase, and through a whole chain of callbacks calls on your passed ContactResultCallback functions.
Post Reply