I have a game written in java and I need some physics

Hi guys ;D I’ve been working on a game for a while now and its getting to the stage where netoworking is good game-play is good and things are really comming together well, but I have hit a wall with the physics side of things(no pun intended ;)). My game is in space and does not require the physics to be very involved. But I would like to have fairly realistic collisions between meshes in space. I’ve been looking at odejava but that project seems to have been abandoned and Ive had a read through a few post here on JOODE but I dont know if its upto the job yet. Can anyone offer me some advice on how I could proceed?

Well, using OdeJava should be fine. Even if it seems somewhat inactive. Which scenegraph do you use? If you are using jME, of course, jmephysics 2 (which also uses ODE) would be best suited… and I believe there is a Newton Java binding around… DP, didn’t you do something like that?

At the moment I cannot encourage you to use JOODE. The trimesh implementation is not known to be finished in the near future.

JOODE apers to have no download on dev.java.net

I’m using a OGL scene graph written in C++ with a java binding. So I need somthing that works independent of the scene graph.

Thanks for the advice I’m going to give odejava a shot. jme physics 2 sound very interesting pitty its not independent of jme.

Nope, i did a Novodex binding; but thats heavily tied in with my other projects, so there’s no hope of anyone else using it without going through miles of code :frowning:

I would recommend you use Odejava for the time being…its stable and works and the annoyances in it are documented through the pages and there are some work arounds.

If your using C++, why not just use Novodex yourself through their API ?

DP

Ok thanks, the reason I dont use novodex/physX or newton or somthing with a C++ API is that I dont want to have to program in C++ the reason for using the java binding was because I can code at least 10 times faster in java than C++. I’m going to give odejava a shot it sounds like it may do the trick.

the dev.java.net version of joode only exists, because we first requested JOODE at java.net, but because java.net was so slow we used then sourceforge instead http://joode.sourceforge.net/. But to get the code, you’ll also still have to checkout the cvs at sourceforge, but a build will come soon!

back again ;D. I’ve had a bit of a play with odejava and it seems to be ok for what I want. What I need help with now is a bit of program design. My scene graph is not thread safe and in order to get it to run I need to have a while loop and call renderScene(). Each loop I change the position/rotation of the objects in the scene based on user input. Currently I move nodes based on the time it took to render each loop. What I want to do is call odejava and say its taken X amount of time to reneder this frame move everything relative to X, then I want to be able to get the new postitions of all my nodes set them in the scene and start the next loop. Can somone just give me a few ideas of whats required to do this.

Edit: I’ve have intergrated odejava with my scene graph, I’m still not sure about how to get it to run based on time.

Edit 2: is there an easy way to work out scale between my scene graph and ode? The objects I draw are not the same as ode objects.

I’m not sure I understand what you mean with scale. But if you have a nested scenegraph you can forget about using
ODE as I understand it. You need to flatten your scenegraph first, that means all nodes must reside at the same level.

odejava and my scene graph are woking together fine. The problem I have is that 1 unit on my scene graph is different in size to 1 unit in ode.

I have another problem now as well. I have a body in space and I want it to have a thrust from an engine, the problem I have is that each loop of my program I do Body.setForce(forceWithDirection), The body keeps getting faster and faster it never reaches top speed(or doesnt seem to). There must be somthing I need to do the counter the thrust force so that the body reaches a top speed. This is also creating the problem that when I turn the body it has momentum in its original direction that never goes away unless it is directly opposed(ie the ship turns 180 and thrust in the reverse direction). I think these two problems are one in the same. I some how need to create a force that reverses old forces so that the new ones can move the body in a more friendly manner.

have a way to stop your while loop for the fist probled do this


int cCount;
while(a == true) {
 cCount += 1;
 Body.setForce(forceWithDirection);
 if(cCount > ?) {
     a = false;
  }

}

yeah thats a solution but not a very dynamic one. Currenly I’m thinking that if I do body.setForce(forceWithDirection-Velocity) it fixes the problem as long as I’m going forwards, if my body goes backwards I’m adding the thrust with the velocity and getting more thrust that I should. There must be some sort of calculation I can do to get it so that it work no matter which direction my body is traveling.

in Odejava you call step to process the simulation, so you simply can dynamically set the step size.

ok, tried that and it works well thanks.

sure , but steping through the simulation with a different time each iteration should be avoided. the step(float steptime) method can create quite a mess (unpredictable behaviour) if your step times vary too much. Ode supposedly does a lot of predicting in between steps. it’s better to step ode with a constant step time and to adjust the sleep time in between steps to compensate.

mmh that could explain, why I sometimes got those jumpy effects…

yeah In that case I’m going to use a constant step size and I’m got to try to control the velocity of each body manualy.