Hey guys,
I've recently got some interest for quaternions, since I couldn't take Gimbal Lock anymore. So what I did is write a small quaternion lib in Axe, but realized I could do at max 15 FPS, where with a classical 3*3 XY rotation matrix I could do more than 56 FPS. So I was asking myself, what's the best way (by that understand : the fastest, the one that uses the less calculations) to use quaternions ?
Right now I use this technique :
- Start with an identity quaternion and its conjugate.
- Game loop :
- Multiply each vertex by the quaternion and its opposite : v' = q * v * q-1
- If an arrow key is pressed, multiply the quaternion by another quaternion representing the correct rotation : if left arrow is pressed, multiply by a quaternion traducing -4° around the (0,1,0) axis, if it's the up arrow multiply it by a quaternion traducing 4° around the (1,0,0) axis etc. I build a quaternion out of an axis and an angle : q = sin(Θ/2) * axis + cos(Θ/2)
- After that, get the conjugate of the resulting quaternion.
- Get back to the beginning.
I'm not quite sure this is the best way to do it since multiplying two quaternions implies 16 multiplications, and rotating a vertex by a quaternion implies 2 quaternions multiplications. Any idea ?