Java physics engines?

Post Reply
amazed
Posts: 1
Joined: Mon Jun 26, 2006 4:45 pm

Java physics engines?

Post by amazed »

I'm a total newbie to physics engines and have been doing a lot of reading both on this site and others (such as ODE's). All the engines I've found seem to be written in C++. Is there an engine written in Java?

I know there is a odeJava engine, but that's really C++ with a Java wrapper (ie JNI). Java calls native C/C++ calls rather than a pure Java implementation. Java gets faster every year, and recently I saw a report of Java being only 1.1 times as slower than C++, so a Java physics engine would be a valuable asset.

Is there such a beast?

Amazed
kevglass
Posts: 7
Joined: Mon Aug 07, 2006 6:48 pm
Location: Davis, CA, USA
Contact:

Post by kevglass »

There is the JOODE effort:

https://joode.dev.java.net/

Kev
User avatar
SteveBaker
Posts: 127
Joined: Sun Aug 13, 2006 4:41 pm
Location: Cedar Hill, Texas
Contact:

Post by SteveBaker »

Generally, Java only comes close to C++ when a large fraction of the execution time is spent in some of the more nicely written heavyweight libraries. Those libraries are frequently written in C or C++ for speed. So measuring the actual performance of raw Java is a somewhat contentious matter. Some benchmarks I've tried in which all of the work was honsestly being done in the actual Java code, came out with Java being ~50 times slower than C++...so I guess a lot depends on what you are doing!

It seems to me that if you need to use physics within a Java program, you should be looking for a C/C++-based physics engine - and adding Java bindings to it so you can use it within Java code. That's not at all unreasonable since it keeps the heavy math in the C++ code and leaves you to do the high level organisational stuff in Java where it's easier to put together than with C++.

So I guess the bottom-line question might more reasonably be: "Has anyone written Java bindings for Bullet?"
Mojomonkey
Posts: 1
Joined: Tue Jan 02, 2007 10:25 pm

Post by Mojomonkey »

"Has anyone written Java bindings for Bullet?"
Ping that.

Has anyone done so? If not, I'll be starting this task Real Soon Now, but don't want to continue with an effort that someone else has accomplished.

BTW: Hi, everyone. ;)
User avatar
SteveBaker
Posts: 127
Joined: Sun Aug 13, 2006 4:41 pm
Location: Cedar Hill, Texas
Contact:

Post by SteveBaker »

Mojomonkey wrote:
"Has anyone written Java bindings for Bullet?"
Ping that.

Has anyone done so? If not, I'll be starting this task Real Soon Now, but don't want to continue with an effort that someone else has accomplished.

BTW: Hi, everyone. ;)
Theoretically, you could use 'swig' to do that automatically - dunno how good it is though.
ewjordan
Posts: 26
Joined: Sat Jun 30, 2007 4:34 am

Re:

Post by ewjordan »

SteveBaker wrote: It seems to me that if you need to use physics within a Java program, you should be looking for a C/C++-based physics engine - and adding Java bindings to it so you can use it within Java code. That's not at all unreasonable since it keeps the heavy math in the C++ code and leaves you to do the high level organisational stuff in Java where it's easier to put together than with C++.
I know this is a pretty old thread, but I'm reviving it just to say that I don't think Java bindings are sufficient for most people doing games in Java. The main reasons to program a game in Java these days would be a) for web applets (sort of passe at the moment, to be fair), and b) for mobile phone games. For mobile phones, at least to my knowledge, native code is a no-go. Since this is an up and coming market (especially with the arrival of OpenGL ES, assuming that takes off), I think a robust pure Java engine would actually be fairly useful, though feel free to disagree, I'm not exactly an expert here. You're obviously not going to squeeze the same performance out of a phone running Java as from good clean C code compiled well for a regular computer, but that doesn't mean that it's pointless to do what you can with the platform.

So have there been any pure Java ports of any of the current popular physics engines? From what I can tell there's not too much Joode activity, but I've never used it so I don't know exactly what state the project is in. Has anyone actually used it in a real project?

Another issue for the phone market: has anyone ever put together a full featured physics engine using only fixed point math? As far as I know, this is crucial for at least the current generation of phones. Not having dealt extensively with fixed point porting myself, I don't know how troublesome it would be to migrate an existing engine to this form (not to mention the troubles in trying to get C/C++ code converted to a form that will run fast in Java).

Is there enough desire for this type of stuff to make it worth starting a Java port of (perhaps a subset of) Bullet, or would it be wasted effort? If there's enough interest I might find some time to donate, but a lot of that depends on the relative usefulness of such an undertaking.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Re:

Post by Erwin Coumans »

ewjordan wrote:
SteveBaker wrote: So have there been any pure Java ports of any of the current popular physics engines? From what I can tell there's not too much Joode activity, but I've never used it so I don't know exactly what state the project is in. Has anyone actually used it in a real project?

Another issue for the phone market: has anyone ever put together a full featured physics engine using only fixed point math? As far as I know, this is crucial for at least the current generation of phones. Not having dealt extensively with fixed point porting myself, I don't know how troublesome it would be to migrate an existing engine to this form (not to mention the troubles in trying to get C/C++ code converted to a form that will run fast in Java).
There is a C# port of Bullet, that runs in Silverlight and on XBox 360 XNA, at very good speed (slower then C++, but not that much). See http://chriscavanagh.wordpress.com/2007 ... ap-update/

So it should be possible to port each C++ or C# class over to Java, and get good results. Using fixed point math would be interesting experiment, there is some open source fixed point math library (and some cool software rasterizer) at Trenki.net.

Thanks,
Erwin
ewjordan
Posts: 26
Joined: Sat Jun 30, 2007 4:34 am

Re: Java physics engines?

Post by ewjordan »

Alright, if I have the time I might see what I can accomplish here, probably with floating point at first - a Java port might be tricky to get running very fast, I'll have to take a look through and see whether there are things that could easily be changed to fix this (in particular object creation can be a huge time waster in Java, I'll have to see if I can get the vector math stuff running without creating too much garbage; I've had entire simulations that turned out to be overwhelmingly bound by the creation overhead of vectors in Java, so this might turn out to be important, whereas in C++ it's not as much of an issue).

Assuming I have the time to get started on this: I saw at http://www.bulletphysics.com/Bullet/php ... 33&start=0 that your advice was to start off with the following classes and try and get spheres working with BasicDemo:

BulletCollision\CollisionDispatch\btSphereSphereCollisionAlgorithm.cpp
BulletCollision\BroadphaseCollision\btSimpleBroadphase.cpp
BulletCollision\BroadphaseCollision\btOverlappingPairCache.cpp
BulletCollision\CollisionDispatch\btCollisionObject.cpp
BulletCollision\CollisionShapes\btSphereShape.cpp
BulletCollision\NarrowPhaseCollision\btPersistentManifold.cpp
BulletDynamics\ConstraintSolver\btSequentialImpulseConstraintSolver.cpp
BulletDynamics\ConstraintSolver\btContactConstraint.cpp

Does that advice still hold?

If I'm able to get something together, I'll see how it's working and then make a decision as to whether it seems worth the effort to do either a) a more or less full featured "normal" Java port, or b) an ME version with fixed point math, perhaps somewhat feature-trimmed (though honestly, this might still be biting off a bit more than I can chew, since my experience with Java ME is minimal, but we'll see...).
Post Reply