Conjugate and inverse
Games mostly use normalized quaternions, which comes in handy when inverting quaternions. The inverse of a normalized quaternion is its conjugate. The conjugate
of a quaternion flips its axis of rotation:
- Implement the
conjugatefunction inquat.cppand remember to declare the function inquat.h:quat conjugate(const quat& q) {     return quat(         -q.x,         -q.y,         -q.z,         q.w     ); } - The proper inverse of a quaternion is the conjugate divided by the squared length of the quaternion. Implement the quaternion
inversefunction inquat.cpp. Add the function declaration toquat.h:quat inverse(const quat& q) { Â Â float lenSq = q.x*q.x + q.y*q.y + q.z*q.z + q.w*q.w; Â Â if (lenSq < QUAT_EPSILON) { Â ...