Game Development Reference
In-Depth Information
y
z
VR
V
V = length of 1
x
Figure 3-10.
Multiplying a unit vector of length 1 with a scalar value
In terms of code, the
Multiply()
function in the Vector3 class multiplies a scalar value by the vector.
Each component x, y, and z of the vector is multiplied by the scalar value (see Listing 3-5).
Listing 3-5.
Multiply
Function
void Multiply(float v)
{
x *= v;
y *= v;
z *= v;
}
Vector Negation
Vector negation means that you multiply the vector by -1, which means you multiply every
component of the vector by -1. Basically, the direction of the vector is reversed. Look at Figure
3-11
,
to see what this looks like graphically.
y
z
-v = (-3,0,
0
)
v = (3,0,0)
x
Figure 3-11.
Vector negation