Graphics Reference
In-Depth Information
// Initialize times of first and last contact
tfirst = 0.0f;
tlast = 1.0f;
// For each axis, determine times of first and last contact, if any
for(inti=0;i<3;i++) {
if (v[i] < 0.0f) {
if (b.max[i] < a.min[i]) return 0; // Nonintersecting and moving apart
if (a.max[i] < b.min[i]) tfirst = Max((a.max[i] - b.min[i]) / v[i], tfirst);
if (b.max[i] > a.min[i]) tlast
= Min((a.min[i] - b.max[i]) / v[i], tlast);
}
if (v[i] > 0.0f) {
if (b.min[i] > a.max[i]) return 0; // Nonintersecting and moving apart
if (b.max[i] < a.min[i]) tfirst = Max((a.min[i] - b.max[i]) / v[i], tfirst);
if (a.max[i] > b.min[i]) tlast = Min((a.max[i] - b.min[i]) / v[i], tlast);
}
// No overlap possible if time of first contact occurs after time of last contact
if (tfirst > tlast) return 0;
}
return 1;
}
A solution similar to the one presented here is given in [Gomez99].
5.6 Summary
In this chapter, a large number of different tests and queries have been discussed
in quite some detail. These include closest-point calculations (which directly allow
the distance between the two query objects to be found); heterogeneous intersection
tests (such as between a sphere and an OBB); intersections involving lines, rays, and
line segments (against triangles, for example); and point containment tests (for both
polygons and polytopes), to name a few. In addition to static intersection tests, meth-
ods for performing dynamic tests have also been described, including the powerful
generalization of the separating-axis test.
Even though this chapter has covered a wide variety of tests, readers will inevitably
make note of specific tests that were excluded from coverage. As mentioned at the start
of the chapter, the intent behind the provided spectrum of tests and the mathematical
detail given is to allow the readers themselves to derive these other tests using the
ideas presented herein. Being able to derive tests from scratch is important because
there are not many sources that cover intersection tests to a great extent, and even
 
Search WWH ::




Custom Search