/
CS 543: Computer GraphicsLecture 2 (Part II): Tiling, Zooming and 2D C CS 543: Computer GraphicsLecture 2 (Part II): Tiling, Zooming and 2D C

CS 543: Computer GraphicsLecture 2 (Part II): Tiling, Zooming and 2D C - PDF document

celsa-spraggs
celsa-spraggs . @celsa-spraggs
Follow
392 views
Uploaded On 2016-08-27

CS 543: Computer GraphicsLecture 2 (Part II): Tiling, Zooming and 2D C - PPT Presentation

Applications of WV MappingnV ApplicationsnZooming in on a portion of objectnTiling WV in loop adjacent viewportsFlipping drawingsnMapping different window and viewportaspect ratios WH Tiling ID: 457001

Applications W-V MappingnV Applications:nZooming:

Share:

Link:

Embed:

Download Presentation from below link

Download Pdf The PPT/PDF document "CS 543: Computer GraphicsLecture 2 (Part..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

CS 543: Computer GraphicsLecture 2 (Part II): Tiling, Zooming and 2D ClippingEmmanuel Agu Applications of W-V MappingnV Applications:nZooming: in on a portion of objectnTiling: W-V in loop, adjacent viewportsFlipping drawingsnMapping different window and viewportaspect ratios (W/H) Tiling: Example 3.2.4 of Hill (pg. 100)nProblem: want to tile dinodat in 5x5 across screenn// set world windowgluOrtho2D(0, 640.0, 0, 440.0);for(inti=0;i ){int j = 0;j ){ // .. now set viewportin a loop(i * 64, j * 44; 64, 44);drawPolylineFile);} ZoomingProblem: ndat is currently drawn on entire screen. nUser wants to zoom into just the head nSpecifies selection by clicking top-left and bottom-right corners Zooming Step 1 :Calculate mapping A, that maps dinodat (world window) to viewportmy first attempt Step 2:Calculate reverse mapping A’ of current viewportback to the entire world window (dinoWorld windowViewport VB Example mapping A Zooming Step 3 :Program accepts two mouse clicks as rectangle cornersmy first attempt Step 4:Use mapping A’ to refer selected screen rectangle to worldWorld windowViewport VB Example mapping A Step 5:Call gluOrtho2D on smaller rectangle ZoomingZooming (pseudocodeCalculate mapping A of from world (entire dino) to current viewportDerive reverse mapping A’ from viewport to world3.Program accepts two mouse clicks as rectangle cornersUse mapping A’ to refer screen rectangle to world5.Sets world to smaller world rectangle (gluOrtho2D on selected rectangle in world coordinates)6.Remaps small rectangle in world to screen viewport What if Window and Viewport have different Aspect Ratios?nAspect ratio: is ratio R = Width/Height nWhat if window and viewport have different aspect ratios?nIf different, two possible cases: n�Case A (R W/H): map a wide window to a tall viewport Aspect ratio R (left, right, bottom, top );R = (right –left)/(top –�If(R W/H)glViewport(0, 0, W, W/R);H What if Window and Viewport have different Aspect Ratios?nCase B (R )map a tall window to a wide viewport Aspect ratio R (left, right, bottom, top );R = (right –left)/(top –If(R )glViewport(0, 0, H*R, H);H reshape( ) function that maintains aspect ratio(left, right, bottom, top )is done previously,// probably in your draw function// function assumes variables left, right, top and bottom// are declared and updated globallyvoid (double W, double H ){R = (right –left)/(top –�if(R W/H)glViewport(0, 0, W, W/R);else if(R )glViewport(0, 0, H*R, H);else(0, 0, W, H); // equal aspect ratios} CohenSutherland ClippingnFrequently want to view only a portion of the picturenFor instance, in dino, you can select to view/zoom in on only the dinosaur’s headnClipping: eliminate portions not selectednOpenGL automatically clips for younWe want algorithm for clippingnClassical algorithm: Cohen-Sutherland ClippingnPicture has 1000s of segments : efficiency is important Clipping Points (, ymin(, ymax Determine whether a point (x,y) is inside or outside of the world window? If (xmin xmax) andymin ymaxthen the point (x,y) is insideelse the point is outside Clipping Linesn3 cases:nCase 1:All of line innCase 2:All of line outnCase 3:Part in, part out (, ymin(, ymax23 Clipping Lines: Trivial AcceptnCase 1: All of line innTest line endpoints:nNote: simply comparing x,y values of endpoints to x,y values of rectanglenResult: trivially accept. nDraw line in completely (, Ymin(, Ymax p2 Xmax andYmin Ymax Clipping Lines: Trivial RejectnCase 2: All of line outnTest line endpoints:nNote: simply comparing x,y values of endpoints to x,y values of rectanglenResult: trivially reject. nDon’t draw line in p1p2 p1.x, p2.x Xmin&#x= 00;p1.x, p2.x = Xmaxp1.y, p2.y ymin&#x= 00;p1.y, p2.y = ymax Clipping Lines: NonTrivial CasesnCase 3: Part in, part outnTwo variations:nOne point in, other outnBoth points out, but part of line cuts through viewportNeed to find inside segmentsnUse similar triangles to figure out length of inside segments e p1 Clipping Lines: Calculation examplenIf chopping window has (left, right, bottom, top) =(30, 220, 50, 240), what happens when the following lines are chopped?n(a) p1 = (40,140), p2 = (100, 200)n(b) p1 = (20,10), p2 = (20, 200)n(c) p1 = (100,180), p2 = (200, 250) e p1 CohenSutherland pseudocode (fig. 3.21)int clipSegment(Point2& p1, Point2& p2, RealRect W)if(trivial accept) return 1; // whole line survivesif(trivial reject) return 0; // no portion survives// now chopif(p1 is outside)// find surviving segment{if(p1 is to the left) chop against left edgeelse if(p1 is to the right) chop against right edgeelse if(p1 is below) chop against the bottom edgeelse if(p1 is above) chop against the top edge} CohenSutherland pseudocode (fig. 3.23)else // p2 is outside// find surviving segment{if(p2 is to the left) chop against left edgeelse if(p2 is to right) chop against right edgeelse if(p2 is below) chop against the bottom edgeelse if(p2 is above) chop against the top edge} CohenSutherland ImplementationnNeed quick efficient comparisons to get quick accepts, rejects, chopCan use C/C++ bit operationsnBreaks space into 4-bit wordsnTrivial accept: both FFFFnTrivial reject: T in same positionnChop everything elsenSystematically chops against four edgesImportant: read Hill 3.3 FFFF Remember to readnSection 3.2.2 on pg. 92 of HillnHill 3.3 ReferencesHill, 3.1 –3.3, 3.8