Game Development Reference

In-Depth Information

v.x -= q.v.x;

v.y -= q.v.y;

v.z -= q.v.z;

return *this;

}

Scalar Multiplication: The *= Operator

This operator simply multiplies each component in the quaternion by the scalar
s
. This

operation is similar to scaling a vector, as described in
Appendix A
:

inline Quaternion Quaternion::operator*=(float s)

{

n *= s;

v.x *= s;

v.y *= s;

v.z *= s;

return *this;

}

Scalar Division: The /= Operator

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

inline Quaternion Quaternion::operator/=(float s)

{

n /= s;

v.x /= s;

v.y /= s;

v.z /= s;

return *this;

}

Conjugate: The ~ Operator

This operator takes the conjugate of the quaternion, ~
q
, which is simply the negative of

the vector part. If
q
= [
n
,
x
i
+
y
j
+
z
k
], then ~
q
= [
n
, (−
x
)
i
+ (−
y
)
j
+ (−
z
)
k
].

The conjugate of the product of quaternions is equal to the product of the quaternion

conjugates, but in reverse order:

~(
qp
) = (~
p
)(~
q
)

Here's the code that computes the conjugate for our
Quaternion
class:

Quaternion operator~(void) const { return Quaternion( n,

-v.x,

-v.y,

-v.z);}