0% found this document useful (0 votes)
45 views

Viewports, Mapping and Clipping

1. A window defines the area of a scene to display in world coordinates, while a viewport defines where it is displayed in screen coordinates. Mapping between the window and viewport scales and shifts the graphics to fit the screen. 2. Clipping removes any graphics outside the viewport so only visible portions are drawn, analogous to only seeing through a window. 3. A point's position in the window is mapped to the viewport, maintaining relative positioning.

Uploaded by

odin phone
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

Viewports, Mapping and Clipping

1. A window defines the area of a scene to display in world coordinates, while a viewport defines where it is displayed in screen coordinates. Mapping between the window and viewport scales and shifts the graphics to fit the screen. 2. Clipping removes any graphics outside the viewport so only visible portions are drawn, analogous to only seeing through a window. 3. A point's position in the window is mapped to the viewport, maintaining relative positioning.

Uploaded by

odin phone
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Viewports, Mapping and

Clipping
Introduction
• In a given problem, it may be much more natural to think in
terms of x varying from, say, -1 to 1, and y varying from –
100.0 to 20.0 and not only the positive values of x and y.
• Methods that let a programmer describe objects in whatever
coordinate system best fits the problem at hand, and to have
the picture automatically scaled and shifted so that it fits on
the screen window.
Viewports
• In the previous sessions, drawings used the basic coordinate system
of the screen window: coordinates that are essentially in pixels,
extending from 0 to some value (Width) in x, and from 0 to some
value (Height) in y.
• This means that only positive values of x and y can be used, and the
values must extend over a large range (several hundred pixels) if to
get a drawing of some reasonable size.
• In a given problem, it may be much more natural to think in terms of
x varying from, say, -1 to 1, and y varying from –100.0 to 20.0. A
picture can be automatically scaled and shifted so that it fits in the
screen window.
• The space in which objects are described is called world coordinates.
• It is the usual Cartesian xy-coordinate system used in mathematics,
based on whatever units are convenient.
• A rectangular world window is defined in these world coordinates.
• The world window specifies which part of the “world” should be
drawn.
• The understanding is that whatever lies inside the window should be
drawn; whatever lies outside should be clipped away and not drawn.
• we define a rectangular viewport in the screen window on the screen.
• A mapping (consisting of scalings and shiftings) between the world window
and the viewport is established so that when all the objects in the world
are drawn, the parts that lie inside the world window are automatically
mapped to the inside of the viewport.
• So a programmer thinks in terms of “looking through a window” at the
objects being drawn, and placing a “snapshot” of whatever is seen in that
window into the viewport on the display.
• This window/viewport approach makes it much easier to do natural things
like “zooming in” on a detail in the scene, or “panning around” a scene.
• Consider Sinc(x), a famous function in signal processing, which is
expressed as follows:

• As x varies from -∞ to ∞ the value of sinc(x) varies over a range of -1


to 1.
• For instance, a plot of sinc(x) that is centred at (0,0) and showing
sinc(x) for closely spaced x values between, say -4.0 and 4.0 can be
drawn using OpenGL to generate a plot as shown in the following
Figure.
Sinc(x) Plot
• See sincPlot code
• The code in these examples operates in a natural coordinate system
for the problem: x is made to vary in small increments from –4.0 to
4.0.
• The key issue here is how the various (x, y) values become scaled and
shifted so that the picture appears properly in the screen window.
Window to Viewport Mapping
• Window to viewport mapping is used to map world coordinates to
screen or device coordinates.
• A window is an area that defines what is to be displayed, while a
viewport is the area that defines where it is to be displayed.
• The following Figure shows a window in world coordinates and the
viewport in screen or display coordinates.
• Whatever area is selected in the window is sent to the viewport.
• The size of the viewport might be smaller or larger than the window.
Fig: The window in world coordinates and the
viewport in screen coordinates
• The window-to-viewport transformation maintains the relative
position of a point in window as well as in the viewport.
• A point at position (xw,yw) in the window is mapped into position
(xv,yv) in the associated viewport.
• An example is shown in the figure below:
Window to viewport transformation example
Clipping
• Any part of a picture that lies beyond the confines of the screen
cannot be displayed, hence methods to handle pictures that are
larger than available display screen size are used.
• Suppose the size of the picture to be shown is bigger than the size of
the screen, then only a portion of the picture can be displayed.
• The context is similar to that of viewing a scene outside the window.
• While the scene outside is quite large, a window will allow to see
only that portion of the scene as can be visible from the window – the
latter is limited by the size of the window.
• If we presume that the screen, which allows us to see the pictures as
a window, then any picture whose parts lie outside the limits of the
window cannot be shown and for algorithmic purposes, they have to
be “clipped”.
• Conclusion:
• This activity has presented how objects in one coordinate system can
be mapped into to another, i.e. world to screen/device coordinates.
• This allows the picture to be scaled and shifted so that it can fit on
the device window.
Review
1. Define window and viewpoint.
2. Define clipping.
3. Explain why clipping is important in drawing graphics.
4. Describe how window to viewport mapping is performed.

You might also like