Game Development Reference

In-Depth Information

So we end up with

M
b
M
t
M
−
1

b

bearing in mind that multiplied matrices are equivalent to transformations carried

out in reverse order.

We will need to use this function whenever we have a matrix expressed in one

basis and we need it in another. We can do this using the multiplication and inverse

functions we have already implemented: there is no need for a specialized function.

In particular the technique will be indispensable in the next chapter when we

come to work with the inertia tensor of a rigid body. At that stage I will provide a

dedicated implementation that takes advantage of some other properties of the inertia

tensor that simplifies the mathematics.

M
t
=

9.4.7

T
HE
Q
UATERNION
C
LASS

We've covered the basic mathematical operations for matrices and have a solid
Matrix

and
Vector
class implemented. Before we can move on, we also need to create a data

structure to manipulate quaternions.

In this section we will build a Quaternion class. The basic data structure looks like

this:

Excerpt from include/cyclone/core.h

/**

* Holds a three degree of freedom orientation.

*/

class Quaternion

{

public:

union {

struct {

/**

* Holds the real component of the quaternion.

*/

real r;

/**

* Holds the first complex component of the quaternion.

*/

real i;

/**

* Holds the second complex component of the quaternion.

*/

real j;