Code: Select all
extern ContactDestroyedCallback gContactDestroyedCallback;
extern ContactAddedCallback gContactAddedCallback;
bool customContactDestroyedCallback( void* userData ) {
cout << "custom destroyed callback!" << endl;
return false;
}
bool customContactAddedCallback( btManifoldPoint& cp, const btCollisionObject* colObj0,int partId0,
int index0,const btCollisionObject* colObj1,int partId1,int index1 ) {
cout << "custom added callback!" << endl;
return false;
}
void physicsInit() {
// Create physics solvers and such here
...................
// Set the custom collision callback
gContactDestroyedCallback = customContactDestroyedCallback;
gContactAddedCallback = customContactAddedCallback;
..................
// Tell the physics system to use our custom callback
physObj->body->setCollisionFlags( physObj->body->getCollisionFlags() |
btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK );
// Associate the body with our physical body structure
physObj->body->setUserPointer( physObj );
m_dynamicsWorld->addCollisionObject( physObj->body, collisionGroup, collidesWith );
}
Now, the reason I am doing this is because when two specific types of objects collide I want to destroy one of them (delete it). I figured the deleted call back was optimal because removing an object mid collision is warned against in the things I have read. So, assuming I can get this callback to work, what would be the best way of associating the collided bodies with my game objects? I've read a little about user data pointers but havent seen anyway to set them, is this what they are for?