Game Development Reference
In-Depth Information
Before leaping into the use of vectors in games for defining motion, a crash
course in essential vector mathematics for game environments is presented in
the next section.
2.2 Principles of Vectors
In Chapter One, a vector was introduced as a line with a length (magnitude)
and a direction (indicated by an arrow). Vectors can be used to represent
measurements such as displacement, velocity, and acceleration. In 2D, a
vector has x and y coordinates. In 3D, it has x , y , and z coordinates. In pure
mathematics, a vector is not a point in space, but a set of changing coordinate
instructions. It can be likened to the instructions on a fictional pirate's treasure
map, for example, take three steps to the west and seven steps to the south.
As shown in Figure 2.1 , the instructions three steps to the west could be
interpreted as the vector (3,0), meaning move 3 in the positive x direction and
nothing in the y direction. The instructions move seven steps to the south
become the vector (0, 7), meaning move only 7 in a negative y direction.
To determine the final location, vector x and y values are added to the starting
point x and y values. For example, in Figure 2.1 , the pirate ship lands at (4,8)
and moving (3,0) will place them at (4 + 3, 8 + 0) = (7,8). Then moving (0, 7)
will put them at (7 + 0,8 7) = (7,1). They can also take a shortcut by going
directly in a straight line to the treasure. In this case, the two instruction
vectors (3,0) and (0, 7) are added together and become (3, 7). By taking the
starting location and adding this new vector, they will end up in the same
location [i.e., (4 + 3,8 7) = (7,1)].
Fig 2.1 A pirate's treasure map
illustrating the use of vectors.
shiver me timbers!
Ta ke 3 steps to
the west, then
7 steps to the south,
and there thee
shall find the
start = (4, 8)
treasure = (7,1)
Search Nedrilad ::

Custom Search