Sign in to follow this  

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

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

If you intended to correct an error in the post then please contact us.

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?

 

Thanks in advance

Lukas

Share this post


Link to post
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 this post


Link to post
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

Share this post


Link to post
Share on other sites
Sign in to follow this