Quaternions Euler Angles


#1

Hi, I seem to have a problem with the usage of Quaternions creation with euler angles. From a GUI I can change the model rotation in all three axis using 3 different GUIFloatField inputs (very much like Banshee Inspectors). The on value changed callback looks like so

std::array< Radian, 3 > angles;
so_->getLocalTransform().getRotation().toEulerAngles( angles[0], angles[1], angles[2] );
angles[idx] = Degree{ value };
Quaternion q{ angles[0], angles[1], angles[2] };
so_->setRotation( q );

My problem is that the angles degenerate on the X axis near +90/-90 degrees, or when moving 2 axis consecutively. I might have forgotten an important point… Do you have a working example with the fromEulerAngles method ? Maybe some unit test ?

Thanks a lot for your help.


#2

I’m not sure you should be transforming back and forth between quaternions and euler angles every time a change happens. Each quaternion can be represented with two sets of euler angles, and the quaternion conversion always returns the shortest path, which might not be the same value the user input into the field.

That said, that might not be your issue as I’ve had a bug report with similar behaviour that has yet been unresolved. The issue might be in the Quaternion::toEulerAngles class itself. I’ll try to take a closer look soon, but if you want to try resolving it yourself you can test if the code on this page works for you: http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/index.htm .


#3

Also if you can send me a fully working demo showing the issue I can take a better look at it.


#4

Thanks for the reply @BearishSun. I’ll look into it this week. BTW you suggested not to transform back and forth between quaternions and euler angles. I understand your explanation, but isn’t it implemented like that in the BansheeEditor (in the InspectorWindow) ?


#5

It quite possibly is, and it’s probably partly the cause of that bug report I mentioned.