Game Development Reference
In-Depth Information
Figure 3.4 Vector subtraction (a), and representing points as vectors from the
origin (b).
Subtraction is extremely important, because it enables you to construct a vector
between two points. But if we always draw our vectors such that the tail is at the
origin and the head aims at only one point, how can we make a vector between two
points ?
Well, suppose we have point A at the position (5, 2) and point B at (3, 5). What if
weinstead represented thesepointsasvectorswiththeirtails attheoriginandtheir
heads at the respective points? As we covered earlier, the values of x and y will be
identical either way. But if we think of them as vectors, subtraction will allow us
to construct a vector between the two, as demonstrated in Figure 3.4(b) . The same
principle applies as before: from A to B is B - A .
This aspect of vector subtraction is frequently used in games. For instance, ima-
gine you are designing a UI arrow system for a game. The player is periodically
given objectives he must travel to, and the game needs to display an arrow that
points the player in the proper direction. In this case, the direction in which the
arrow needs to face is the vector from the player to the objective, which we would
calculate with:
Search WWH ::




Custom Search