Game Development Reference
In-Depth Information
d = ((real)1.0)/real_sqrt(d);
r*=d;
i*=d;
j*=d;
k*=d;
}
};
9.4.9
C OMBINING Q UATERNIONS
We combine two quaternions by multiplying them together. This is exactly the same
as for rotation (or any other transformation) matrix: the result of q
ˆ
p
ˆ
is a rotation that
is equivalent to performing rotation ( p
ˆ
).
As we saw in section 9.2.4, the multiplication of two quaternions has the following
form:
) first, then ( q
ˆ
w 1
x 1
y 1
z 1
w 2
x 2
y 2
z 2
w 1 w 2
x 1 x 2
y 1 y 2
z 1 z 2
=
w 1 x 2
+
x 1 w 2
y 1 z 2
z 1 y 2
w 1 y 2
x 1 z 2 +
y 1 w 2
z 1 x 2
w 1 z 2 +
x 1 y 2
y 1 x 2 +
z 1 w 2
which is implemented as
Excerpt from include/cyclone/core.h
/**
* Holds a three degree of freedom orientation.
*/
class Quaternion
{
// ... other Quaternion code as before ...
/**
* Multiplies the quaternion by the given quaternion.
*
* @param multiplier The quaternion by which to multiply.
*/
void operator *=(const Quaternion &multiplier)
{
Quaternion q = *this;
r = q.r*multiplier.r - q.i*multiplier.i -
q.j*multiplier.j - q.k*multiplier.k;
i = q.r*multiplier.i + q.i*multiplier.r +
q.j*multiplier.k - q.k*multiplier.j;
Search Nedrilad ::




Custom Search