From tests of quaternions in OpenGL I noticed that rotations on multiple axis are not working how they should. So I wrote a simple program to debug that. This is my program:
glm::quat rotation = glm::angleAxis(glm::radians(45.0f), glm::vec3(1.0f, 1.0f, 0.0f));
glm::vec3 eulerRotation = glm::degrees(glm::eulerAngles(rotation));
printf("X = %f\tY = %f\tZ = %f\n", eulerRotation.x, eulerRotation.y, eulerRotation.z);
From my understanding of rotations this should output:
X = 45.0 Y = 45.0 Z = 0.0
But the program outputs this:
X = 51.589348 Y = 45.000004 Z = 18.939444
I'm using GLM version 0.9.9.5 and C++ 14 So, is my understanding of rotations wrong or is GLM screwing something up?
The Axis-Angle Representation and the Euler Angles are two different ways of encoding a rotation. For rotations on canonical axes (X, Y, Z), the representations are very similar and can lead to the false deduction that the conversion is trivial. For example, the Axis-Angle (45,(1,0,0))
is simply the Euler Angles (45,0,0)
. However, for more general axes, the conversion is not always so obvious.
Adding to the confusion is that the name Euler Vector is used when we create a single 3D vector out of the Axis-Angle representation using the length of the vector to encode the angle of rotation. For example, (45,(1,0,0))
can be encoded as 45*(1,0,0)
. However, an Euler Vector is not the same as a vector that contains Euler Angles for the same reason that the Axis-Angle representation is different from Euler Angles.
Finally, as stated in another answer by Amadeus, the glm framework requires that the input axis vector is normalized. Normalizing this vector will give the expected result.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With