Game Development Reference

In-Depth Information

q.n*v.z + q.v.y*v.x - q.v.x*v.y);

}

Scalar Division: The / Operator

This operator simply divides each component in the quaternion by the scalar
s
:

inline Quaternion operator/(Quaternion q, float s)

{

return Quaternion(q.n/s, q.v.x/s, q.v.y/s, q.v.z/s);

}

QGetAngle

This function
1
extracts the angle of rotation about the axis represented by the vector

part of the quaternion:

inline float QGetAngle(Quaternion q)

{

return (float) (2*acos(q.n));

}

QGetAxis

This function returns a unit vector along the axis of rotation represented by the vector

part of the quaternion
q
:

inline Vector QGetAxis(Quaternion q)

{

Vector v;

float m;

v = q.GetVector();

m = v.Magnitude();

if (m <= tol)

return Vector();

else

return v/m;

}

QRotate

This function rotates the quaternion
p
by
q
according to the formula:

p
' = (
q
)(
p
)(~
q
)

1. For a description of how quaternions are used to represent rotation, refer to the section
“Quaternions” on

page 232
in
Chapter 11
.