Graphics Reference
In-Depth Information
// If all 3 bits set (m == 7) then p is in a vertex region
if (m == 7) {
// Must now intersect segment [c, c+d] against the capsules of the three
// edges meeting at the vertex and return the best time, if one or more hit
float tmin = FLT_MAX;
if (IntersectSegmentCapsule(seg, Corner(b, v), Corner(b, v 1), s.r, &t))
tmin = Min(t, tmin);
if (IntersectSegmentCapsule(seg, Corner(b, v), Corner(b, v 2), s.r, &t))
tmin = Min(t, tmin);
if (IntersectSegmentCapsule(seg, Corner(b, v), Corner(b, v 4), s.r, &t))
tmin = Min(t, tmin);
if (tmin == FLT_MAX) return 0;
// No intersection
t = tmin;
return 1;
// Intersection at time t == tmin
}
// If only one bit set in m, then p is in a face region
if ((m & (m - 1)) == 0) {
// Do nothing. Time t from intersection with
// expanded box is correct intersection time
return 1;
}
// p is in an edge region. Intersect against the capsule at the edge
return IntersectSegmentCapsule(seg, Corner(b, u 7), Corner(b, v), s.r, &t);
}
// Support function that returns the AABB vertex with index n
Point Corner(AABB b, int n)
{
Point p;
p.x = ((n & 1) ? b.max.x : b.min.x);
p.y = ((n & 1) ? b.max.y : b.min.y);
p.z = ((n & 1) ? b.max.z : b.min.z);
return p;
}
This test also works for performing the same intersection against an OBB: by
expressing the sphere center C and the movement vector d in the local coordinate
system of the OBB the problem is effectively reduced to that of a moving sphere
against an AABB.
5.5.8 Intersecting Moving AABB Against AABB
Because an AABB is an instance of a convex polyhedron, the problem of determining
intersection between two moving AABBs, A and B with corresponding velocities v A
 
Search WWH ::




Custom Search