Viewports, Mapping and Clipping
Viewports, Mapping and Clipping
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: