Lecture05-Clipping

Lecture05-Clipping - CS 455 Computer Graphics Clipping...

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS 455 Computer Graphics Clipping Shadow maps, or, why Z buffers matter From http://en.wikipedia.org/wiki/Shadow_mapping Project 2 Projection Comparison Perspective Parallel (and orthonormal) Line Clipping What happens when one or both endpoints of a line segment are not inside the specified drawing area? Draw just the portions of a line (or object) that fall within a given region/window/screen (usually rectangular) Drawing Area Math Problem of the Day y=100 x=200 (x0,y0) = (10,90) (x1,y1) = (20,115) (xi,yi)=(_,_) 14 10 25 10 10 ) 100 ( 1 1 = + =--- + = y y y x x x xi Line Clipping Strategies for clipping: a) Check (in inner loop) if each point is inside Works, but slow b) Clip invalid coordinate(s) to boundary Incorrect results c) Find intersection of line with boundary Correct if (x >= xmin && x <= xmax && y >= ymin && y <= ymax) drawPoint(x,y,c); if (x < xmin) x = xmin; else if (x > xmax) x = xmax; if (y < ymin) y = ymin; else if (y > ymax) y = ymax; Input Output Clip x Clip y Clip line to intersection Line Clipping: Possible Configurations 1. Both endpoints are inside the region (line AB ) No clipping necessary 1. One endpoint in, one out (line CD ) Clip at intersection point 3. Both endpoints outside the region: a. No intersection (lines EF , GH ) b. Line intersects the region (line IJ )- Clip line at both intersection points A B C D F E I J G H Line Clipping: Cohen-Sutherland Basic algorithm: Accept (and draw) lines that have both endpoints inside the region F E Trivially reject A B Trivially accept H C D I J G Clip and retest Clip the remaining lines at a region boundary and repeat steps 1 and 2 on the clipped line segments Reject (and dont draw) lines that have both endpoints less than x min or y min or greater than x max or y max Cohen-Sutherland: Accept/Reject Tests Assign 4-bit code to each endpoint corresponding to its position relative to region: First bit (1000) : if y > y max Second bit (0100) : if y < y min Third bit (0010) : if x > x max Fourth bit (0001) : if x < x min Test: if code OR code 1 = 0000 accept (draw) else if code AND code 1 0000 reject (dont draw) else clip and retest 0100 0101 0110 1000 1001 1010 0001 0010 0000 Why does this work? Accept/reject/redo all based on bit-wise Boolean ops. Cohen-Sutherland Accept/Reject 0100 0101 0110 1000 1001 1010 0001 0010 0000 Cohen-Sutherland: Line Clipping Intersection algorithm: if code 0000 then code = code else code = code 1 dx = x 1 x ; dy = y 1 y if code AND 1000 then begin // y max x = x + dx * ( y max y ) / dy ; y = y max end else if code AND 0100 then begin // y min x = x + dx * ( y min y ) / dy ; y = y min end else if code AND 0010 then begin // x max y = y + dy * ( x max x ) / dx ; x = x max end else begin // x min y = y + dy * ( x min x ) / dx ; x = x min end if code = code then begin x = x ; y = y ; end else begin x = x ; y = y ; end ( x 1 , y 1 ) ( x , y ) y...
View Full Document

This note was uploaded on 03/02/2012 for the course C S 455 taught by Professor Jones,m during the Winter '08 term at BYU.

Page1 / 39

Lecture05-Clipping - CS 455 Computer Graphics Clipping...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online