I have seen chapters and sections about quaternion rotation in countless programming books, but I have never needed to use them. With all the examples available I always assumed that they were easy. Oops. I've been reading about them and thinking about them, but the purpose still eludes me.
I have an OpenGL sphere representing a planet, and I thought that by using quaternion rotation I could avoid Gimbal lock. However, even with all the equations, I do not understand the code that I need to write. If I understand the math, a quaternion is represented as a vector and a scalar. q = [qv, qw] where qv is the vector (qx, qy, qz) and qw is the scalar. I understand that the regular vector is multiplied by sin(angle/2) and the scalar by cos(angle/2) to convert the regular vector into a quaternion vector and scalar.
I understand that quaternion multiplication uses the Grassman product with a dot product and a cross product. I also understand that the conjugate q* = [-qv, qw], and if the quaternion is normalized with a length of one, then the inverse and the conjugate are identical.
q^-1 = q*. The inverse is used to perform rotation of a vector. v' = qvq^-1. Multiply the quaternion by the vector, and then by the inverse. If I have made any mistakes so far please let me know.
Here is what I do not understand:
* To rotate a vector, does that vector need to be normalized? It also seems that I do not convert the vector to be rotated into a quaternion. It is just (vx, vy, vz, 0). But then after multiplication with the quaternion and inverse, I convert the result from the quaternion back to a vector?
* I have examples of turning a quaternion into a matrix, but when is this necessary? Do I convert the rotation into a matrix and multiply that by my current matrix? What happens to vectors multiplied by this matrix? Do they come on quaternions? It is very confusing.
* If I want to rotate my planet based on the user clicking and dragging the mouse, I don't understand what the code should do. What vector becomes the quaternion? What vector is rotated by the quaternion? How do I take the result and rotate the planet?
Hopefully I haven't been too confusing.