Graphics Reference
In-Depth Information
Entering
Logical intersection
Exiting
Figure 5.27 The intersection of a ray (or segment) against a convex polyhedron (defined as
the intersection of a set of halfspaces) is the logical intersection of the ray clipped against all
halfspaces. (Illustration after [Haines91b].)
if (denom == 0.0f) {
// If so, return “no intersection” if segment lies outside plane
if (dist > 0.0f) return 0;
} else {
// Compute parameterized t value for intersection with current plane
float t = dist / denom;
if (denom < 0.0f) {
// When entering halfspace, update tfirst if t is larger
if (t > tfirst) tfirst = t;
} else {
// When exiting halfspace, update tlast if t is smaller
if (t
<
tlast) tlast = t;
}
// Exit with “no intersection” if intersection becomes empty
if (tfirst > tlast) return 0;
}
}
// A nonzero logical intersection, so the segment intersects the polyhedron
return 1;
}
Search WWH ::




Custom Search