Game Development Reference
In-Depth Information
Figure 14.1
The dot product projects one vector onto another.
That is a complicated way of saying that if you divide the dot product of two vectors
by their lengths multiplied together, you get the cosine of their angle. Take the arc-
cosine of that number, and you have the angle! This is extremely useful in computer
games, since you are always trying to figure out the angle between vectors.
Another way to visualize the dot product graphically is that the dot product projects
one vector onto the other and calculates the length of that vector. This dot product
relationship is shown in Figure 14.1, where the dot product equals the length of the
projection of vector A onto B. As it turns out, this length is exactly the same as the
projection of vector B onto vector A. Weird, huh?
The dot product can be useful by itself, since it can determine whether the angle
between two vectors is acute, a right angle, or obtuse. The classic application of the
dot product in 3D graphics is determining whether a polygon is facing toward or
away from the camera (see Figure 14.2).
In Figure 14.2, the camera has a unit vector called the look at vector, and it points in
the same direction as the camera. Each polygon has a normal vector that is orthogo-
nal to the plane of the polygon. If the dot product between these two vectors is less
than zero, the polygon is facing the camera and should be added to the draw list. In
the case of Figure 14.2, the dot product for these two vectors is close to -1.0, so the
polygon will be drawn.
Search WWH ::




Custom Search