Game Development Reference
In-Depth Information
int CheckForCollision(pRigidBody2D body1, pRigidBody2D body2)
{
Vector d;
float r;
int retval = 0;
float s;
Vector vList1[4], vList2[4];
float wd, lg;
int i,j;
bool haveNodeNode = false;
bool interpenetrating = false;
bool haveNodeEdge = false;
Vector v1, v2, u;
Vector edge, p, proj;
float dist, dot;
float Vrn;
// First check to see if the bounding circles are colliding
r = body1->fLength/2 + body2->fLength/2;
d = body1->vPosition - body2->vPosition;
s = d.Magnitude() - r;
if(s <= ctol)
{ // We have a possible collision, check further
// build vertex lists for each hovercraft
wd = body1->fWidth;
lg = body1->fLength;
vList1[0].y = wd/2; vList1[0].x = lg/2;
vList1[1].y = -wd/2; vList1[1].x = lg/2;
vList1[2].y = -wd/2; vList1[2].x = -lg/2;
vList1[3].y = wd/2; vList1[3].x = -lg/2;
for(i=0; i<4; i++)
{
VRotate2D(body1->fOrientation, vList1[i]);
vList1[i] = vList1[i] + body1->vPosition;
}
wd = body2->fWidth;
lg = body2->fLength;
vList2[0].y = wd/2; vList2[0].x = lg/2;
vList2[1].y = -wd/2; vList2[1].x = lg/2;
vList2[2].y = -wd/2; vList2[2].x = -lg/2;
vList2[3].y = wd/2; vList2[3].x = -lg/2;
for(i=0; i<4; i++)
{
VRotate2D(body2->fOrientation, vList2[i]);
vList2[i] = vList2[i] + body2->vPosition;
}
// Check for vertex-vertex collision
Search Nedrilad ::




Custom Search