1
Vote

Quaternion.ToEulerAngles returning 0

description

If you pass in a value that is larger than 179.9999 it will return 0 instead of its negative counterpart.

comments

chris7333 wrote Oct 19, 2012 at 8:08 PM

the problem is at the bottom there is a check if the resulting value is less than Epsilon and then setting it to 0. It should be this... I would submit a patch if i had the code properly checked out.

Quaternion.cs needs this around line 600
        if (pitch >= -Real.Epsilon && pitch <= Real.Epsilon)
        {
            pitch = 0f;
        }
        if (yaw >= -Real.Epsilon && yaw <= Real.Epsilon)
        {
            yaw = 0f;
        }
        if( roll >= -Real.Epsilon && roll <= Real.Epsilon )
        {
            roll = 0f;
        }

chris7333 wrote Oct 19, 2012 at 8:17 PM

I ended adding one more check so that the value doesn't flip back and forth between -180 and 180...
        if (pitch >= -Real.Epsilon && pitch <= Real.Epsilon)           
            pitch = 0f;
        else if (pitch == -Utility.PI)
            pitch = Utility.PI;

        if (yaw >= -Real.Epsilon && yaw <= Real.Epsilon)
            yaw = 0f;
        else if (yaw == -Utility.PI)
            yaw = Utility.PI;

        if (roll >= -Real.Epsilon && roll <= Real.Epsilon)
            roll = 0f;
        else if (roll == -Utility.PI)
            roll = Utility.PI;