1 / 11

Resizing the Window

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.”

tdixon
Download Presentation

Resizing the Window

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Resizing the Window Lecture 6 Mon, Sep 8, 2003

  2. 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.

  3. Resizing the Window (xmin, ymax) H h W w (xmax, ymin)

  4. 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)

  5. Example: Drawing a Teapot • DrawTeapot2.cpp

  6. 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.

  7. 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

  8. 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.

  9. 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).

  10. 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);

  11. Example: Draw the Teapot • DrawTeapot3.cpp • DrawTeapot4.cpp

More Related