Game Development Reference
In-Depth Information
// penetration is least deep.
real min_depth = box.halfSize.x - real_abs(relPt.x);
if (min_depth < 0) return 0;
normal = box.getAxis(0) * ((relPt.x < 0)?-1:1);
real depth = box.halfSize.y - real_abs(relPt.y);
if (depth < 0) return 0;
else if (depth < min_depth)
{
min_depth = depth;
normal = box.getAxis(1) * ((relPt.y < 0)?-1:1);
}
depth = box.halfSize.z - real_abs(relPt.z);
if (depth < 0) return 0;
else if (depth < min_depth)
{
min_depth = depth;
normal = box.getAxis(2) * ((relPt.z < 0)?-1:1);
}
// Compile the contact.
Contact* contact = data->contacts;
contact->contactNormal = normal;
contact->contactPoint = point;
contact->penetration = min_depth;
// Write the appropriate data.
contact->body[0] = box.body;
// Note that we don't know what rigid body the point
// belongs to, so we just use NULL. Where this is called
// this value can be left, or filled in.
contact->body[1] = NULL;
contact->restitution = data->restitution;
contact->friction = data->friction;
return 1;
}
Notice that we generate the contact data for the point-face collision exactly as we did
in the sphere-box test.
Search Nedrilad ::




Custom Search