Game Development Reference
In-Depth Information
elements are multiplied against another element, this is known as the dot pro-
duct and is covered here.
public Vector Multiply(double v)
{
return new Vector(X * v, Y * v, Z * v);
}
public static Vector operator * (Vector v, double s)
{
return v.Multiply(s);
}
Figure 8.8 shows what occurs when a vector is multiplied by a scalar. Multiplying
by a vector scales the vector, so multiplying by 2 will double the length of the
vector. Multiplying by -1 will make the vector point in the opposite direction it
currently points. If a player character was shot in a 3D game, the vector the bullet
was traveling can be multiplied by -1, reversing it. This vector will now point
outwards from the body along the line of the bullet's entry, a perfect vector to use
to play a blood splat effect (see Figure 8.9).
Normal Vectors
A normal vector is a vector that has a length of exactly 1. These vectors are also
known as unit vectors. Unit vectors are an excellent way to represent a direction
without caring about the magnitude. The normalize operation maintains the
vector's direction but makes its magnitude equal 1. If a unit vector is multiplied
Figure 8.8
Vector, scalar multiplication.
 
Search WWH ::




Custom Search