First off, the w component of the quaternion doesn’t represent an angle, so you need to do some conversion before passing it to glRotatef (which accepts an axis-angle pair). The proper angle is 2 * acos(w), and the axis should be the (x, y, z) normalized (remember since the whole quaternion (x, y, z, w) is normalized, the (x, y, z) part will not necessarily be normalized).

Second, the way you compose the quaternions is incorrect. You should just be multiplying qvert * qhorz, the conjugate should not appear. (Although I think that qhorz * qvert may be what you actually want.) It looks like you’ve gotten confused about that: the composition of two rotations is just the product of their quaternions. You only need the conjugate when you want to apply a rotation to a *vector*. Then you convert the vector to a quat with a w-component of 0, and apply the v’ = q * v * q\~ formula. But you won’t need this formula, since you convert the quat to axis-angle and let OpenGL do the work of applying it to vectors.

I’m trying to write a very simple quaternion camera that looks from its location when you move the mouse. Nothing fancy. Apparently, I’m not understanding something about quaternion rotation correctly, because I just get jiggle, and, without renormalization, the quaternion becomes unnormalized faster than I would expect (after < 30 frames, |q|=\~0). I would really like a picture explaining a simple quaternion camera system because the math/programming is surely trivial if I understand the problem I’m trying to solve.

Anyway, this is what I think I want to be doing:

And here is my function.

…And how I tell OpenGL to rotate:

Thanks in advance for your help.

-Tobey