2 Dviewing
2 Dviewing
2 Dviewing
Clipping Algorithms
Procedures for displaying two dimensional views of a
picture.
Any Cartesian coordinate system can be used to define the
picture.
A single or multiple areas of a picture can be selected for
display by a user.
The selected parts of the picture are mapped to device
coordinates for display.
Transformation from world to device coordinates involve
translation, rotation, scaling operations, and procedures for
deleting parts of the picture (clipping).
TWO-DIMENSIONAL VIEWING PIPELINE
Clipping Window
A section of a two dimensional scene that is selected for
display.
Viewport
Used to control the placement of the clipping window
within the display window.
The clipping window selects what we want to see, the
viewport indicates where it is to be viewed on the output
device.
Two-Dimensional Viewing Transformation
The mapping of a two-dimensional, world-coordinate
scene description to device coordinates.
Changing the viewport position allows for viewing
objects at different locations on the display device.
By changing clipping window size or position, zooming,
overview, or panning effects can be achieved.
1. Construct World Coordinate Scene using Model-
Coordinate Transformations
2. Convert World Coordinates to Viewing Coordinates
(clipping window)
3. Transform Viewing Coordinates to Normalized
Coordinates
4. Map Normalized Coordinates to Device Coordinates
THE CLIPPING WINDOW
Most applications allow only a rectangular clipping
window aligned with the x and y axes.
Rectangular clipping windows in standard positions are
easily defined by giving the coordinates of two opposite
corners of each rectangle.
We could design our own clipping window with any
shape, size, or orientation.
A concave polygon clipping window or one with
nonlinear boundaries, requires more processing.
If we like to get a rotated view of a scene, we could
either define a rectangular clipping window in a rotated
viewing-coordinate frame or, equivalently, we could
rotate the world-coordinate scene. Some systems provide
options for selecting a rotated, two-dimensional viewing
frame, but usually the clipping window must be
specified in world coordinates.
glutHideWindow ( );
In addition, we can return a “hidden” display window, or
one that has been converted to an icon, by designating it
as the current display window and then invoking the
function
glutShowWindow ( );
GLUT Subwindows
Within a selected display window, we can set up any
number of second-level display windows, which are
called subwindows. This provides a means for
partitioning display windows into different display
sections.
We create a subwindow with the following function
glutCreateSubWindow(windowID,xBottomLeft, yBottomLeft,
width, height);
Parameter windowID identifies the display window in
which we want to set up the subwindow.
SELECTING A DISPLAY-WINDOW
SCREEN-CURSOR SHAPE
We can use the following GLUT routine to request a
shape for the screen cursor that is to be used with the
current window:
glutSetCursor (shape);
For example, we can assign the symbolic constant
GLUT_CURSOR_UP_DOWN to parameter shape to
obtain an up-down arrow. A rotating arrow is chosen
with GLUT_CURSOR_CYCLE, a wristwatch shape is
selected with GLUT_CURSOR_WAIT, and a skull and
crossbones is obtained with the constant
GLUT_CURSOR _DESTROY.
VIEWING GRAPHICS OBJECTS IN A
GLUT DISPLAY WINDOW
we invoke the following function to assign something to that window:
glutDisplayFunc (pictureDescrip);
The argument is a routine that describes what is to be displayed in the
currentwindow. This routine, called pictureDescrip for this example, is
referred to as a callback function because it is the routine that is to be
executed whenever GLUT determines that the display-window
contents should be renewed.
Also, we may need to call glutDisplayFunc after the
glutPopWindow command if the display window has been damaged
during the process of redisplaying the windows. In this case, the
following function is used to indicate that the contents of the current
display window should be renewed:
glutPostRedisplay ( );
This routine is also used when an additional object, such as a pop-up
menu, is to be shown in a display window.
Sometimes it is convenient to designate a function that is to
be executed when there are no other events for the system to
process. We can do that with
glutIdleFunc (function);
The parameter for this GLUT routine could reference a
background function or a procedure to update parameters for
an animation when no other processes are taking place.
Finally, we can use the following function to query the
system about some of the current state parameters:
glutGet (stateParam);
we can retrieve the current display-window width or the
screen width with GLUT_WINDOW_WIDTH or
GLUT _SCREEN_WIDTH.