Game Development Reference
In-Depth Information
To find the direction of the rotation, we use the vector cross product in the lines 68
through 70. The benefit we get from using cross product is the direction of the resulting
vector, which is going to be important to us. This vector is perpendicular to the two vectors
involved in the cross product operation. Since the camera direction and the car front are both
horizontal, the resulting vector is vertical, and it points either up or down. The direction is
determined by the smallest angle between the two vectors involved in the cross product.
To illustrate, let's take the example in Illustration 27, which shows the case in which the car
turns right.
Illustration 27: Angle difference between the car front (a) and the camera direction (b)
In Illustration 27, the camera looks forward while the car front is a bit rotated to the right. To
get the rotation direction, we need to apply left and rule on the cross product between these
two vectors. Th s rule is different from the right-hand rule of cross product you might have
learned in mathematics or physics class. So, according to this rule, the fastest way to let the fi
st vector in the operation (car front) point to the direction of the second vector (camera front)
is to rotate it counter-clockwise. It is clear in Illustration 27 that we need to rotate vector a
counter clockwise to match the direction of vector b . Th s counter-clockwise rotation results
Search WWH ::




Custom Search