Game Development Reference
Therefore, the triangle that includes
4 has sides
Length2 * sin(
2 ) and Length2 * cos(
2 ) + Length1
4 is found using the inverse tangent of the ratio of these
Length1 + Length2 * cos (
Length2 * sin (
4 = atan
You could even reduce the number of trig function calls by using the tan
identity for tan(
2 ) = (tan(
1 ) - tan(
2 ))/(1 + tan(
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
Figure 9.5 Rotating the objects with the target beyond reach.