Game Development Reference
In-Depth Information
Figure 14.4
A cross product.
I
m going to borrow your right hand for a moment. Hold your right hand out in
front of you, fingers together and totally flat. Make sure you are looking at your
palm. Extend your thumb out, keeping your hand flat. Your thumb is vector A, and
your forefinger is vector B. The result of the cross product, A cross B, is a vector
pointing up out of your palm. If you did it backward, B cross A, the vector would
be pointing away from you. This is the fundamental difference between left- and
right-handed coordinate systems
'
determining which vectors get sent into the cross
product in which order. It matters!
The classic use of the cross product is figuring out the normal vector of a polygon
(see Figure 14.4). The normal vector is fundamental to calculating which polygons
are facing the camera, and therefore, which polygons are drawn and which can be
ignored. It is also good for calculating how much light reflects from the polygon
back to the camera. By the way, if you take the cross product of two parallel vectors,
the result will be a null vector
X, Y, and Z will all equal zero.
For any polygon that has three vertices, V0, V1, and V2, the normal vector is calcu-
lated using a cross product:
Vector A = V1
-
V0;
Vector B = V2
V0;
Vector Cross = CrossProduct(A, B);
In a right-handed coordinate system, the vertices are arranged in a counterclockwise
order because they are seen when looking at the drawn side of the polygon.
Another use is figuring the direction. We have a dot product that tells us that we
need to steer either left or right, but we can
-
'
t figure out which. It turns out that the
Search WWH ::




Custom Search