Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
7  
Your problem is more or less the definition of gimbal lock. –  Seth Battin May 13 '13 at 23:37
7  
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
3  
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. –  bobenko May 14 '13 at 12:32

1 Answer 1

up vote 0 down vote accepted

Gimbal lock is the answer, avoid using euler angles even converting to and from quaternion, use multiplication by quaternion created from angle axis.

Unity3d has same problem when rotating around ox axis:

transform.eulerAngles += new Vector3(5,0,0); //problem
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.