Game Development Reference
In-Depth Information
The source code listings show the line numbers. As you can see, the line num-
bers are not continuous. They represent excerpts from the source code on the
CD. In the full source code there are additional comments, more functions,
and bits of code we've yet to meet. Each of the source code listings I give
should be a self-contained chunk of code. In the preceding code, for example,
you shouldn't need any other code to make the listings work; in other excerpts
you can add the given code to any previous code for the same class (when we
come to add some additional functions to the Vector3 class, for example). I've
added the line numbers simply to allow you to locate where each element is
implemented on the CD.
Ihaveused real rather than float to reserve the storage for my vector compo-
nents. The real data type is a typedef , contained in its own file ( precision.h ).
I've done this to allow the engine to be rapidly compiled in different preci-
sions. In most of the work I've done, float precision is fine, but it can be a
huge pain to dig through all the code if you find you need to change to double
precision later. You may have to do this if you end up with numerical rounding
problems that won't go away (they are particularly painful if you have objects
with a wide range of different masses in the simulation). By consistently using
the real data type, we can easily change the precision of the whole engine by
changing the type definition once. We will add to this file additional defini-
tions for functions (such as sqrt ) that come in both float and double form.
I've added an extra piece of data into the vector structure, called pad .Thisisn't
part of the mathematics of vectors and is there purely for performance. On
many machines four floating-point values sit more cleanly in memory than
three (memory is optimized for sets of four words), so noticeable speed-ups
can be achieved by adding this padding.
Your physics engine shouldn't rely on the existence of this extra value for any
of its functionality. If you are programming for a machine that you know is
highly memory limited, and doesn't optimize in sets of four words, then you
can remove pad with impunity.
If you are an experienced game developer, you will have spied a contentious assump-
tion in figure 2.1. The figure shows the three axes arranged in a right-handed coordi-
nate system. There are two different ways we can arrange three axes at right angles to
one another: in a left-handed way or a right-handed way, 1 as shown in figure 2.2.
You can tell which is which by using your hands: make a gun shape with your
hand, thumb and extended forefinger at right angles to one another. Then, keeping
your ring finger and pinky curled up, extend your middle finger so it is at right angles
1. Strictly speaking this handedness is called “chirality,” and each alternative is an “enantiomorph,” al-
though those terms are rarely if ever used in game development.
Search Nedrilad ::

Custom Search