# quaternion to angle

Alright, so this is how I am doing it:

float xrot = 0;
float yrot = 0;
float zrot = 0;

Quaternion q = new Quaternion().fromRotationMatrix(player.model.getRotation());
if(q.getW() > 1){
q.normalizeLocal();
}

float angle = (float) (2 * Math.acos(q.getW()));
double s = Math.sqrt(1-q.getW()*q.getW());
if (s < 0.001) { // test to avoid divide by zero, s is always positive due to sqrt
// if s close to zero then direction of axis not important
xrot = q.getXf(); // if it is important that axis is normalised then replace with x=1; y=z=0;
yrot = q.getYf();
zrot = q.getZf();
// z = q.getZ();
} else {
xrot = (float) (q.getXf() / s); // normalise axis
yrot = (float) (q.getYf() / s);
zrot = (float) (q.getZf() / s);
}


But it doesn't seem to work when I try to put it into use:

player.model.addTranslation(zrot * player.speed, 0, xrot * player.speed);


AddTranslation takes 3 numbers to move my model by than many spaces (x, y, z), but hen I give it the numbers above it doesn't move the model in the direction it has been rotated (on the XZ plane)

-
What are you trying to accomplish? Could you edit your question and tell us? – Ryan Budney Dec 14 '10 at 1:41
I'm trying to move a model in the direction that it's facing. – CyanPrime Dec 14 '10 at 1:44
I don't understand what it is you're looking for. – Ryan Budney Dec 14 '10 at 1:55
I wanna make the quaternion's y into a degree (0 to 360) – CyanPrime Dec 14 '10 at 2:19
If you are trying to move the character in the direction that the character is facing, there is no need to convert to a quaternion, you can use out vector of the rotation matrix. I would ask the question "How do I move translate a character in the facing direction?" here: gamedev.stackexchange.com . If no one answers the question there, I will. – Jonathan Fischoff Dec 14 '10 at 2:23

P_{k+1} = P_k + U*speed*dt