# Matrix represents same rotation with different euler angles

I have Transform component storing it's rotation as Quaternion. Transform has set/getEulerAngles (rotation order oy, ox, oz). I want to rotate object in any direction but while testing I get jumping(glitch) objects stop rotating at specific angles.

Euler angles in problem frames:

1) oy 0 ox -90 oz 0 - previous frame.

2) oy 180 ox -90 oz 180 - next frame after incrementing angle of the object.

my increment looks like:

tr->setEulerAngles(tr->eulerAngles()+Vector3(5,0,0));//rotate around ox by 5 degrees


visually this rotations are equal, but when I get angles 2) from quaternion and increment them it starts rotating in oposite direction, next frame rotation is again as 1), so there is infinite loop at this rotation (some kind of black hole;-)). What can it be? Something wrong with math?

• Your problem is more or less the definition of gimbal lock. – Seth Battin May 13 '13 at 23:37
• From a practical perspective, the best way to fix this is to avoid Euler angles altogether; precompute a quaternion that corresponds to a 5-degree rotation about ox and just multiply your current orientation by that 5-degree rotation each frame. – Steven Stadnicki May 14 '13 at 0:46
• As intuitive as Euler angles seem at first, they are equally that evil when you go beyond 2d. In 3d, avoid them whenever possible. – Steve H May 14 '13 at 4:37
• Unity3d has same problem when rotation around ox axis. Thanks for help, I solved problem multiplying current rotation by quaternion created from axis angle. Comment about gimbal lock and euler angles equally evil)) I'll mark as an answer if you write it there. I thought that using quaternion do not make gimbal lock at all, but conversion to from euler angles does. – Yevhen May 14 '13 at 12:32

transform.eulerAngles += new Vector3(5,0,0); //problem