Page 1 of 1
CcdPhysicsEnvironment Callback Triggers
Posted: Tue Sep 19, 2006 7:05 am
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.
Posted: Tue Sep 19, 2006 7:29 am
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
Posted: Tue Sep 19, 2006 8:26 am
by Sheikh Dawood
Thanks!
It works but I also have to include addSensor() to call requestCollisionCallback()