Game Development Reference
In-Depth Information
examples on a piece of paper until you do. Once you've got it, try to think how
you might do a circle-circle intersection or a sphere-sphere intersection.
The Dot Product Operation
The dot product is an operation that takes two vectors and returns a number.
The number returned is related to the angle between the two vectors.
A B ¼j A jj B j cos ð y Þ
The dot product operation used on vector A and B returns the length of A and B
multiplied by the cosine of the angle between the vectors. This is shown graphi-
cally in Figure 8.13. If vectors B and A are normalized, then their length values
are 1 and the equation is simplified to A
). To retrieve the angle, the
arccosine operation can be used. In C#, the arccosine function is Math.acos
and it returns the angle in radians.
B
¼
cos(
y
The dot product operation is very good for determining if objects in the game are
facing each other. It's also very useful for testing if an object is on one side of a
plane or the other; this is used in 3D games to ensure the character doesn't walk
through walls.
The operation itself is very simple: all the elements from the first vector are
multiplied by the second vector, then all these values are added together to
Figure 8.13
The dot product operation.
 
Search WWH ::




Custom Search