Bullet + OF

Been developing a wrapper for Bullet. Pretty much have the bullet primitives done and collisions inside an event. Here is a experiment with spheres, cubes, bullet outlines, etc.

Check it out.


Nice! Love those spheres.

Very cool, is it possible to share the code?

Definitely. Going to clean it up a bit and I will post a link to github when it’s is postable.

Nick, are you wrapping the entire library, including the SSE vector math classes? I’ve written a particle class that uses them but it was a pain in the ass to set-up, and I’d love a cleaner interface to those classes.

I was thinking about re-implementing ofxVectorMath to use the bullet Vector classes and preserving the interface so they can be easily swapped out, but if the bullet addon has something similar I won’t bother.

nice glow shader ;))

@nick awesome work, looks really great!

@Tim_S Total sidenote but the ofxVectorMath addon is going away and will be implemented in the core in v007 which is getting released in the next week or so. Also, there’s a bullet addon that was put together on a project that I’ll post up as soon as I make sure it’s ok w/everyone else. I’m not sure it’s as complete as what Nick is doing, but it might be useful.

joshua, thanks for the info. I’m not convinced that the addition of SSE instructions made a huge difference for my particle system anyway. It may be that GCC was optimizing some vector operations into SSE already.


I love the illuminating fx when colliding :slight_smile:

Thanks everyone!

@Tim_S currently not wrapping the SSE library, but creating helper functions for primitive shapes for rigid bodies. Some of them being

ofVec3f getPosition();  
ofQuaternion getRotationQuat().   

I have added events for the collisions, which looks like this

ofAddListener(world.COLLISION_EVENT, this, &testApp::onCollision);  
void testApp::onCollision(ofxBulletCollisionData& cdata) {  
     // if the collision shape is not the ground //  
     if(ground != cdata) {  
          // we have a collision, not with the ground //  
          if(cylinder == cdata && sphere == cdata) {  
               // the collision is between the cylinder and the sphere //  

@joshuajnoble, sounds awesome, looking forward to your post. :slight_smile:

Finally got ofxBullet cleaned up and on github. The video below shows the included examples.


Included are all of the primitive shapes; sphere, cone, capsule, box and cylinder. Joints are supported as well, between two shapes and a shape and a location. Collision events can be enabled to fire an event. The object passed contains information about the collision, including the two colliding objects, the location of the collision, etc. Mouse events can be enabled as well, and pass an event similar to the collision events. Mouse grabbing is also supported. The custom shape example illustrates passing a mesh from a loaded collada file (the OF logo) and building the bullet shape. This custom shape class also takes all of the primitives and supports multiple meshes.

These screen captures are from the included examples; Simple, Events, Joints and Custom Shapes.

Check it out!
ofxBullet: github.com/?NickHardeman/?ofxBullet

just compiled the bullet2.78 as windows lib,but not sure whether it will work out. ???

I developed the addon working with bullet 2.77 and I have not tested it with 2.78. If it doesn’t work with 2.78, you can get 2.77 from here: http://code.google.com/p/bullet/downloads/list

Let me know how it turns out. :slight_smile:


Wow Nick this looks awesome! Thanks for your hard work!

Hi nick, i tried your code on windows7 with VS2010. but why i see lots of ‘$’ in the code?
e.g. in ofxBulletUtils.h the function static btRigidBody* ofGetBtRigidBodyFromCollisionShape(btCollisionShape* $cs, btTransform $tr, float $mass)

Hi Nick. Great work, works like a charm! Just a note: Had to change

camera.cacheMatrices = true  



in testApp.cpp as well as

mouseRay *= _camera->getFarClip()  


mouseRay *= _camera->farClip  

in ofxBulletWorldRigid.cpp for it to compile with OF 007

Mac OSX 10.6.7
OF 007
ofxBullet from https://github.com/NickHardeman/ofxBullet/tree/master/src

@yaya Haha. That is a habit I picked up from my Flash and PHP days. I use $ in front of function arguments.

@chrisg Did you have to change those in the examples? If so, which ones?


@Nick. The camera.cacheMatrices(true) thing was in both examples and mouseRay *= _camera->farClip was only used for the Event example if i remember right (present two places in ofxBulletWorldRigid.cpp). There was no getFarClip() function available in the OF (07) camera Class… Not 100% positive that the farClip refer to the exact same values though?

@chrisg Looking through the source on git right now. Maybe you have an older version? Try pulling the latest version from git. Right now there are a total of 5 examples, though one is just an empty one. I do remember removing the farClip bit because it was no longer in 007. Now I just multiply by an arbitrary number, I think 300. I also added a raycastTest function to take a start and end vector to test any ray cast hits.

Let me know if this helps.

These examples are great! Thanks a lot for making these.