UPDATE: The definitions of R3 and R4 were missing, code has been updated
#####UPDATE: Added a function to get a quaternion from and angle and an axis
Often times I find myself needing to use quaternions to store rotations in my code. They are compact and easy to use, the math however is not always intuitive.
Base data structures
“real” defines a floating point number (either float or double)
“real3” and “real4” define data structures containing a vector or a quaternion
Cross and Dot Products
Normalizing a quaternion
Store the inverse of the length to reduce computational cost
Quaternion inverse
Add two quaternions
Multiplying two quaternions adds them together
Rotate a vector by a quaternion
Angle Axis to Quaternion
Other operations
Some basic multiply/add operations which might be usefull