Game Development Reference
In-Depth Information
dist = d.Magnitude();
vCollisionPoint = vList1[i];
body1->vCollisionPoint = vCollisionPoint −
body1->vPosition;
body2->vCollisionPoint = vCollisionPoint −
body2->vPosition;
vCollisionNormal = ((u^p)^u);
vCollisionNormal.Normalize();
v1 = body1->vVelocityBody +
(body1->vAngularVelocity ^
body1->vCollisionPoint);
v2 = body2->vVelocityBody +
(body2->vAngularVelocity ^
body2->vCollisionPoint);
v1 = VRotate2D(body1->fOrientation, v1);
v2 = VRotate2D(body2->fOrientation, v2);
vRelativeVelocity = (v1 - v2);
Vrn = vRelativeVelocity * vCollisionNormal;
if( (proj.Magnitude() > 0.0f) &&
(proj.Magnitude() <= edge.Magnitude()) &&
(dist <= ctol) &&
(Vrn < 0.0) )
haveNodeEdge = true;
}
}
}
Here, the nested for loops check each vertex in one list to see if it is in contact with each
edge built from the vertices in the other list. After building the edge under consideration,
we save and normalize a copy of it to represent a unit vector pointing along the edge:
if(j==3)
edge = vList2[0] - vList2[j];
else
edge = vList2[j+1] - vList2[j];
u = edge;
u.Normalize();
Variable u represents that unit vector, and it will be used in subsequent calculations. The
next set of calculations determines the location of the projection of the vertex under
consideration onto the edge under consideration, as well as the minimum distance from
the vertex to edge:
Search Nedrilad ::




Custom Search