Jump to content

  • Log In with Google      Sign In   
  • Create Account


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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 m3t4lukas   Members   -  Reputation: 210

Like
0Likes
Like

Posted 24 November 2013 - 05:18 AM

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



Sponsor:

#2 m3t4lukas   Members   -  Reputation: 210

Like
0Likes
Like

Posted 27 November 2013 - 10:14 AM

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



#3 Álvaro   Crossbones+   -  Reputation: 13002

Like
1Likes
Like

Posted 27 November 2013 - 10:37 AM

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, 27 November 2013 - 10:37 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS