Game Development Reference
the relationships between them remain the same as for linear velocity and accelera-
tion. In particular we can update the angular velocity using the equation
+ θ t
where θ is the angular acceleration and θ is the angular velocity, as before.
I MPLEMENTING THE M ATHEMATICS
We've covered the theory. Now it's time to implement functions and data structures
that are capable of performing the right mathematics. In chapter 2 we created a Vec-
tor3 class that encapsulated vector mathematics; we'll now do the same thing for
matrices and quaternions. As part of this process I'll introduce the mathematics of
many operations for each type.
If you are working with an existing rendering library, you may already have ma-
trix, vector, and quaternion classes implemented. There is nothing physics-specific in
the implementations I give here. You should be able to use your own implementations
without alteration. I've personally worked with the DirectX utility library implemen-
tations on many projects without having to make any changes to the rest of the physics
T HE M ATRIX C LASSES
A matrix is a rectangular array of scalar values. They don't have the same obvious
geometric interpretation as vectors do. We will use them in several different contexts,
but in each case they will be used to change (or “transform”) vectors.
Although matrices can be any size, with any number of rows and columns, we are
primarily interested in two kinds: 3
4 matrices. To implement
matrices we could create a general matrix data structure capable of supporting any
number of rows and columns. We could implement matrix mathematics in the most
general way, and use the same code for both of our matrix types (and other types
of matrix we might need later). While this would be an acceptable strategy, having
the extra flexibility is difficult to optimize. It would be better to create specific data
structures for the types of matrix we need. This will be our approach.
Wewillcreateadatastructurecalled Matrix3 for 3
3 matrices and one called
Matrix4 for 3
The basic data structure for Matrix3 looks like this:
Excerpt from include/cyclone/core.h
* Holds an inertia tensor, consisting of a 3x3 row-major matrix.
* This matrix is not padding to produce an aligned structure, since
* it is most commonly used with a mass (single real) and two
* damping coefficients to make the 12-element characteristics array