JBullet on Android

JBullet is a pure Java port of the famous (and awesome) Bullet physics library. I played around it as soon as i got my first Android device in early october and started implementing a Super Monkeyball clone which was actually playable. Back than i wrote a JNI wrapper for the C++ version of Bullet and the performance was really good. Granted my scenery wasn’t all that complex, just a big static mesh, a few kinematic objects and single ball. (Ask me for the code of the wrapper if you want it).

After my small expedition into the realm of float vs fixed-point math in Dalvik a few days back i wrote a simple JBullet demo. It features a plane and 60 cubes that fall down from above, a classic hello world physics demo. The outcome was as expected, the thing is slow:

I get between 4-8fps, the majority of time is taken up by the physics simulation. When the cubes don’t touch the ground plane the simulation takes between 100-120ms, as soon as the cubes touch the ground the time needed goes up to 250ms. That’s not real-time enough i guess :). Never the less, the performance is actually not that bad given the multitude of overhead the Dalvik VM introduces. JBullet uses JStackAlloc to get rid of any heap allocations so garbage collection is not a big deal, as oposed to say JBox2D which is a messy garbage collection monster.

The performance of the JNI wrapper was actually really useable. For the Super Monkeyball setup it took no longer than 4ms, good enough for almost all purposes.

You can find the apk at http://file-pasta.com/file/1/MyriadDemos.apk or use the qr code below with your device

11 thoughts on “JBullet on Android

  1. It would be good to see a test of this app on a Nexus One device which I believe contains an FPU.

  2. I don’t have a Nexus One so i can test its performance there. However, i added the link to the apk in the post above for anyone to try.

  3. Is there any place to get your JNI code wrapper for Bullet? I am interested in getting a new game demo going and I have messed around with the other BulletForAndroidNDK code but it is a little buggy. If you have any example projects or demos that would be awesome. Thanks!

  4. p.s. I downloaded your androllz game and it is very smooth on my N1. I am guessing this is using Bullet under C++ and NDK with your JNI wrapper? Any reason you have not finished this and put it out on the market?

  5. Yes, it’s using Bullet via the NDK. I didn’t finish it cause the controls sucked :). Also, there’s now a nice new game on the market called SteamBall which does a better job overall imo (altough i think the camera movement could use some work).

  6. I’m afraid i don’t have the code anymore. My “wrapper” was not as elaborate as the Box2D wrapper and only consisted of 4-5 methods for setting up the world/sphere/mesh, stepping, and getting back the current location of the ball. It wouldn’t be of much use for anything else really.

Leave a Reply

Your email address will not be published.