Game Development Reference
In-Depth Information
//Convert to unit vectors
mag = sqrt(pt.x * pt.x + pt.y * pt.y);
pt.x/=mag; pt.y/=mag;
mag = sqrt(pe.x * pe.x + pe.y * pe.y);
pe.x/=mag; pe.y/=mag;
//Calculate dot product
dotprod = pe.x * pt.x + pe.y * pt.y;
//Calculate cross product for direction
sign = pe.x * pt.y - pe.y * pt.x;
if (sign > 0.0){
theta = -acos(dotprod);
}else{
theta = acos(dotprod);
}
link->rot.z += theta;
//Set matrices for current link and all children
tmplink = link;
while(link){
link->CreateMatrix();
link = link->next;
}
link = tmplink;
//Move on to next link
if (link==links.next){
loopcount++;
link = lastlink;
}else{
link = link->parent;
}
}
}else{
//Just use the single link solution
link = links.next;
x = target.x - link->pos.x;
y = -target.y - link->pos.x;
link->rot.z = atan(y/x);
if (x<0) link->rot.z = PI + link->rot.z;
Search Nedrilad ::




Custom Search