Game Development Reference
In-Depth Information
1.4.3
T HE M ATH W E ' LL I NTRODUCE
Finally there is a good deal of mathematics that you may not have discovered unless
you have done some physics programming in the past. This is the content I'll try not
to assume you know and will cover in some more depth.
At the most well-known end of the spectrum this includes the quaternions, a vec-
torlike structure that represents the orientation of an object in three-dimensional
space. We will take some time to understand why such a strange structure is needed
and how it can be manipulated: converted into a matrix, combined with other quater-
nions, and affected by rotations.
We will also need to cover vector calculus: the way vectors change with time and
through space. Most of the topic requires only simple calculusâ€”numerical integra-
tion and first-order differentiation. The more complex physics approaches of chapter
18 get considerably more exotic, including both partial differentials and differential
operators. Fortunately we will have completely built the physics engine by this point,
so the content is purely optional.
Finally we will cover some more advanced topics in matrix manipulation. In par-
ticular, a difficult chunk of the engine development involves working with changes-
of-basis for matrices. This kind of manipulation is rarely needed in graphics develop-
ment, so it will be covered in some depth in the relevant section.
1.5
T HE S OURCE C ODE IN T HIS B OOK
Throughout the topic the source code from the Cyclone physics engine is given in
the text. The complete engine is available on the accompanying CD, but repeating the
code in the text has allowed me to comment more fully on how it works.
The latest Cyclone source, including errata and new features, is available on its
own siteâ€” www.procyclone.com . Check the site from time to time for the latest release
of the package.
In each section of the topic we will cover the mathematics or concepts needed and
then see them in practice in code. I encourage you to try to follow the equations or
algorithms in the code, and to find how they have been implemented.
I have used C++ throughout the code. This is by far the most common program-
ming language used for serious game development worldwide. Even those few studios
that use other languages for building the final game (including LISP, Lua, and Python)
have most of their core engines written in C++.
Some developers still swear by C and believe that using anything else for game de-
velopment is tantamount to heresy. C compilers have traditionally been more efficient
at producing fast-executing code, and the same overhead that makes C++ a more
powerful language (in the sense that it does more for you automatically) has the rep-
utation of slowing down the final program. In reality this is a dying mindset rooted
in dubious fact. With modern optimizing C++ compilers, and a programming style
that takes into consideration problems with the C++ libraries (avoiding some imple-
mentations of the hashtable, for example), the final result can be at least as fast and