I'm using lib glm (http://glm.g-truc.net/) for test quaternion but I've a problem; when I convert euler angle to quaternion then immediatly quaternion to euler angles, my result are totally different from my initial euler angles. Is this normal? Could it be because the rotations are not communative?
Code test:
#include <glmquaternion.hpp>
#include <math.h>
#define PI M_PI
#define RADTODEG(x) ( (x) * 180.0 / PI )
#define DEGTORAD(x) ( (x) * PI / 180.0 )
int main( void )
{
float RotX = 90.f;
float RotY = 180.f;
float RotZ = -270.f;
if ( RotX || RotY || RotZ )
{
std::cout << "Init: x= " << RotX << ", y= " << RotY << ", z= " << RotZ << "
";
glm::quat key_quat(glm::detail::tvec3<float>(DEGTORAD( RotX ),
DEGTORAD( RotY ),
DEGTORAD( RotZ )));
glm::detail::tvec3<float> v = glm::eulerAngles(key_quat);
/* // the result is even worse with this code here
RotX = RADTODEG(v.x);
RotY = RADTODEG(v.y);
RotZ = RADTODEG(v.z);
*/
RotX = v.x;
RotY = v.y;
RotZ = v.z;
std::cout << "Final: x= " << RotX << ", y= " << RotY << ", z= " << RotZ << "
";
}
return (0);
}
Result:
Init: x= 90, y= 180, z= -270
Final: x= -90, y= -3.41509e-006, z= -90
thank you in advance o/
See Question&Answers more detail:os