Game Development Reference
In-Depth Information
The standard algorithm for clipping polygons is the Sutherland-Hodgman
algorithm. This algorithm tackles the di cult problem of polygon clipping
by breaking it down into a sequence of easy problems. The input polygon
is clipped against one plane at a time.
To clip a polygon against one plane, we iterate around the polygon,
clipping each edge against the plane in sequence. Each of the two vertices
of the edge may be inside or outside the plane; thus, there are four cases.
Each case may generate zero, one, or two output vertices, as shown in
Figure 10.39.
Figure 10.39
Clipping a single edge—the four
cases
Figure 10.40 shows an example of how we can apply these rules to
clip a polygon against the right clip plane. Remember that the clipper
outputs vertices, not edges. In Figure 10.40, the edges are drawn only
for illustration. In particular, the final clip step appears to output two
edges when actually only one vertex was output—the last edge is implicit
to complete the polygon.
At the end of each stage, if there are fewer than three vertices remaining,
then the polygon is rejected as being invisible. (Notice that it is impossible
to output only one or two vertices. The number of vertices output by any
one pass will either be zero, or at least three.)
Some graphics hardware does not clip polygons to all six planes in 3D
(or 4D). Instead, only the near clip is performed, and then scissoring is
done in 2D to clip to the window. This can be a performance win because
clipping is slow on certain hardware. A variation on this technique is to
employ a guard band. Polygons completely outside the screen are rejected,
polygons completely inside the guard band are scissored rather than clipped
Search WWH ::




Custom Search