Absolute rotation in space

Hi everybody,

I apologize for any english grammatical problem in my post, I’m french and I’m not trusting a lot my ability to speak a perfect english.

Anyway, i’ll try to expose my problem.

I’m developping a little game of space battle, based on Albator universe.

I’m actually in front of a mathematical problem.

I would like to simulate the physics properly relative to space, it means that if you make turn a vessel, it turns infinitely the same way until you make an other move.

that’s what i want to simulate, using a method called keepMoving(float tpf) executed in the loop() method, itself executed in the simpleUpdate() method of the main class.

I tried many ways to find a solution, but the best result I can get is to get a relative rotation of the vessel. I mean, in space the infinite rotation of the vessel should be absolute, but in my case, it’s only relative to it.
To give an exemple, if I want to make the vessel’s nose go up and roll it a the same time, it should go on the same straight “road”, just rolling and doing looping on itself. But what I only got is a vessel going in spiral…

I don’t know if I make myself understanded clearly, if it is not the case, ask me more precision, it’s a problem difficult to explain, more the fact that english is not natural to me.

Thanks for reading, and happy first post to me!


Hi theodeme,

if I understand you correctly, you just want to simulate newtonian physics of an object in space, right?
So no friction or gravity.

Is there any reason on why you don’t use the JBullet physics for simulating this stuff for you?

If there is a reason, where exactly is the problem? Just keep rotating your ship using its rotation quaternion
and move it along its directional vector.
I think here:
is all you need.

Actually the reason is simple, I didn’t study the physic part of the api, I thought it was not necessary to do it, and that it was precisely only to simulate gravity etc, but i wouldn’t be surprise if I were wrong.
Is it more simple to use Jbullet ?

thank you for the link. I’ll try to find what I need. But the ship’s directional vector isn’t relative it?

Track the rotation using a direction and up vector, unless you are really able to deal with things like gimbal lock and euler angles using rotations directly will only give you headaches:

With the in jme implemented physics it is quite simple yes.

By the way, I know it is tempting to dive into coding without a thorough look at the documentation and tutorials but it is worth it. Also if you have a problem just search in the forum first before posting. There is a good chance someone else already solved the problems. ( I don’t want to imply that you didn’t - just a suggestion in any case :wink: )

For example here:

PS: Don’t worry about language issues - english is not the native language of a lot of users in this forum and I didn’t met any gramma nazis so far :stuck_out_tongue:

Wow… Actually I’m quite lost now. That is the kind of situation that makes me remember that I did litteraries studies… But I’m not giving up!

I think I understood how to rotate vectors (I read all the math for dummies wiki), but I do not have any Idea of how to use the vectors to rotate my ship globaly, or how to use physics to do the same… Well, is it a kind of beginner’s despair that I feel ? Maybe.

I searched a little on the forum actually, but maybe not enough apparently, I didn’t find this post. That do not means that I understand it… I begin to think that I’m a little bit dumb.

Well, thank you for the help, I don’t know if you can do more than the wiki, it’s my job to understand it…

Anyway, that’s good to now that there is not any gramma nazis here. Even in french I’m not sure to survive to them… !! :wink:

Just rotate the up and direction vector to turn the ship and when you need a quaternion to set a rotation, do newQuat.lookAt(direction, up). If you use physics you will have to work with forces, angular and linear.

Actually, i use a node called vesselNode, that has for child the spatial vessel that contains the mesh.

Using your method, how can I apply the up and direction vectors to this node to make it rotate globaly? …

@theodeme said: Actually, i use a node called vesselNode, that has for child the spatial vessel that contains the mesh.

Using your method, how can I apply the up and direction vectors to this node to make it rotate globaly? …

Like I said by setting that quaternion.

@theodeme said: Actually, i use a node called vesselNode, that has for child the spatial vessel that contains the mesh.

Using your method, how can I apply the up and direction vectors to this node to make it rotate globaly? …

If vesselNode’s parent has not been rotated globally, then you simply set the local rotation of vesselNode:
Quaternion q = new Quaternion();
q.lookAt(direction, up);

If vesselNode’s parent might have been rotated globally, then you need to invert that rotation first:
Node p = vesselNode.getParent();
Quaternion inverse = p.getWorldRotation().inverse();
Quaternion g = new Quaternion();
g.lookAt(direction, up);
Quaternion q = inverse.mult(g);

And go with the “use bullet” advice… 3D angular momentum as you describe is not easy to calculate on your own. Just let bullet do it.

Note: I think you guys might miss his real issue. He wants to simulate rotational thrust of a free floating body in space… where if you apply thrust to get the nose to pitch up then it keeps pitching up until a counter thrust. If you then applied thrust to make it roll then it rolls relative to the up-pitch that already exists.

…but the math is non-trivial. Bullet already does it, though.

I think it will be clearer with my code, maybe should have do it since the beginning.

pspeed is right when he is saying that I want to simulate a free body in space, with realistics physics.

I explain what follows :

I’ve got a class “Objects” that extends from Spatial, including special properties of the objects in my game.

an object has got two node, a global node called"node", and a rotation node called “rotationNode”, child of “node”.
the main class is called Game, it initializes the controls, load the meshes, and got simpleUpdate method that executes every loop method of an “Objects” object execute his code.

keepRolling() is a method executed in the loop() method of the vessel in question. it simulates the infinite movement produced when you make it roll.

I’m quite lost with all you said, I mean, how to apply the direction and up vector on my rotation node, etc…

do not hesitate to tell me to go to hell with my beginners and dumbs questions, or to go RTFM.

public class Vessel extends Objects{
private TheodemeMaths math = new TheodemeMaths();

ArrayList<Canon> canons;

float fullPv; //the basic life of a Vessel
float PV;//life of the vessel
float speedLimitFighting;//the  speed limit for dogfights (to put in a final)

float rcsPower;
float enginePower;

public Vessel(){

public Vessel(Node parentNode){

//method that executes the rolling of the vessel, to use in the loop() method
public void keepRolling(){

public void keepTranslating(float tpf){

//kill the permanent rolling of the vessel in space to make it fix again
public void killRolling(float tpf, float value){

private boolean checkRollingKilled(){
  return false;//not yet implemented

public void moveIt(String whatToDo, float value, float tpf){


} [/java]

Hum sorry, vesselNode = rotationNode, i changed its name for a test…

Rolling your own for this will be pretty tough… as I imagine if the math came easy to you then you’d have already done it. I think both of my game physics books devote an entire chapter to angular momentum and torque.

I seriously recommend you use a bullet RigidBody for this and just apply the appropriate angular acceleration as required.

I start to explain but I have a feeling that I will lead you down the wrong path unless I provide a lot of background for several areas. For example, if I start talking about x,y,z rotational velocities without spending two paragraphs talking about how these are NOT Euler angles and treating them as such will lead to many many issues… I’m just not sure I have the time.

And bullet already does it.