Game Development Reference
In-Depth Information
Figure 9.8 Rotating the intermediate link using the Cylic Coordinate Descent
technique for IK solutions.
We then move one link down the chain and determine new vectors from
the pivot point of the new link to the chain end and target and repeat the
dot product and cross product calculations. We then create a rotation
matrix and calculate the new location for the chain end. This procedure is
repeated until the base object is rotated. At this point we determine if we
are close enough to the target to exit the function. If not, we must repeat
the procedure. It is possible that the target cannot be reached. The
function needs to ensure that under such circumstances the program
does not enter an infinite loop. A simple technique to avoid this is to limit
the looping to a certain number of times; if this is exceeded then the
function exits.
If the total length of the links is less than the distance to the target, then
the goal can never be achieved and it can be useful to add this condition
to the code. Under these circumstances we return to the problem of
orientating a single link, the base link, and setting all other links to zero
rotation.
The code for the Cyclic Coordinate Descent method is as follows:
void CIKDemoDoc::SolveMultiLink()
{
CLink *link = links.next, *lastlink, *tmplink;
int loopcount = 0;
double x, y, totallength, linkslength = 0.0, dotprod;
Search Nedrilad ::




Custom Search