Title: 4ICT10 Computer Graphics and Virtual Reality
14ICT10 Computer Graphics and Virtual Reality
- 9. World Windows, Viewports Clipping
- Dr Ann McNamara
2Definitions
- World Coordinate System (Object Space)
- This space in which the application model is
defined. The representation of an object is
measured in some physical or abstract units - Screen Coordinate Space (Image Space)
- The space in which the image is displayed.
Ususally measured in pixels but could use any
units.
3Definitions
- Window, the rectangle defining the part of the
world we wish to display - Interface Window the visual represntation of the
screen coordinate system for windowed displays
(coordinate system moves with the interface
window)
4Definitions
- Viewport the rectangle on the raster graphics
screen (or interface window for window
displays) defining where the image will appear,
usually the entire screen or interface window - Viewing Transformations the process of mapping
from a window in world cordintates to a viewport
in screen coordinates
5Windows and Viewports
6Window-Viewport Transformation
7Viewing Transformation Example
8Window-Viewport Transformation
9Window-Viewport Transformation
- Proportionality in mapping x to sx
10(No Transcript)
11Window to Viewport Mapping
- sx Ax C sy By D
- A C V.l AW.l
- B D V.b BW.b
V.r-V.l
W.r-W.l
V.t-V.b
W.t-W.b
12Properties of Mapping
- If x is at the windows left edge x W.l the
xs is at the viewports left edge sx V.l - If x is at the windows right edge then sx is at
the viewports right edge - If x is a fraction of f of the way across the
window then sx is a fraction of f the way across
the viewport - If x is outside the window to the left (xltW.l)
theh xs is outside the viewport to the left
(sxltV.l) and analogously if x is outside to the
right - One should also check these properties for y to sy
13Example
- Window (W.l, W.r, W.b, W.t)(0, 2.0,0,1.0)
- Viewport(V.l, V.r, V.b, V.t)(40,400,60,300)
14Example
- A 180, C 40, B 240, D 60
- sx 180x 40
- sy 240x 60
- Check!
- Each corner is indeed mapped
- The center of the window maps to the center of
the viewport
15Example 2
- Find the values of A,B,C,D for the case of a
world window (-10.0, 10.0, -6.0, 6.0) and a
viewport of (0, 600, 0, 400)
16Window-Viewport Transformation in OpenGL
- gluOrtho2d does it for us!
- If my window is 5 meters by 4 meters and has a
lower left corner at (2, 0) in world coordinates - gluOrtho2D (2, 7, 0, 4)
- Will automatically transform the vertices
- If you do the transform manually, you normally
dont include the last step (translating to
screen coordinates) because you probably set up
your interface window so that the origin was at
the lower-left corner - Generally, also need glViewport(l, b, r, t) but
the default viewport uses the whole interface
window
17Sequences of OpenGL Transformations
18 2D in OpenGL
19Notes on Window-Viewport Transformation
- Panning
- Moving the window about the world
- Zooming
- Reducing/increasing the window size
- As the window increases in size the image in the
viewport decreases in size and vice versa - See Thursdays Tutorial for Examples!
20Setting the Window Automatically
21Setting the Viewport Automatically
- Largest undistorted version that will fit in
screen? - R Aspect Ratio of World
- Two situations
22Setting the Viewport Automatically
- RgtW/H
- World window is short and stout compared to
screen window viewport with a matching aspect
ratio R will extend fully across but will be some
space unused above/below - At largest therefore the viewport will have width
W and height W/R - setViewport(0, W, 0, W/R)
- RltW/H
- World window is Tall and Narrow compared to
screen window viewport with a matching aspect
ratio R will extend fully from top to bottom but
will be some space unused at left/right - At largest therefore the viewport will have width
HR and height H - setViewport(0, HR, 0, H)
23Example, Tall Window
- If the world window has R1.6 and the screen has
H 200 and W 360, W/H 1.8. Therefore we have
case B and the viewport is set to 200 pixels high
and 320 wide - (Height H 200, Width HR 2001.6 320!)
24Example, Short Window
- If the world window has R2.0 and the screen has
H 200 and W 360, W/H 1.8. Therefore we have
case B and the viewport is set to 180 pixels high
and 360 wide - (Width 360, Height W/R 360/2 180!)
25Clipping Lines
26Cohen-Sutherland Algorithm
- Region Checks
- Trivially accept/reject lines and points
- Fast for large windows and small windows
- Everything is either inside or outside!
- Each vertex is assigned a 4-bit outcode
27Cohen-Sutherland Algorithm
28Cohen-Sutherland Clipping
29Cohen-Sutherland Clipping
- Trivially Accepted
- Both endpoints have outcode FFFF
- Trivially Rejected
- Any correspoding bits in the two outcodes are T.
(this means both endpoints are to the right, to
the left, above or below the window)
30Clipping Lines not Accepted or Rejected
- In case where a line is neither trivially
accepted or rejected - divide and conquer approach
31Cohen-Sutherland Algorithm
- A must be computed
- x W.right
- y needs adjusting p1.y by the amount d
- By similar triangles
- e is p1.x-W.right
- delx p2.x p1.x
- dely p2.y p1.y
- p1.y-(p1.x-W.right)dely/delx
d/dely e/delx
32(No Transcript)
33Polygon Clipping
- Polygons can be clipped against each edge of the
window one edge at a time. Window/Edge
intersections (if any) are easy to find since the
x and y coordinates are known. - Vertices which are kept after clipping against
one window edge are saved for clipping against
remaining edges. Note that the number of
vertices ususally changes and will often increase.
34Polygon Clipping Algorithm
- The window boundary determines a visible or
invisible region - The edge from vertex i to vertex i1 can be one
of 4 types - Exit visible region save the intersection
- Wholly outside visible region save nothing
- Enter visible region save intersection and end
point - Wholly inside visible region save endpoint
35Polygon Clipping Issues
- The final output, if any, is always considered a
single polygon - The spurious edge may not be a problem since it
always occurs on a window boundary, but can be
eliminated if necessary
36Pipelined Polygon Clipping
- Because polygon clipping does not depend on any
other polygons it is possible to arrange the
clipping stages in a pipeline. The input polygon
is clipped against one edge and any points that
are kept are passed on as input to the next stage
of the pipeline. - This way four polygons can be at different stages
of the clipping process simultaneously. This is
often implemented in hardware
37Clipping in the OpenGL Pipeline