Rotation around z only 0 - PI/2?

Hi,



I’m rotation around Z and outputting the rotation. I’m getting values from 0 to PI/2 (first fourth), then PI/2 to 0 (second), then 0 to -PI/2 (third), then -PI/2 to 0 (fourth).



Is this normal? Am I doing something wrong? with X and Y I get 0 to PI for the first half and then PI to 0 for the second.



Here’s the code:

[java]import com.jme3.app.SimpleApplication;

import com.jme3.input.controls.AnalogListener;

import com.jme3.input.controls.KeyTrigger;

import com.jme3.material.Material;

import com.jme3.math.Vector3f;

import com.jme3.scene.Geometry;

import com.jme3.scene.shape.Box;

import com.jme3.math.ColorRGBA;

import com.jme3.scene.Node;



public class Main extends SimpleApplication {



Node pivot1;



Geometry red;

Geometry yel;



public static void main(String[] args){

Main app = new Main();

app.start();

}



@Override

public void simpleInitApp() {



Box box2 = new Box( new Vector3f(0,0,0), 1,1,1);

red = new Geometry(“Box2”, box2);

red.setLocalTranslation(new Vector3f(2,2,0));

Material mat2 = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);

mat2.setColor(“m_Color”, ColorRGBA.Red);

red.setMaterial(mat2);



Box box3 = new Box( new Vector3f(0,0,0), .5f,.5f,.5f);

yel = new Geometry(“Box3”, box3);

yel.setLocalTranslation(new Vector3f(0,0,0));

Material mat3 = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);

mat3.setColor(“m_Color”, ColorRGBA.Yellow);

yel.setMaterial(mat3);



pivot1 = new Node(“pivot1”);

rootNode.attachChild(pivot1);



pivot1.attachChild(yel);

pivot1.attachChild(red);



inputManager.addMapping(“rotate”, new KeyTrigger(keyInput.KEY_M));



inputManager.addListener(analogListener, new String[]{“rotate”});

}



private AnalogListener analogListener = new AnalogListener() {



public void onAnalog(String name, float value, float tpf) {

if (name.equals(“rotate”)) {

//x

// pivot1.rotate(0.002f, 0, 0);

// System.out.println(pivot1.getLocalRotation().toAngles(null)[0]);

//y

// pivot1.rotate(0, 0.002f, 0);

// System.out.println(pivot1.getLocalRotation().toAngles(null)[1]);

//z

pivot1.rotate(0, 0, 0.002f);

System.out.println(pivot1.getLocalRotation().toAngles(null)[2]);

}

}

};

}[/java]

Print the other values of the toAngles() results and I think you will see what’s going on.

I see the rotation around X and Y becomes PI in the second quadrant, -PI in the third… in one case (rotation Z = -1.5707964) it says 0 for X, 2PI for Y…



Sorry don’t know really what’s going on :confused:

This is all normal. A single quaternion can technically be an infinite number of different Euler angle sets because Euler angles are not the most precise way to represent a rotation. When you convert a Quaternion back to Euler angles, the selection of which Euler angles to return is rather arbitrary and I don’t understand the math fully.



But in general

euler → quaternion → euler



Will in most cases produce different results even if the represented rotations are all technically the same.



If you want to keep track of an angle around the Z axis then you will have to do it separately as this information is not available in the Quaternion.

Ok, I solved it saving the rotation separatedly as you said…



But anyways a bit strange, I had expected some getter for this value, like there’s fromAngleAxis to set it…