Rotation: Calculate the rotation axis

Hey guys,

i am trying to implement a rotation to a object. The rotation seems to be like opening a door. My rotation axis has to be the door hinge(and it is not Vector3f.UNIT_X/_Y/_Z). At the moment my door rotates around itself…How could i calculate the rotation axis?

Here my code for the rotation:

[java]Quaternion rota_left_shutter=new Quaternion();

Quaternion rota_right_shutter=new Quaternion();

Vector3f rotateVec=new Vector3f(1f, 0, 0f);

rota_left_shutter.fromAngleAxis(-FastMath.HALF_PI, rotateVec);


Two additional questions:

[java] Vector3f rotateVec=new Vector3f(1f, 0, 0f);[/java]

This is the Vector from Orgin (0/0/0) to the Point(1/0/0), right?

How could I create a Vector in jmonkey between two Points(For example P1(1/2/3) and P2 (2/3/4)?

[java] rota_left_shutter.fromAngleAxis(-FastMath.HALF_PI, rotateVec);[/java]

Thats the right function for my rotation?

I have already read :

and was looking for an rotation Matrix:

[java]Matrix3f mat = new Matrix3f();

mat.setColumn(0, new Vector3f(1,0,0));

mat.setColumn(1, new Vector3f(0,-1,0));

mat.setColumn(2, new Vector3f(0,0,1));


But here i dont now how to calculate the Vectors.

Could someone give me please some help?

If you have read math for dummies you know how to use direction vectors and make quaternions from them. So do that. Its much better than working with rotations and/or rotation axes directly as you don’t have to deal with gimbal lock and euler angle conversion among other things.

1 Like
@barak said:
[java] rota_left_shutter.fromAngleAxis(-FastMath.HALF_PI, rotateVec);[/java]
Thats the right function for my rotation?

Point your finger in a direction. Imagine a ring around your finger. The vector is your finger and HALF_PI is how much you want to twist the ring.

The rest of your post about vectors makes me think you still didn't fully understand the math for dummies stuff. You may want to read it a few more times.
1 Like

i did not unterstand at the moment how to set the up vector and the direction vector…

But that have to be my code, isn´t it?


//rotate my object

Quaternion rota_left_shutter=new Quaternion();

Vector3f rotateVec=new Vector3f(0f, 0, 1f);

Vector3f directionVec=new Vector3f(0,1,1);

rota_left_shutter.lookAt(directionVec, rotateVec);


Tomorrow,I will give it a try with a test application for a better understanding…

One question i have: Is my Up vector and my direction vector next to my object (placed somewhere in universe) or next to the origin?


You do know that rotate() combines the rotation with any existing rotation on the Spatial?