Game Development Reference
In-Depth Information
In terms of code, the Negate() function in the Vector3 class performs negation (see Listing 3-6).
Listing 3-6. The Negate Function
void Negate()
{
x = -x;
y = -y;
z = -z;
}
The Right Triangle
The right triangle comes in handy when trying to break up vectors into components. For example,
if you know the speed of a tank shell and the angle the shell's path makes with the ground, then
you can get the horizontal and vertical speeds of the tank shell. The horizontal speed would be
calculated using the formula for the adjacent side of the right triangle. The vertical speed would be
calculated using the formula for the opposite side of the triangle. Let's review the basic trigonometric
identities related to the right triangle, as depicted in Figure 3-12 .
Hypotenuse
Opposite
Adjacent
Figure 3-12. The right triangle
The following is a list of standard trigonometric identities that describe how the lengths of the sides
of a right triangle relate to one another and the angle theta shown in Figure 3-12 :
Sin(Theta) = Opposite/Hypotenuse
Cos(Theta) = Adjacent/Hypotenuse
Opposite = Hypotenuse * Sin(Theta)
Adjacent = Hypotenuse * Cos(Theta)
Vector Dot Product
The vector dot product of two vectors is the magnitude of vector A multiplied by the magnitude of
vector B multiplied by the cosine of the angle between them. The dot product is commonly used to
find the angle between two vectors. One application of the dot product is in billboarding, where a
2D rectangle with a complex image on it, such as a tree, is turned to face the camera. This is a way
 
Search WWH ::




Custom Search