this week
play

This Week Windows, Viewports and Clippings Creating Useful Drawing - PDF document


  1. ������������������������ ������������������������������ �������������������� � �������������������������������� Computer Graphics Computer Graphics Computer Graphics Computer Graphics CSC CSC 48 0 476 Chapter Three Chapter Three This Week • Windows, Viewports and Clippings • Creating Useful Drawing Tools • Turtle Graphics Computer Graphics C S 4 8 0

  2. ������������������������ ������������������������������ �������������������� � �������������������������������� Windows and Viewports • Previously we looked at an OpenGL window where x and y were plotted as positive pixel values. • However, we may not be interested in keeping track of pixels like this. • We may prefer to plot points in the coordinates in which they are given. • This means handling both positive and negative values. Computer Graphics C S 4 8 0 Windows and Viewports • We need to distinguish between the world, world coordinates, world windows, the screen window and the viewport. • It’s like this…. Computer Graphics C S 4 8 0

  3. ������������������������ ������������������������������ �������������������� � �������������������������������� Windows and Viewports The World (what you can see, the real world) The World Window (the bit we want to capture) Screen Screen Window Viewport Computer Graphics C S 4 8 0 Windows and Viewports • The world window is a rectangle. • The viewport is a rectangle. • Both are not necessarily the same size or have the same aspect ratio. • Coordinates need to be stretched, shrunk and moved to make them fit. Computer Graphics C S 4 8 0

  4. ������������������������ �������������������������������� ������������������������������ �������������������� � Windows and Viewports World Window Example Viewports Computer Graphics CS 480 ` Windows and Viewports World Window Viewport This is called Mapping ( 0 , 0 ) ( 100 , 0 ) ( 0 , 0 ) ( 100 , 0 ) Computer Graphics CS 480 ´

  5. ������������������������ �������������������������������� ������������������������������ �������������������� � Windows and Viewports • Recall from the last lecture: x’ = Ax + B � y’ = Cy + D � • This is exactly how mapping is achieved!! Computer Graphics CS 480 ^ Windows and Viewports • Mapping involves scaling and translation (moving). • Both the world window and viewport can be any aligned rectangle . • Usually the viewport is set to take up the entire screen window. Computer Graphics C S 4 8 0

  6. ������������������������ �������������������������������� ������������������������������ �������������������� � 4 / 6 / 2009 Computer Graphics C S 4 8 0 4 / 6 / 2009 Computer Graphics C S 4 8 0

  7. ������������������������ �������������������������������� �������������������� � ������������������������������ Mapping from the Window to the Viewport • The Figure shows a world window and a viewport in more detail. The world window is described by its left, top, right, and bottom borders as W.l, W.t, W.r, and W.b • The viewport is described likewise in the coordinate system of the screen ' opened at some place on the screen) by V.l, V.t, V.r, and V.b 4 / 6 / 2009 Computer Graphics C S 4 8 0 Windows and Viewports W.t = Window top V.t = Viewport top W.l = Window left V.l = Viewport left W.b = Window bottom V.b = Viewport bottom W.r = Window right V.r = Viewport right Computer Graphics C S 4 8 0 `

  8. ������������������������ �������������������� � ������������������������������ �������������������������������� Windows and Viewports xmin, ymin, xmax, ymax = W.l, W.b, W.r, W.t SCREENWIDTH = V.r – V.l SCREENHEIGHT = V.t – V.b Computer Graphics C S 4 8 0 • We derive a mapping or transformation, called the window - to - viewport mapping. This mapping is based on a formula that produces a point (sx, sy) in the screen window coordinates for any given point (x, y) in the world. sx = Ax + C, sy = By + D C A 4 / 6 / 2009 Computer Graphics C S 4 8 0 ´

  9. ������������������������ �������������������� � ������������������������������ �������������������������������� Windows and Viewports • The same holds for y: − − sy V . b y W . b = − − V . t V . b W . t W . b • or by rearranging D B − −   V . t V . b V . t W . b = + − sy y  V . b W . b  − − W . t W . b  W . t W . b  Computer Graphics CS 480 ` Using the formulas in Equation 3 . 3 , we obtain A = 180 , C = 40 , B = 240 , and D = 60 . Thus, for this example, the window - to - viewport mapping is sx = 180 x + 40 ; sy = 240 y + 60 . 4 / 6 / 2009 Computer Graphics CS 480 ´ ^

  10. ������������������������ ������������������������������ �������������������� � �������������������������������� PRACTICE EXERCISE • Find values of A,B, C, and D for the case of a world window of ( - 10 . 0 , 10 . 0 , - 6 . 0 , 6 . 0 ) and a viewport of ( 0 , 600 , 0 , 400 ). What about the - ve values ?? 4 / 6 / 2009 Computer Graphics CS 480 ^ Windows and Viewports Example World Window World Window Viewport Viewport 400 ( 10 , 6 ) 0 ( -10 , -6 ) 0 600 What are A, B, C & D ?? Computer Graphics C S 4 8 0

  11. ������������������������ �������������������� � ������������������������������ �������������������������������� Windows and Viewports • Do you need to perform these calculations each time you draw something with OpenGL?? Computer Graphics C S 4 8 0 Windows and Viewports • No • OpenGL does all the hard work for you. • But it is important that you understand what is going on….. Computer Graphics C S 4 8 0

  12. ������������������������ �������������������������������� �������������������� � ������������������������������ Windows and Viewports • Each time you call for a vertex to be drawn (e.g. glVertex 2 f() etc..) the the coordinates of the point are passed coordinates of the point are passed through a set of transformations through a set of transformations that map world coordinates into viewport coordinates. Computer Graphics C S 4 8 0 Windows and Viewports • First set the world window coordinates with: void glOrtho 2 D(GLDouble left, GLDouble right, GLDouble bottom, GLDouble top); • Then set the viewport with: void glViewport(GLint xmin, GLint ymin, GLint width, GLint height); Computer Graphics C S 4 8 0

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend