Game Development Reference
In-Depth Information
Therefore, the triangle that includes
4 has sides
Length2 * sin(
2 ) and Length2 * cos(
2 ) + Length1
The angle
4 is found using the inverse tangent of the ratio of these
lengths:
2 )
Length1 + Length2 * cos (
Length2 * sin (
4 = atan
2 )
You could even reduce the number of trig function calls by using the tan
identity for tan(
1 -
2 ):
tan(
1 -
2 ) = (tan(
1 ) - tan(
2 ))/(1 + tan(
1 )tan(
2 ))
If the target is beyond the reach of the current chain, the exercise reduces
to the single link one. The child object will have zero rotation or rotation
that orientates it to the direction of the parent in a more general solution.
The parent object can be rotated as in the single link solution.
The code for the double link solution is shown below. The code makes
use of a CLink class that stores the current orientation for a link and the
rotation matrix. The CLink class is a linked list with a parent member
variable.
Figure 9.5 Rotating the objects with the target beyond reach.
Search Nedrilad ::




Custom Search