# libGDX Quaternion.getAxisAngle(Vector3, float) returns only values between 0 and 180

This topic is 2156 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey guys,

I may have encountered a bug, but I'm not sure, maybe this is the way quaternions work.

I try to calculate the models roatation based on the camera angle, the angle of the analog stick, the model angle and the time.

So far my code works out well as long as my model keeps being rotated between 0 and 180 degrees (counterclockwise, along y-Axis, y-Up). To get the ModelInstance's rotation (still along y) I use

Quaternion quatRotation = new Quaternion;
modelInstance.transform.getRotation(quatRotation);
float rotation = quatRotation.getAxisAngle(new Vector3 (0f, 1f, 0f)) % 360f;


but rotation is always between 0f and 180f. Even if I'd expect (because I see it on my display) the value to be e.g. -6f it still is 6f. So basically the rotation gets mirrored along x-Axis.

Do I do anything wrong or is this a bug within libGDX?

Lukas

##### Share on other sites

Hello again,

I patched it up by storing the yaw seperately in my player class.

I hope anyone has an swer to this for me to have it the "clean" way.

Happy Hacking

Lukas

##### Share on other sites

I suspect the method getAxisAngle doesn't do what you think. The parameter is used for output, not input. So you have a variable of type Vector3, you pass it to the function and the function fills it with the axis. The angle returned is around that axis.

So you are building the rotation as "-6 degrees around (0,1,0)" and you are getting "6 degrees around (0,-1,0)" back. This is correct, because those two are the same rotation, and the quaternion has no way of telling the difference. Your code is ignoring the axis indicated by getAxisAngle, and therefore it looks incorrect to you.

Edited by Álvaro

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 16
• 9
• 15
• 9
• 11