Jump to content
  • Advertisement
Sign in to follow this  
Wavesonics

Culstom callbacks in Bullet Physics engine not working?

This topic is 3659 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I just started implementing bullet's custom collision callbacks and have been having some trouble:
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() {
   // Set the custom collision callback
   gContactDestroyedCallback = customContactDestroyedCallback;
   gContactAddedCallback = customContactAddedCallback;
}

But I only get output from the custom "added" callback. If two objects collide and bounce off each other, shouldn't the contact point be destroyed, and thus call my callback? 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?

Share this post


Link to post
Share on other sites
Advertisement
Have you asked the question over at the Bullet forums? I'm not sure what the behavior is with respect to destroying contacts in Bullet. I believe in ODE, you have to manually destroy the contact after it's been resolved, but about Bullet I cannot say without digging.

Share this post


Link to post
Share on other sites
hey thanks for the reply,

Ya I posted on the bullet forums but they are fairly low traffic compared to gamedev so I put it on here as well.

I got one reply there and it seems that it *should* be getting called, so I need to do some more digging I guess.

Share this post


Link to post
Share on other sites
Found the first problem:
btSequentialImpulseConstraintSolver's constructor assigns the global:
gContactDestroyedCallback

to it's own destroy callback. So a user's assignment for their custom callback MUST take place after you construct the solver for your dynamics world.

But I am still having an issue. I am setting the user data for my rigid bodies, but the m_persistentUserdata in the manifolds seem to be NULL, thus the destroy callback is not called.

Is there anything special i have to do to get my user data to propagate through the collision system?

Share this post


Link to post
Share on other sites
Glad you solved the first problem. It's nice to have source code and a debugger, isn't it?

About the 2nd problem, I cannot say. Again, source code is your friend, they say. The Bullet forums actually are pretty active, though perhaps more on the researchy side than usage....have you had any more luck getting answers there?

Share this post


Link to post
Share on other sites
Yep, I just a minute ago got the answer I was looking for:

The solver defaults to:
CACHE_FRIENDLY or similar, which is bad.

So changing it to:

m_dynamicsWorld->getSolverInfo().m_solverMode = SOLVER_RANDMIZE_ORDER | SOLVER_USE_WARMSTARTING;

fixes it and my user pointer make it to the destroyed callbacks just fine :)

Share this post


Link to post
Share on other sites
So it turns out that yes, my destroy callback gets a pointer, but it doesn't seem to be the one that I put in there when I was making the object :/

Anyone know why it would get changed, or what it would get changed to?

[Edited by - Wavesonics on June 13, 2008 5:53:18 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!