collision callback

mirv
Posts: 19
Joined: Tue Jun 20, 2006 7:13 am

collision callback

Post by mirv »

G'day,
Just curious as to the proper method of putting a callback for knowing when objects collide. For example, a bullet will do damage to a person, but not really much to a wall. For the moment, I'm checking all manifolds from a collision dispatcher, and if there are contact points, using the user data pointer to point to my own data.
Just curious as to if there is a better method of doing this? Or am I going the right way about it?
Thanks for you time!
Eltharyon
Posts: 13
Joined: Wed Jun 07, 2006 12:55 pm

Post by Eltharyon »

Well, ideally you only want to have to process a collision you're actually interested in. Generally it'd be nice to only receive a callback when the collision classes of two colliding objects have a callback collision response defined.

An additional callback I'd be very interested in is an "object leaves world" callback. No matter how accurate the simulation, in game reality objects do occasionally leave the expected environment and then generally tend to fall forever, until they reach the end of the defined three dimensional space (at which point they might wrap around) or until the simulation crashes.
Sheikh Dawood
Posts: 7
Joined: Tue Sep 19, 2006 3:14 am

Post by Sheikh Dawood »

Hi, I'm using version 2.40. Is the touch callback or collision callback implemented yet?
I can't find any functions such as "addTouchCallback" like from the previous versions.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Post by Erwin Coumans »

How do you plan to use this exactly?

The easiest option is to just traverse all contact points after the simulation step finishes. See Demos/CollisionInterfaceDemo for this. This is what the addTouchCallback did.

Another option is using the new collision nearCallback. This is called for every overlapping pair, before the actual nearphase collision detection. You have the option to register your own nearCallback with the collision dispatcher.
See Demos/CcdPhysicsDemo, and make sure USE_CUSTOM_NEAR_CALLBACK is defined at the top, see

Code: Select all

//implement your own version of the near callback:
void customNearCallback(btBroadphasePair& collisionPair, btCollisionDispatcher& dispatcher, btDispatcherInfo& dispatchInfo);
//and register it to the dispatcher:
dispatcher->setNearCallback(customNearCallback);
One option is to check for contact points in the 
You can override this method in btManifoldResult (but still call the base implementation if needed):

Code: Select all

    virtual void addContactPoint(const btVector3& normalOnBInWorld,const btVector3& pointInWorld,btScalar depth);
Does this help, or do you prefer the old style touchCallback?
Erwin

Sheikh Dawood wrote:Hi, I'm using version 2.40. Is the touch callback or collision callback implemented yet?
I can't find any functions such as "addTouchCallback" like from the previous versions.
Sheikh Dawood
Posts: 7
Joined: Tue Sep 19, 2006 3:14 am

Post by Sheikh Dawood »

I was trying to a detect a collision when an object hits the ground in the ConvexDecompositionDemo and do my own collision response.

The current implementation for collision call back is fine. Thanks for the help to get me started.
Sheikh Dawood
Posts: 7
Joined: Tue Sep 19, 2006 3:14 am

Post by Sheikh Dawood »

Need some help.

How do I implement processCollision in btCollisionAlgorithm to make use of the btManifoldResult to get the contact points?
Somehow, I need to call getContactPoint on a btPersistentManifold in btManifoldResult.

And what does addContactPoint in btManifoldResult do?

Thanks
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Post by Erwin Coumans »

This is just too complicated to support at the moment, please take the easy route first:

The easiest option is to just traverse all contact points after the simulation step finishes. See Demos/CollisionInterfaceDemo for this. This is what the addTouchCallback did.

Thanks,
Erwin