Presentation is loading. Please wait.

Presentation is loading. Please wait.

Window to Viewport Transformations

Similar presentations


Presentation on theme: "Window to Viewport Transformations"— Presentation transcript:

1 Window to Viewport Transformations
CS 455 – Computer Graphics Window to Viewport Transformations

2 Compositing Transformations
Does order matter? Case 1: translate by (–2, 0), scale by (2, 2) Case 2: scale by (2, 2), translate by (-2, 0) Begin: red, 1st transform: purple, 2nd: green Y Y 2,3 2,3 3,1 1,1 3,1 1,1 X X Case 1(translate then scale) Case 2 (scale then translate)

3 Compositing Transformations
Does order matter? Case 1: translate by (–2, 0), scale by (2, 2) Case 2: scale by (2, 2), translate by (-2, 0) Begin: red, 1st transform: purple, 2nd: green Y Y 0,2 4,2 2,6 0,6 -2,2 2,2 2,2 6,2 4,6 2,3 -1,1 0,3 2,3 3,1 3,1 1,1 1,1 X X Case 1(translate then scale) Case 2 (scale then translate)

4 Composition Example In general, transformations are not commutative
Scale(2.0,2.0); Translate(-2.0,0.0); drawTriangle(); Translate(-2.0, 0.0); Scale(2.0,2.0); drawTriangle(); In general, transformations are not commutative

5 Window-to-Viewport Transform
Need to transform points from “world” view (window) to the screen view (viewport) Maintain relative placement of points (usually) Can be done with a translate-scale-translate sequence Window (“world”) Viewport (screen) v y -3 -2 -1 1 2 3 -4 4 60 50 40 x 30 20 10 10 20 30 40 50 60 70 80 u

6 Window “Window” refers to the area in “world space” or “world coordinates” that you wish to project onto the screen Location, units, size, etc. are all determined by the application, and are convenient for that application Units could be inches, feet, meters, kilometers, light years, etc. The window is often centered around the origin, but need not be Specified as (x,y) coordinates Window (“world”) y (xmax, ymax) -3 -2 -1 1 2 3 -4 4 x (xmin, ymin)

7 Viewport The area on the screen that you will map the window to
Specified in “screen coordinates” - (u,v) coordinates The viewport can take up the entire screen, or just a portion of it Viewport (screen) v (umax, vmax) 60 50 40 30 20 10 (umin, vmin) 10 20 30 40 50 60 70 80 u

8 Viewport (cont) You can have multiple viewports
They can contain the same view of a window, different views of the same window, or different views of different windows Viewport (screen) v 60 50 40 30 20 10 10 20 30 40 50 60 70 80 u

9 Window-to-Viewport Transform (cont.)
The window-to-viewport transform is: 1. Translate lower-left corner of window to origin 2. Scale width and height of window to match viewport’s 3. Translate corner at origin to lower-left corner in viewport Window (“world”) Viewport (screen) v y -3 -2 -1 1 2 3 -4 4 10 20 30 40 50 60 Move lower left to origin. Scale to screen size Move lower left from viewport origin to screen lower left x u 10 20 30 40 50 60 70 80

10 Window-to-Viewport Transform (cont.)
The final window-to-viewport transform is:

11 Window-to-Viewport Transform (cont.)
Multiplying the matrix Mwv by the point p gives:

12 Window-to-Viewport Example
Window: (xmin, ymin) = (-3, -3), (xmax, ymax) = (2 , 1) Viewport: (umin, vmin) = (30, 10), (umax, vmax) = (80, 30) Window (“world”) Viewport (screen) v y -3 -2 -1 1 2 3 -4 4 10 20 30 40 50 60 x u 10 20 30 40 50 60 70 80

13 Window-to-Viewport Example
Plugging the values into the equation: Window (“world”) Viewport (screen) v y -3 -2 -1 1 2 3 -4 4 10 20 30 40 50 60 x u 10 20 30 40 50 60 70 80

14 Window-to-Viewport Example
Plugging the values into the equation:

15 Window-to-Viewport Example
So: Trying some points: (xmin, ymin) = (-3, -3) -> (xmax, ymax) = (2, 1) -> Left eye = (-1, -.8) -> Top of head = (-0.5, 0.5) -> Window (“world”) Viewport (screen) v y -3 -2 -1 1 2 3 -4 4 10 20 30 40 50 60 x u 10 20 30 40 50 60 70 80

16 Window-to-Viewport Example
So: Trying some points: (xmin, ymin) = (-3, -3) -> (30, 10) (xmax, ymax) = (2, 1) -> (80, 30) Left eye = (-1, -.8) -> (50, 21) Top of head = (-0.5, 0.5) -> (55, 27.5) Window (“world”) Viewport (screen) v y -3 -2 -1 1 2 3 -4 4 10 20 30 40 50 60 x u 10 20 30 40 50 60 70 80

17 Window-to-Viewport Transform (cont.)
What if the viewport origin is top-left? 1. Use the same equation, but subtract the results from (vmax + vmin) Window (“world”) Viewport (screen) y u 10 20 30 40 50 60 70 80 This is just a change in v by the way, u is unchanged. -3 -2 -1 1 2 3 -4 4 60 50 40 30 20 10 x v

18 Window-to-Viewport Transform (cont.)
Rationale: 1. If vmin = 0, we reverse the results of our equation by subtracting it from vmax, i.e., vmax -> 0 and 0 -> vmax 2. If we take (vmax - vmin) we get the correct scale factor 3. We need to move the point in question back to the v-axis, then scale 4. We need to add vmin to get from the v-axis back to the original point location, so the scaling is correct Thus, we have (vmax - vmin) - (p - vmin) + vmin = vmax + vmin - p

19 Window-to-Viewport Example - downward pointing v-axis
Window: (xmin, ymin) = (-3, -3), (xmax, ymax) = (2 , 1) Viewport: (umin, vmin) = (30, 10), (umax, vmax) = (80, 30) Window (“world”) Viewport (screen) y -3 -2 -1 1 2 3 -4 4 10 20 30 40 50 60 70 80 60 50 40 30 20 10 u x v

20 Window-to-Viewport Example - downward pointing v-axis
The equation for this situation is:

21 Window-to-Viewport Example - downward pointing v-axis
So: Trying some points: (xmin, ymin) = (-3, -3) -> (xmax, ymax) = (2, 1) -> Left eye = (-1, -.8) -> Top of head = (-0.5, 0.5) -> Window (“world”) Viewport (screen) y 10 20 30 40 50 60 70 80 60 50 40 30 20 10 u -3 -2 -1 1 2 3 -4 4 x v

22 Window-to-Viewport Example - downward pointing v-axis
So: Trying some points: (xmin, ymin) = (-3, -3) -> (30, 30) (xmax, ymax) = (2, 1) -> (80, 10) Left eye = (-1, -.8) -> (50, 19) Top of head = (-0.5, 0.5) -> (55, 12.5) Window (“world”) Viewport (screen) y 10 20 30 40 50 60 70 80 60 50 40 30 20 10 u -3 -2 -1 1 2 3 -4 4 x v


Download ppt "Window to Viewport Transformations"

Similar presentations


Ads by Google