














Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!















Computer Graphics Tiling, Zooming and 2D Clipping
n Zooming: in on a portion of object n Tiling: W-to-V in loop, adjacent viewports n Flipping drawings
n dino.dat is currently drawn on entire screen. n User wants to zoom into just the head n Specifies selection by clicking top-left and bottom-right corners
my first attempt
Step 2: Calculate reverse mapping Aโ of current viewport back to the entire world window (dino.dat)
World window
Viewport
Example mapping A
1. Calculate mapping A of from world (entire dino.dat) **to current viewport
n Case A (R > W/H): map a wide window to a tall viewport?
Viewport
glOrtho(left, right, bottom, top ); R = (right โ left)/(top โ bottom); If(R > W/H) glViewport(0, 0, W, W/R);
Window
// glOrtho(left, right, bottom, top )is done previously, // probably in your draw function // function assumes variables left, right, top and bottom // are declared and updated globally
void myReshape(double W, double H ){ R = (right โ left)/(top โ bottom);
if(R > W/H) glViewport(0, 0, W, W/R); else if(R < W/H) glViewport(0, 0, HR, H); else glViewport(0, 0, W, H); // equal aspect ratios*
n 3 cases: n Case 1: All of line in n Case 2: All of line out n Case 3: Part in, part out
n Case 1: All of line in n Test line endpoints:
n Note: simply comparing x,y values of endpoints to x,y values of rectangle n Result: trivially accept. n Draw line in completely
(Xmin, Ymin)
(Xmax, Ymax)
p
p
Xmin <= P1.x, P2.x <= Xmax and Ymin <= P1.y, P2.y <= Ymax
n Case 3: Part in, part out
n Two variations: n One point in, other out n Both points out, but part of line cuts through viewport
n Need to find inside segments
n Use similar triangles to figure out length of inside segments
e
p
p
d
delx
dely
delx
e dely
n If 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
p
p
d
delx
dely
delx
e dely
else // p2 is outside // find surviving segment { if(p2 is to the left) chop against left edge else if(p2 is to right) chop against right edge else if(p2 is below) chop against the bottom edge else if(p2 is above) chop against the top edge } }while(1); }
n Need quick efficient comparisons to get quick accepts, rejects, chop n Can use C/C++ bit operations n Breaks space into 4-bit words n Trivial accept: both FFFF n Trivial reject: T in same position n Chop everything else
n Systematically chops against four edges
n Important: read Hill 3.