# Disable one angle of rotation

I'd like to disable one angle of rotation of an object rotating in 3D space. Imagine a camera rotating around and displaying objects as they are in space. I'd like this object to be fixed on the horizontal axis (always in the center of the camera view) and follow the camera rotation on other two angles ( yaw and pitch).

Before multiplying the position matrix with the view matrix, I tried to anull the roll rotation by extracting Euler angles from the view matrix and then recreating it with roll value of zero. Something along these lines:

1. Take view matrix and extract Euler angles
2. Create the same matrix by replacing roll with zero

It's giving somewhat strange results, and there must be a better way to do this.

-
So in other words, if there was a horizontal line across the camera viewer, it would always appear to be parallel to the horizon, correct? Is it critical you do this with Euler angles or would you be willing to do it with quaternions? – rschwieb Mar 27 '13 at 17:23

A quaternion solution which can compute a rotation quaternion as a composition of first a yaw turn then a pitching turn:

I'm thinking of the usual right-handed $i,j,k$ axes in three space. We suppose that the camera begins looking along the $i$ axis, and that the $i,j$ plane is horizontal.

To accomplish a yaw turn through an angle of $\psi$ radians, we can apply the transformation $x\mapsto qxq^{-1}$ where $q=\cos(\psi/2)+\sin(\psi/2)k$.

At that point, we could rotate around $qjq^{-1}$ to perform a pitch turn. Set $h=qjq^{-1}$. A pitch up by $\theta$ radians is accomplished by the transformation $x\mapsto pxp^{-1}$ where $p=\cos(\theta/2)+\sin(\theta/2)h$.

The composition would just be given by $R=pq$, mapping $x\mapsto RxR^{-1}$. One would have to multiply out what $pq$ is in terms of $\psi$ and $\theta$, but that isn't too hard.

Unfortunately I am not adept at converting this solution to Euler angles or rotation matrices, but fortunately there is a wiki devoted to that subject.

-
Thanks, but my quaternion knowledge is rather limited, unfortunately. – user1304844 Mar 28 '13 at 10:26
@user1304844 Yeah, sorry if it doesn't directly help. It's the least complicated theoretical solution that I'm handy with. What texts do you have to help you solve the problem? – rschwieb Mar 28 '13 at 12:06
Actually you did help. I ended up reading your solution over and over again and studying quaternions for a day. What I did was: 1.Take rotation matrix and convert to quaternion; 2. Set Y component to zero (since the y component get multiplied with the Y axis of the vector. If there is no rotation, y is 0); 3. Normalize the quaternion; 4. OPTIONAL: Convert it back to a matrix4f (since openGL works very well with matrices) and set translation values from the original matrix ( the last column of the original matrix gets copied) – user1304844 Mar 29 '13 at 10:31
@user1304844 Awesome! Good luck with your studies! – rschwieb Mar 29 '13 at 13:14