CcdPhysicsEnvironment Callback Triggers

Sheikh Dawood
Posts: 7
Joined: Tue Sep 19, 2006 3:14 am

CcdPhysicsEnvironment Callback Triggers

Post by Sheikh Dawood »

Hi,

I'm a junior programmer and trying to use the callback trigger feature in the CcdPhysicsDemo app. After adding a physics object into the m_triggerControllers by using the requestCollisionCallback function, how do I catch a callback collision event in the CcdPhysicsDemo class?

I'm trying to capture this collision event to create my own collision response of one of the objects.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Post by Erwin Coumans »

You can register your callback function using this interface:

Code: Select all

void CcdPhysicsEnvironment::addTouchCallback(int response_class, PHY_ResponseCallback callback, void *user)
Then for each object that you requested a collision callback, this callback function will be called.

Code: Select all

void CcdPhysicsEnvironment::requestCollisionCallback(PHY_IPhysicsController* ctrl)

For example:

Code: Select all

 static bool newCollisionResponse(void *client_data, void *object1, void *object2, const PHY_CollData *coll_data)
{
//process the collision
    PHY_IPhysicsController* obj1 = static_cast<PHY_IPhysicsController*>(object1);
    PHY_IPhysicsController* obj2 = static_cast<PHY_IPhysicsController*>(object2);

//you can also cast to a CcdPhysicsController if necessary

//...
//coll_data is 0 at the moment, this is reserved for future use


return false;
}

Code: Select all


MyClass* client_data =0;
//optionally this 'client_data' can be some class. Then, in the callback you can jump from a static function into that class, to keep things object oriented.

//register this callback
 physEnv->addTouchCallback(PHY_OBJECT_RESPONSE, newCollisionResponse, client_data);
It's probably best to add a Demo that shows the usage, and add this to the documentation/user manual.
Thanks,
Erwin
Sheikh Dawood
Posts: 7
Joined: Tue Sep 19, 2006 3:14 am

Post by Sheikh Dawood »

Thanks!

It works but I also have to include addSensor() to call requestCollisionCallback()