Game Development Reference
In-Depth Information
Chapter 3. Linear Algebra for Games
Linear algebra is a broad category of mathematics with more than
enough material for a separate topic. But for 3D computer games, only
a very specific subset of linear algebra is typically utilized. Rather than
covering the overall theories and proofs behind linear algebra, this
chapter will present the practical aspects that are most relevant to game
programmers.
It cannot be overstated how important vectors and matrices are in the
game programmer's toolbox; most programmers in the industry use
them every single day.
Vectors
A vector represents both a magnitude and a direction in an n -dimensional space
and has one real number component per dimension. In video games, vectors are
usually either 2D or 3D, depending on the number of dimensions the game sup-
ports. However, as we will discuss in Chapter 4 , 3D Graphics , ” there are in-
stances where 4D vectors may be used, even though the game itself is only 3D.
A vector can be written out on paper in several different ways, but the approach
used in this topic is to draw an arrow above a letter to denote that it's a vector. The
components ofthe vector are then referenced bysubscript foreach dimension. The
3D vector could be represented as follows:
So the vector 1, 2, 3 would have an x-component of 1, a y-component of 2, and
a z-component of 3.
In code, vectors are usually represented as a class with one float per dimension:
class Vector3
float x
float y
float z
end
Search WWH ::




Custom Search