# Problem with my camera rotation

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.

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.