Java port of Bullet Physics Library

Good point, I’ve added offer to do porting as a service. Details here. Also note that the initial aim is bigger because there are many things to do at current state. If successful (at least to some degree) next goals will be fairly smaller.

Yes, you may be right. The motivation behind this is to allow making JBullet even better than at current development rate which will continue even without donations. However at this rate we will be always several versions behind and many stuff not ported. The porting work is pretty tedious and typically this kind of work doesn’t occur in open source and I have feeling that nearly none people are able to steadily maintain this work.

New version available on JBullet homepage.

Changes in release 20090404:

  • Added ConeShape
  • Fixed thread safety issues when running distinct simulations in different threads simultaneously
  • Changed back to building of just one library JAR
  • Added run configuration for each demo in NetBeans project
  • Fixed compilation with JDK 1.5
  • Added fix for collision detection bug from Bullet 2.70
  • Generalized mesh access interface
  • Added ScaledBvhTriangleMeshShape
  • Added calculatePrincipalAxisTransform method in CompoundShape

As of current plans, I’m occupied with main projects more than before and I think that there won’t be any significant development in half a year (at minimum). If you need some functionality implemented earlier, consider donating, ordering porting service or contributing code.

Hi, i’m new to this Forum.
Was searching for a physics engine, to do some things in LWJGL.
First i thought about odejava, but it looks quite dead?
Now i’m happy i found this here, looks quite promising :slight_smile:

I think it’s awesome and impressive that you have done this. But I was thinking wouldn’t it have been a lot easier to
just make a binding ? I mean for each version you must look at every method to see if they have changed something, even if method names are the same, the might have changed something deep inside a nested for/next…and to spot that you need eagle eyes.
That must be pure hell, and I can’t imagine anything else than that errors will arise. I know a binding is not as cool, for applets etc. Still it would be easier to maintain…

I also have a question : do your version support joint motors ? (so that I can animate ragdolls)

Thanks, yes it would be easier. Actually I did binding first, but wasn’t satisfied with it for following reasons:

  • bad API interaction with native stuff
  • you need to track objects to destroy instead of just relying on GC
  • maintaining and testing native builds for all supported platforms is huge task
  • you can’t use it in secure (sandbox) environments such as unsigned applets
  • there was lack of full-blown pure Java physics libraries (bindings to other physics engines are already present)
  • wanted tighter integration with Java to use internal stuff and generally provide more Java-like library

As for porting process, I use tools that allows me to just track changes so it’s pretty straightforward to port it.

Basically it was huge short-term investment which returns very much in long-term, I’m already very glad I took this route as it’s great to use it in my apps.

I’m very precise when doing the porting, basically I do it manually line by line and there were minimum bugs arised due to porting in early versions. Hunting the bugs was great experience for me as they forced me to think more about Bullet’s internals (I discovered most evil bugs by just thinking without using computer after studying the internals), thanks to it I gained very valuable experience how to use Bullet and how the internal things interacts and it definitelly helped me in using the library in my applications. Also learned about many interesting algorithms that can be used in other contexts too.

Joint motors should be supported, check the constraints classes for more detail and demo (Dynamic Control Demo).

Great. I understand your motivations for this completely.
I’ll try jbullet soon as possible, maybe switch to that.
I have a little hobby project that currently uses PhysX…but for various reasons I’d like to switch to another engine.
One of the reasons is that it’s not pure Java, and that you have to “install” physx…very annoying.
Also another question : in the demo applet, what do you use to render ?
you use JME for the signed webstarts right ?

Also, I don’t think you should never give up on this project. Java is in DESPERATE need of a good physics engine. If you’re short of time, as we all are, then I suggest that you merge with the bullet team. Make them help you a bit. After all, it’s in their own interest as well.

Demo applet uses my own simple OpenGL-like renderer, but I’m not much interested in developing it further, so I’ll switch to 3DzzD when I’ll have more time (or combine parts of my code with renderer part of 3DzzD).

Webstart demos uses OpenGL directly (by LWJGL), like the original demos from Bullet.

I highly doubt I would give up on this project as I depend on JBullet pretty much in my applications. The development can stagnate a little (as it’s temporarily now because of lack of time), but I’m always available to answer questions and fix bugs (ie. by porting from newer Bullet versions). Also as the development progresses I use more and more features from JBullet so eventually I may cover big feature set by just using it in my applications so it warrants ongoing porting of new features, albeit at pretty slow rate.

I don’t think that merging with Bullet team would be any helpful or even possible, but little interaction occurs both ways (including bug fixing of original Bullet by finding bug in JBullet, me caring about original Bullet and it’s users, etc.). As of interests, Java is very low priority for Bullet folks as they’re focused to commercial PC/console gaming and Java has not yet much place there (definitely not on consoles). While there is also C# port (very outdated and unmaintained) for XNA so it works on XBOX360, interactions with Bullet team was similar as with JBullet.

I also use JBullet for ragdoll animation. Works fine, they walk.
Although took long to program them to move their legs somewhat reasonably.
I apply a cheat torque to their pelvis, else they fall.
Initially my ragdolls had no elbow or knee joints. (I thought I should save some CPU by reducing the number of bodies and joints.) This did not work well.

Regards, Magnus

how did you make them walk, balance etc ?
OK just read, the cheat force (thats what I do to)…but how do they walk ?
Personally I just make a walking animation…and then I change materials on the fly.
For example, walk forward1 pose, I make left foot super slippery, that way it’s like he lifts his foot a bit.

Hi NewbTon,

If you google for “walk cycle”, you might find 4 + 4 images (left leg walking + right leg walking) illustrating 4 + 4 poses a biped takes whilst walking (for example, http://www.idleworm.com/how/anm/02w/walk1.shtml). If you drive the limb-joint-motors towards these poses, and at the same time apply a torque so the biped doesn’t fall, then friction feet-ground will entail it moves forwards.

(So, first I try to orient the biped’s limb after the first pose. Then, when the biped is reasonably close to this pose, I switch target pose: I apply motor torques to reach the second pose instead. And so on. To determine whether the biped is reasonably close to one pose: One could sum angle errors. Or simply assume it’s close enough after having tried to reach that pose in 100 ms. And then switch to the next target pose. For some poses, I switch to the next pose when the appropriate leg makes ground contact.)

I don’t know, however, how to make the biped turn around. It’s much more complicated movements I think. Perhaps it’s better simply to apply a fairly huge cheat torque to the pelvis and head, so that the whole biped rotates (in an unrealistic manner). Then perhaps I should do what you have done, make the biped’s feet super slippery, so the feet doesn’t get stuck whilst the head and torso rotates 180’. :slight_smile:

OK that sounds logical…may I ask what kind of constraints (joints ) you use ? Is it hinge or ball ?
I have this game in PhysX and I’d like to know if it’s possible to port it to jbullet:

What’s you’re opinion on that ?

Hey Jesek when I try to run the demos in Eclipse I get this error.
Exception in thread “main” java.lang.Error: not instrumented
at cz.advel.stack.Stack.alloc(Stack.java:110)
at com.bulletphysics.collision.broadphase.AxisSweep3Internal.(AxisSweep3Internal.java:90)
at com.bulletphysics.collision.broadphase.AxisSweep3.(AxisSweep3.java:52)
at com.bulletphysics.collision.broadphase.AxisSweep3.(AxisSweep3.java:44)
at com.bulletphysics.demos.forklift.ForkLiftDemo.initPhysics(ForkLiftDemo.java:544)
at com.bulletphysics.demos.forklift.ForkLiftDemo.main(ForkLiftDemo.java:860)

You know what that might be ?

Edit: never mind, I found out that I have to build using ant. And create projects properly.

EDIT2: I type “ant” and I get this error :
BUILD FAILED
C:\Users\Mikkel\Desktop\jbullet-20090404\jbullet-20090404\nbproject\build-impl.x
ml:569: The following error occurred while executing this line:
C:\Users\Mikkel\Desktop\jbullet-20090404\jbullet-20090404\nbproject\build-impl.x
ml:220: The for must include junit.jar if not in Ant’s own c
lasspath

I’m trying to put junit in the lib directory now.

Another question : Is the jar generated from the build different from the jbullet.jar included ?

Edit : OK got it working by copying the demos to it’s own project, then include the jars.

I create the jar by running the ANT build script outside IDE. If you wish to fiddle with examples, best is to use provided jbullet.jar and just copy the com.bulletphysics.demos packages into your project (they don’t use StackAlloc), then it should run fine. Or use provided ANT build script.

As this issue is pretty common I will create NetBeans and Eclipse projects for just demos (and using included jbullet.jar) to make it more easy to start for users.

Alright thanks, it works now in Eclipse. But when I run the Ant script (outside IDE) I don’t see it doing anything.
There’s still just the old jar. And that one works fine to begin with. Just curious, anyway it all works fine, and I’ll now try to use
jbullet in my app.

Hi NewbTon,

Both hinge and ball.

Bullet Physics has recently made improvements to the ConeTwist joint.
(http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=18&t=3177)
Had these improvements been available in JBullet, I’d preferred to use
the new ConeTwist constraint, instead of my current approach,
with 2 constraints per biped parent-child limb joint.

My current approach:
Each joint has 2 constraints: (1) A passive ConeTwist or HingeJoint
constraints that restricts movement, and (2) a Generic6DoFConstraint,
that applies muscle actuation. To apply muscle actuation, I rotate the
frame of the 2nd body attached to the Generic6DofConstraint. I
don’t use the setAngular{Lower/Upper}Limit functions.
(I had to add a function that allows modifying this second frame
after the creation of the Generic6DofConstraint.)

(I think the reason I used 2 constraints was:

  1. Easier to define max-rotation-limits using ConeTwistConstraint
    (than with Generic6DofConstraint).
  2. (JBullet’s current version of) ConeTwistConstraint doesn’t allow defining both
    max-rotation-limits and a different desired rotation. So
    I used a second constraint, the Generic6DofConstraint, for this.
    (I.e. for muscle actuation.))

   // Below, childPart might be an upper arm,
   // and parentPart would then be the torso.
   // Or the child part could be the left shin leg;
   // the parent part would then be the left thigh.)

   // The constraint that just limits movement.
   if (constraintType == HINGE_CONSTRAINT_TYPE) {
      childPart.joint = new HingeConstraint(
            parentPart.physics(), childPart.physics(),
            new Transform(parentFrame), new Transform(childFrame));
   }
   else if (constraintType == CONETWIST_CONSTRAINT_TYPE) {
      childPart.joint = new ConeTwistConstraint(
            parentPart.physics(), childPart.physics(),
            new Transform(parentFrame), new Transform(childFrame));
   }
   ...
 
   // The muscle actuation constraint.
   childPart.motor = new Generic6DofConstraint(
         parentPart.physics(), childPart.physics(),
         new Transform(parentFrame), new Transform(childFrame), true);
 
   // To apply muscle actuation, the motor child frame is rotated
   // (relative the parent frame); the motor limits remain 0, always.
   childPart.motor.setLimit(3 + 0, 0, 0);
   childPart.motor.setLimit(3 + 1, 0, 0);
   childPart.motor.setLimit(3 + 2, 0, 0);


// And in some function, to rotate the child body part
// relative the parent body part:

   childPart.motor.setFrameBaseB(newRotation);
   // Function is not present in JBullet, but see below:


public class Generic6DofConstraint extends TypedConstraint {
   ...
   public void setFrameBaseB(Quat4f basis) {
      frameInB.basis.set(basis);
   }
   ...
}

And then there are functions that set the childPart.joint limits.

I’ve seen that game before :slight_smile: (You’re the author, I gather?) I like
that approach, mainly physics and gameplay, rather than graphics.

My bipeds only walk forwards, slowly. No quick movements, as of now.
So I do not know if it’s possible. But I guess it is, and that it
would work as well as with PhysX.

Hi, some of you wanted to know more about the projects I’m doing with JBullet. Recently I’ve implemented ragdoll into my engine and created video of it: ragdoll.avi (16MB, xvid). Enjoy :slight_smile: and forgive small FPS (and pause at end) it was mostly due to recording overhead.

Those were beautiful ragdolls.

That was 3DzzD? May I ask, any reason you’ve chosen 3DzzD not jPCT? I can think of one, that 3DzzD is open source?

Thanks :slight_smile:

No, that’s custom specialized engine that is in development for about 2 years.

I’m currently not using 3DzzD nor jPCT, though in future I would like to use 3DzzD (or it’s parts) for JBullet’s demo applet which uses software renderer and yes, it’s because it’s opensource (and rendering quality seems better than jPCT’s). jPCT would be fine for the demo too, but I need similar interface as OpenGL (or some raw access to just rasterizer) which jPCT doesn’t provide.

New version available on JBullet homepage.

Changes in release 20090628:

  • Added conversion methods between Transform and Matrix4f
  • Fixed bug in ShapeHull
  • Added CollisionWorld.updateSingleAabb method from Bullet 2.74
  • Added CollisionWorld.convexSweepTest
  • Added ConcaveConvexcastDemo

Please add following code into initialization part of your application if you want to use convexSweepTest otherwise not all collisions are detected. This will be unnecessary when JBullet get ported to Bullet 2.73.


dynamicsWorld.getDispatchInfo().allowedCcdPenetration = 0f;

Thank you for donations, I will be able to start working soon on initial porting of changes from newer versions, most notably to port to final 2.70 release (some bits are still on 2.66 and rest on 2.70-beta1) which will fix issue with tearing of joints.

That is good news, I still haven’t got around to porting my application from PhysX to JBullet though. I think it would be worth it though.