Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I am using quaternions to rotate my camera. I only rotating the camera around it's x and y axises. But for some reason, after some rotation, y axis also gets rotated(looks like around z axis).

I could avoid the problem with fixing y to (0,1,0), but I am curious where I am wrong.

share|improve this question

2 Answers 2

up vote 3 down vote accepted

How are you handling rotations? If you're composing rotations then you might be running into the fundamental 'trick' with rotations: their non-commutativity. In particular, if you have some rotation $R$ that's built (e.g.) as 'rotate around the $x$ axis $10^{\circ}$, then rotate around the $y$ axis $10^{\circ}$', then composing $R$ with itself (i.e., 'rotate around the $x$ axis $10^{\circ}$, then rotate around the $y$ axis $10^{\circ}$, then rotate around $x$ $10^{\circ}$ again, then rotate around $y$ $10^{\circ}$ again) is not the same as 'rotate around the $x$ axis $20^{\circ}$, then rotate around the $y$ axis $20^{\circ}$'! (This happens because 'rotate around $x$ by $10^{\circ}$, then rotate around $y$ by $10^{\circ}$' isn't the same as 'rotate around $y$ by $10^{\circ}$, then rotate around $x$ by $10^{\circ}$'.) If you want to keep your camera upright and you're not allowing arbitrary camera rotations, then it's a good idea to explicitly consider your camera in terms of the classic Yaw/Pitch/Roll Euler angles and manipulate those rather than by composing rotations.

Incidentally, for questions like this (practical questions about the implementation of rotation of objects, rather than abstract questions about the space of rotations) I'd recommend the gamedev StackExchange site; this is exactly the sort of thing they handle on a regular basis.

share|improve this answer

An answer you would probably receive in a game dev forum:

It sounds like your using a Y up system and pitching around the world X axis. Typically, for a game camera where you only want yaw & pitch, usually the yaw is desired about the world's vertical axis but pitch is desired about the camera's local horizontal axis(local X axis). When the camera orientation is in the identity orientation, the camera's local horizontal axis happens to be aligned with the world horizontal axis (usually the X axis) but when yaw is applied the local horizontal axis rotates away from the world X axis. If you then apply pitch around the world X axis, it can cause a rotation with a Z axis component to it. But if you apply the pitch rotation first (before the yaw) while the local and world X axes are aligned, there will be no Z component to the rotation.

This pitch rotation causes the local Up axis to rotate away from the world Up axis too but you really don't care because you always yaw around the world up axis anyway.

So try applying pitch first, then yaw and see if it helps.

or... calculate the local horizontal axis after yawing and use that axis to pitch around instead of the world X axis.

share|improve this answer

Your Answer


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.