It has been an hardcore saturday evening i’ve…

It has been an hardcore saturday evening: i’ve struggled with Bullet for 3 hours, and, finally, i’m able to get all bullet events in my code, without having to “manually” asking to each object “are you touching somebody?”.

It’s a bit weird, but to achieve this you have to plug a static method on the C callbacks of Bullet, called ContactAddedCallback, ContactProcessedCallback and ContactDestroyedCallback.

To avoid ever doing this again, PBullet class has now 3 static methods to set these 3 callbacks,

  • static void setContactAddedCallback( ContactAddedCallback callbackFunction);
  • static void setContactProcessedCallback( ContactProcessedCallback callbackFunction);
  • static void setContactDestroyedCallback( ContactDestroyedCallback callbackFunction);

In your class, you declare one method like this (.h):

static bool myContactProcessedCallback(
btManifoldPoint& cp,
void* body0, void* body1) {
std::cout << “myContactProcessedCallback: ” << body0 << ” <> ” << body1 << std::endl;
}

You link it to PBullet like this (easy):

PBullet::setContactProcessedCallback( myContactProcessedCallback );

And it works! Result is absolutely NOT visual…

The bullet documentation is a bit too subtle for me, I lost a lot of time to implement a ContactResultCallback before understanding that this is a one timer, the link between objects and the callback is lost at the next update…

For the braves and the curious, here is the urls i’ve used to complete this:

  • http://www.ogre3d.org/addonforums/viewtopic.php?f=12&t=7984
  • http://www.bulletphysics.org/mediawiki-1.5.8/index.php?title=Collision_Callbacks_and_Triggers
  • https://www.linuxquestions.org/questions/programming-9/does-any-physics-engine-work-on-linux-alongside-a-3d-engine-4175420573/
  • http://irrlicht.sourceforge.net/forum/viewtopic.php?f=1&t=46752
  • https://github.com/kripken/ammo.js/issues/82
  • http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?f=9&t=3997
  • https://github.com/sinistersnare/libgdx/wiki/Bullet-Wrapper—Contact-callbacks
  • https://stackoverflow.com/questions/20300615/bullet-collision-callback-between-2-bodies
  • http://www.bulletphysics.org/mediawiki-1.5.8/index.php/Collision_Callbacks_and_Triggers
  • http://bulletphysics.org/Bullet/BulletFull/classbtCollisionObject.html
  • http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=4807
  • https://stackoverflow.com/questions/20300615/bullet-collision-callback-between-2-bodies#20300782
  • https://stackoverflow.com/questions/25462954/how-does-the-libgdx-bullet-extensions-contactlistener-work
  • http://www.bulletphysics.org/mediawiki-1.5.8/index.php/Collision_Callbacks_and_Triggers
  • https://sourceforge.net/projects/irrbullet/?source=typ_redirect

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.