Game Development Reference
In-Depth Information
But the dot product can't tell us whether it's θ in the clockwise or counterclock-
wisedirection.Todeterminethis,wemustusethecrossproduct.Becausethecross
product only works on 3D vectors, and must be converted to 3D vectors by
adding a z-component of 0:
Oncethevectorsare3D,wecancalculate .Ifthez-componentoftheresultant
vector is positive, it means that the rotation is counterclockwise. On the other
hand, a negative z-component means the rotation is clockwise. The way to visual-
ize this is by using the right-hand rule. If you go back to Figure 3.10 and position
your index finger along ĉ and your middle finger along ĉ , your thumb should point
out of the page. In a right-handed coordinate system, this is a positive z value,
which is a counterclockwise rotation.
Linear Interpolation
Linear interpolation, or lerp , calculates a value somewhere linearly between two
other values. For example, if a = 0 and b = 10, a linear interpolation of 20% from a
to b is 2. Lerp is not limited to only real numbers; it can be applied to values in any
number of dimensions. It is possible with points, vectors, matrices, quaternions,
and many other types of values. Regardless of the number of dimensions, lerp can
be applied with the same generic formula:
Lerp ( a,b,f ) = (1- f )·a + f·b
Here, a and b are the values being interpolated between and f is a fractional value
in the range of [0,1] from a to b .
Ingames,acommonapplicationoflerpistofindapointbetweentwootherpoints.
Suppose there is a character at point a and it needs to be smoothly moved to b over
time. Lerp will allow you to slowly increase f until it hits 1, at which point the
character will be at point b (see Figure 3.11 ) .
Search WWH ::




Custom Search