Upload
binjad
View
25
Download
0
Tags:
Embed Size (px)
DESCRIPTION
Window - To - Viewport Transformation
Citation preview
CS450/550 Introduction
Computer GraphicsWindow to Viewport TransformationsCompositing TransformationsDoes 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
YX1,13,12,3YX1,13,12,3Case 1(translate then scale)Case 2 (scale then translate)Compositing TransformationsDoes 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
YX1,13,12,3YX1,13,12,3Case 1(translate then scale)Case 2 (scale then translate)-1,10,3-1,10,6-2,22,22,26,24,60,24,22,6Composition Example
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 commutativeNeed 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 sequenceWindow-to-Viewport Transformxy-3-2-10123-4-3-2-11234uv010203040506070801020304050600Window (world)Viewport (screen)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 beSpecified as (x,y) coordinatesWindowxy-3-2-10123-4-3-2-11234Window (world)(xmin, ymin)(xmax, ymax)The area on the screen that you will map the window toSpecified in screen coordinates - (u,v) coordinatesThe viewport can take up the entire screen, or just a portion of itViewportuv010203040506070801020304050600Viewport (screen)(umin, vmin)(umax, vmax)You can have multiple viewportsThey can contain the same view of a window, different views of the same window, or different views of different windowsViewport (cont)uv010203040506070801020304050600Viewport (screen)The window-to-viewport transform is:1.Translate lower-left corner ofwindow to origin2.Scale width and height ofwindow to match viewports3.Translate corner at origin tolower-left corner in viewportWindow-to-Viewport Transform (cont.)xy-3-2-10123-4-3-2-11234vu010203040506070800102030405060Window (world)Viewport (screen)
Window-to-Viewport Transform (cont.)The final window-to-viewport transform is:
Window-to-Viewport Transform (cont.)Multiplying the matrix Mwv by the point p gives:
Now we need to plug the values into the equation:Window-to-Viewport Example
xy-3-2-10123-4-3-2-11234vu010203040506070800102030405060Window (world)Viewport (screen)
12Window: (xmin, ymin) = (-3, -3), (xmax, ymax) = (2 , 1)Viewport: (umin, vmin) = (30, 10), (umax, vmax) = (80, 30)Window-to-Viewport Examplexy-3-2-10123-4-3-2-11234vu010203040506070800102030405060Window (world)Viewport (screen)
Plugging the values into the equation:Window-to-Viewport Example
So:Trying some points:Window-to-Viewport Example
(xmin, ymin) = (-3, -3) -> (30, 10) (xmax, ymax) = (2, 1) -> Left eye = (-1, -.8) -> Top of head = (-0.5, 0.5) -> xy-3-2-10123-4-3-2-11234vu010203040506070800102030405060Window (world)Viewport (screen)(55, 27.5) (50, 21) (80, 30) What if the viewport origin is top-left?Use the same equation, but subtract the results from(vmax + vmin)Window-to-Viewport Transform (cont.)xy-3-2-10123-4-3-2-11234uv010203040506070806050403020100Window (world)Viewport (screen)
If vmin = 0, we reverse the results of our equation by subtracting it from vmax, i.e., vmax -> 0 and 0 -> vmax
Rationale:
vu010203040506070800102030405060Viewport
uv010203040506070806050403020100Viewport (screen)
This gives us the correct offset from the new u axis
If vmin was not 0, then we need a) the offset inside the viewport b) the offset from the u axis
Rationale (cont)
vu010203040506070800102030405060Viewport
uv010203040506070806050403020100Viewport
So the correct offset is vmax v + vmin = vmax + vmin v
vmax - vvminWindow: (xmin, ymin) = (-3, -3), (xmax, ymax) = (2 , 1)Viewport: (umin, vmin) = (30, 10), (umax, vmax) = (80, 30)Window-to-Viewport Example - downward pointing v-axisxy-3-2-10123-4-3-2-11234Window (world)
uv010203040506070806050403020100Viewport (screen)
The equation for this situation is:Window-to-Viewport Example - downward pointing v-axis
So:Trying some points:Window-to-Viewport Example - downward pointing v-axis
(xmin, ymin) = (-3, -3) -> (30, 30) (xmax, ymax) = (2, 1) -> Left eye = (-1, -.8) -> Top of head = (-0.5, 0.5) -> xy-3-2-10123-4-3-2-11234Window (world)Viewport (screen)(55, 12.5) (50, 19) (80, 10) uv010203040506070806050403020100