Difference Between Rotations

Hello there.

Is it possible to calculate difference between 2 rotations on the same Y axis ?

Im tryng to create a body control, witch will turn around if the difference of the head rotation from the body rotation is big enought, then the body turns !

Im tryng this simple way:

[java]float diff = headNode.getLocalRotation().subtract(bodyNode.getLocalRotation()).getY();[/java]

Im rotatin the head’s angle using the following:


// angle = angle to mouse pointer in screen to character position

public void turn(Node n, float angle, RoundCamera cam) {

Quaternion lookAtMouse = new Quaternion();

lookAtMouse.fromAngleAxis((FastMath.PI * angle / 180), new Vector3f(0,1,0));

// look at mouse coords


headNode.rotate(0, -cam.getAngle(), 0); // fix coords for changed camera angle


And this, is one tryout of what i want to do. Ive tryed the first mentioned method to call difference with this too:

[java]public void setAngleRotation(RoundCamera cam, float angle) {

turn(headNode, angle, cam); // makes head follow mouse

float diff;

if(headNode.getLocalRotation().getY() > (bodyNode.getLocalRotation()).getY())

diff = headNode.getLocalRotation().getY()-(bodyNode.getLocalRotation()).getY();


diff = (bodyNode.getLocalRotation()).getY()-headNode.getLocalRotation().getY();

if(angle<=270 && angle > 90)

left = true;


left = false;


if(diff > 0.5f) {


bodyNode.rotate(0f, 0.2f, 0f);


bodyNode.rotate(0f, -0.2f, 0f);




Local rotation is a Quaternion… which for the sake of this discussion is a “magic box with swirly sparkly bits inside”. The x,y,z,w values are those magic swirly bits and should not be used directly. This is 4 dimensional space we’re talking about.

You probably want to convert them to angles with something like toAngles(). The second value is rotation around the Y axis (despite what the Javadoc might say).

It will be +/- 180 degrees (well, in radians) so you will have to do some math to get a proper delta between two separate values.

So, ive been banging my head over the wall cuz of this… i cant handle Quaternions well they too magical for me yet. When i changed a little value on his axis and the object started to move like crazy i was like, “WTF, wasnt this the rotation” ?

its the first time im dealing with 3D, and im really bad at math so this aint goin easy to me, so im gettin punched in the face specially about rotations.

Ill try to explain here what im tryng to do, in every step so i kno im going the right way.

Whats Done:

1- Theres a character, with a camera following him from above him.

2- The characters face is aways pointed at the mouse cursor position (measured in degrees, center of the screen is aways the character)

3- When the camera rotates, the character face rotates as well so i can still look at the mouse pointer.

Now, the problem:

When the face rotates, i want to check if the face is rotated more then 50 degrees from the angle the body rotates a little bit, so it can only have 50 degrees of difference from the head.

Ive wrote more then 100 lines tryng to do this, ereased it, done again, and failed again… The major problem is 360+1 = 0 so i would have to spend alot of cpu to figure out angles. Is there an easy way to do this ?

Thanx alot for any help.

[EDIT] Solved. I gotta stop drinking too much n coding.