Game Development Reference
In-Depth Information
Figure 8.3
Comparing vectors and positions.
In Figure 8.3, vectors a and e are the same vector because they have the same
direction and magnitude. They are at different origins so they appear different
places on the diagram. Vectors c and d are also the same. Vector b is the same
direction as a and e , but the magnitude is less so it is a different vector.
Vectors, in game programming, are used to answer questions such as:
The enemy spaceship is at position [0, 0, 90]; the player spaceship is at
[0, 80,
50]. What direction should the enemy launch a missile? Each
frame, how is that missile's position updated to send it towards the player?
Is the player's distance from the bomb a meter or less?
Which side of the wall is the player?
Is the player looking at the NPC?
Given a quad that represents the end of a gun, which direction are the bul-
lets going to fire?
How should light reflect off this surface?
Move the car three meters forward.
A player has just hit an enemy; which direction should that enemy move?
How do I increase the force of this bullet by 100?
Which player is nearest the alien artifact?
To be able to answer these questions, the vector class will need to be expanded to
add the basic vector methods. The examples in this chapter will build upon the
code you have written in previous chapters. Most examples will require you to
 
Search WWH ::




Custom Search