Last Time Finished viewing Now you know how to Define a region of space that you wish to view the view volume Transform it into a generic view volume canonical view volume Using orthographic or perspective projection Very brief intro to clipping 02 28 02 c 2002 University of Wisconsin CS559 Today Clipping in all its detail 02 28 02 c 2002 University of Wisconsin CS559 Sutherland Hodgman Clip Clip the polygon against each edge of the clip region in turn Clip polygon each time to line containing edge Only works for convex clip regions Why 02 28 02 c 2002 University of Wisconsin CS559 Sutherland Hodgman Clip To clip a polygon to a line plane Consider the polygon as a list of vertices One side of the line plane is considered inside the clip region the other side is outside We are going to rewrite the polygon one vertex at a time the rewritten polygon will be the polygon clipped to the line plane Check start vertex if inside emit it otherwise ignore it Continue processing vertices as follows 02 28 02 c 2002 University of Wisconsin CS559 Sutherland Hodgman 3 Look at the next vertex in the list and the edge from the last vertex to the next If the polygon edge crosses the clip line plane going from out to in emit crossing point next vertex polygon edge crosses clip line plane going from in to out emit crossing polygon edge goes from out to out emit nothing polygon edge goes from in to in emit next vertex 02 28 02 c 2002 University of Wisconsin CS559 Sutherland Hodgman 4 Inside Outside Inside Outside Inside Outside s p p s Output p 02 28 02 i p Output i Inside p Outside i s s No output c 2002 University of Wisconsin CS559 Output i and p Inside Outside Testing n s x 0 Lines planes store a vector pointing toward the outside of the clip region the outward pointing normal n i x 0 n f x 0 Could re define for inward pointing Outside Dot products give inside outside information Note that x is any point on the clip line plane f n i s 02 28 02 x c 2002 University of Wisconsin CS559 Inside Finding Intersection Pts Use the parametric form for the edge between two points x1 and x2 x t x1 x 2 x1 t 0 t 1 For planes of the form x a y2 y1 z2 z1 xi a y1 a x1 z1 a x1 x2 x1 x2 x1 Similar forms for y a z a Solution for general plane can also be found 02 28 02 c 2002 University of Wisconsin CS559 Inside Outside in Screen Space In canonical screen space clip planes are xs 1 ys 1 zs 1 Inside Outside reduces to comparisons before perspective divide w x w s s s ws y s ws ws z s ws 02 28 02 c 2002 University of Wisconsin CS559 Hardware Sutherland Hodgman Suitable for hardware implementation Only need the clip edge the endpoints of the current edge and the last output point Polygon edges are output as they are found and passed right on to the next clip region edge Vertices in Clipped vertices out 02 28 02 Clip Top Clip Far Clip Right Clip Near c 2002 University of Wisconsin CS559 Clip Bottom Clip Left Other Ways to Reject If a polygonal object is closed then no back facing face is visible Front facing faces must occlude all back facing ones Reject back facing polygons in view space Transform face normal and check OpenGL supports optional back face culling and front face culling too Bounding volumes enclosing many polygons can be checked against the view volume Done in software in world or view space Visibility can reject whole chunks of geometry without even looking at them 02 28 02 c 2002 University of Wisconsin CS559 Clipping In General Apart from clipping to the view volume clipping is a basic operation in many other algorithms Breaking space up into chunks 2D drawing and windowing Modeling May require more complex geometry than rectangular boxes 02 28 02 c 2002 University of Wisconsin CS559 Additional Clipping Planes Useful for doing things like cut away views Use a clip plane to cut off part of the object Only works if piece to be left behind is convex OpenGL allows you to do it Also one way to use OpenGL to identify objects in a region of space uses the selection mechanism 02 28 02 c 2002 University of Wisconsin CS559 Clipping Lines Lines can also be clipped by Sutherland Hodgman Slower than necessary unless you already have hardware Better algorithms exist Cohen Sutherland Liang Barsky Nicholl Lee Nicholl we won t cover this one only good for 2D 02 28 02 c 2002 University of Wisconsin CS559 Cohen Sutherland 1 Works basically the same as Sutherland Hodgman Was developed earlier Clip line against each edge of clip region in turn If both endpoints outside discard line and stop If both endpoints in continue to next edge or finish If one in one out chop line at crossing pt and continue Works in both 2D and 3D for convex clipping regions 02 28 02 c 2002 University of Wisconsin CS559 Cohen Sutherland 2 1 2 3 3 4 4 3 3 4 4 1 02 28 02 2 1 2 1 2 c 2002 University of Wisconsin CS559 Cohen Sutherland 3 Some cases lead to premature acceptance or rejection If both endpoints are inside all edges If both endpoints are outside one edge General rule of clipping if a fast test can cover many cases do it first 02 28 02 c 2002 University of Wisconsin CS559 Cohen Sutherland Details Only need to clip line against edges where one endpoint is out Use outcode to record endpoint in out wrt each edge One bit per edge 1 if out 0 if in 1 2 0010 Trivial reject outcode x1 outcode x2 0 Trivial accept 3 outcode x1 outcode x2 0 Which edges to clip against 4 outcode x1 outcode x2 0101 02 28 02 c 2002 University of Wisconsin CS559 Liang Barsky Clipping Parametric clipping view line in parametric form and reason about the parameter values More efficient as not computing the coordinate values at irrelevant vertices Works for rectilinear clip regions in 2D or 3D Clipping conditions on parameter Line is inside clip region for values of t such that for 2D xmin x1 t x xmax ymin y1 t y ymax 02 28 02 x x2 x1 y y2 y1 c 2002 University of Wisconsin CS559 Liang Barsky 2 Infinite line intersects clip region edges when qk tk pk where p1 x p 2 x p 3 y p 4 y q1 x 1 x min q 2 x max x 1 q 3 y1 y min q 4 y max y1 Note Left edge is 1 right edge is 2 top edge is 3 bottom is 4 02 28 02 c 2002 University of Wisconsin CS559 Liang Barsky 3 When pk 0 as t increases line goes …
View Full Document
Unlocking...