Disable one angle of rotation

330 Views Asked by At

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.

1

There are 1 best solutions below

5
On BEST ANSWER

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.