110 likes | 130 Views
Resizing the Window. Lecture 6 Mon, Sep 8, 2003. Resizing the Window. When we resize the window, we can Distort the scene proportionally, or Keep the scene of a constant size. Expand the scene without distortion. Distortion occurs “automatically.”
E N D
Resizing the Window Lecture 6 Mon, Sep 8, 2003
Resizing the Window • When we resize the window, we can • Distort the scene proportionally, or • Keep the scene of a constant size. • Expand the scene without distortion. • Distortion occurs “automatically.” • By adjusting the world window, we can compensate and keep the scene a constant size or let it grow without distortion.
Resizing the Window (xmin, ymax) H h W w (xmax, ymin)
Maintaining Constant Size • When resizing, the upper-left corner is stationary. • Therefore, to keep the scene a constant size, keep xmin and ymax the same and change xmax and ymin. xmax = xmin + (w/W)*(xmax – xmin) ymin = ymax – (h/H)*(ymax – ymin)
Example: Drawing a Teapot • DrawTeapot2.cpp
Preserving the Aspect Ratio • The aspect ratio of a drawing is its width divided by its height. • If we keep the aspect ratio of a scene constant, then there will be no distortion or expansion in the scene. • This may be tricky since the aspect ratio of the enclosing window may change.
Preserving the Aspect Ratio • By what factor should the scene expand? H = 2 h = 3 W = 3 Aspect ratio R = 3/2 w = 4 Aspect ratio r = 4/3
Preserving the Aspect Ratio • If the aspect ratio increases (r > R), then the new scene will fill the height but not the width of the new window. • If the aspect ratio decreases (r < R), then the new scene will fill the width but not the height of the new window.
Preserving the Aspect Ratio • Suppose r > R. (You can work out the details when R < r.) • Then w/h > W/H. • w is larger than it should be. • Clearly, to preserve the aspect ratio, we need the new width of the scene to be h(W/H).
Preserving the Aspect Ratio • We make this change in the viewport. if (w > h*aspectRatio) screenWidth = h*aspectRatio; else screenWidth = w; if (h > w/aspectRatio) screenHeight = w/aspectRatio; else screenHeight = h; glViewport(0, 0, screenWidth, screenHeight);
Example: Draw the Teapot • DrawTeapot3.cpp • DrawTeapot4.cpp