Game Development Reference
In-Depth Information
Figure 8.5
Adding a halo to a player.
If you add a vector [0, 0.2, 0] that should get you a position that's perfect for a
hovering halo. This operation is shown in Figure 8.5.
Vector subtraction is used all the time to get the vector between two points in
space. The calculation is very similar to addition, but the members are subtracted
rather than added.
public Vector Subtract(Vector r)
{
return new Vector(X - r.X, Y - r.Y, Z - r.Z);
}
public static Vector operator-(Vector v1, Vector v2)
{
return v1.Subtract(v2);
}
The result of subtracting two vectors is shown in Figure 8.6. In a space battle, one
spaceship might want to shoot another spaceship. Spaceship A can subtract its
position, represented as a vector, from spaceship B's position; this will give a
vector from A to B (see Figure 8.7). This vector's direction can be used to aim
missiles or advance one craft towards the other.
Vector multiplication is when a vector is multiplied by a scalar number; a scalar
number is a number like an int or double, just a normal number. If all a vector's
 
Search WWH ::




Custom Search