23 nov cg eden1
TRANSCRIPT
-
8/13/2019 23 Nov CG Eden1
1/38
Introduction to Open GL
By
Rama Satish KV
Visiting Professor, WASE
-
8/13/2019 23 Nov CG Eden1
2/38
Class Objective
WINDOW TO VIEWPORT TRANSFORMATION
-
8/13/2019 23 Nov CG Eden1
3/38
WINDOW~TO-VIEWPORT
TRANSFORMATION
Some graphics packages allow the programmer to
specify output primitive coordinates in a floating-point
world coordinate system.
The term world is used because the application programis representing a world that is being interactively created
or displayed to the user.
Given that output primitives are specified in world
coordinates, the graphics subroutine package must betold how to map world coordinates onto screen
coordinates.
-
8/13/2019 23 Nov CG Eden1
4/38
Coordinate mapping
We could do this mapping by having the application
programmer provide the graphics package with a
transformation matrix to effect the mapping.
Another way is to have the application programmer specify arectangular region in world coordinates, called the world
coordinate window, and at corresponding rectangular region
in screen coordinates, called the viewport. into which the
world-coordinate window is to be mapped.
The transformation that maps the window into the viewport is
applied to all of the output primitives in world coordinates,
thus mapping them into screen coordinates. Figure 5.10
shows this concept.
-
8/13/2019 23 Nov CG Eden1
5/38
ViewPort
As seen in this figure, if the window and viewport do not have
the same height to width ratio, a non uniform scaling occurs.
If the application program changes the window or viewport,
then new output primitives drawn onto the screen will be
affected by the change.
Existing output primitives are not affected by such a change.
-
8/13/2019 23 Nov CG Eden1
6/38
The application program would be able to change the window or
the viewport at any time, in which case subsequently specified
output primitive would be subjected to a new transformation.
If the change included a different viewport, then the new output
primitive would be located on the canvas in positions different
from those of the old ones, as shown in Fig. 5.11.
-
8/13/2019 23 Nov CG Eden1
7/38
-
8/13/2019 23 Nov CG Eden1
8/38
Output primitives in world coordinates are clipped against
the window. Those that remain are displayed in the
viewport
-
8/13/2019 23 Nov CG Eden1
9/38
CLIPPING IN A RASTER WORLD
Clipping can be done analytically on thefly
during scan conversion, or as part of a
copyPixel with the desired clip rectangle from
a canvas storing unclipped primitive to the
destination canvas.
Combining clipping and scan conversion,
sometimes called scissoring, is easy to dofor filled or thick primitives as part of span
arithmetic
-
8/13/2019 23 Nov CG Eden1
10/38
-
8/13/2019 23 Nov CG Eden1
11/38
CLIPPING LINES This section treats analytical clipping of lines against
rectangles.
Circles and Ellipses may be piece wise linearly
approximated with a sequence of very short lines, so that
boundaries can be treated as a single polyline or polygon forboth clipping and scan conversion.
Clipping a rectangle against a rectangle results in at most a
single rectangle.
Clipping a convex polygon against a rectangle results in atmost a single convex polygon, but clipping a concave
polygon may produce more than one concave polygon.
Clipping a circle or ellipse against a rectangle results in as
many as four arcs.
-
8/13/2019 23 Nov CG Eden1
12/38
Lines intersecting a rectangular clip region
are always clipped to a single line segment;
lines lying on the clip rectangle's border are
considered inside and hence are displayed.
Figure 3.38 shows several examples of
clipped lines.
-
8/13/2019 23 Nov CG Eden1
13/38
Fig 3.38
-
8/13/2019 23 Nov CG Eden1
14/38
Clipping Endpoints
Let's look at the simpler problem of clipping individual points.
If the x coordinate boundaries of the clip rectangle are at xmin
and Xmaxand the y coordinate boundaries are at Yminand
Ymaxthen four inequalities must be satisfied for a point (x. y)to be inside the clip rectangle:
If any of the four inequalities does not hold, the point isoutside the clip rectangle.
-
8/13/2019 23 Nov CG Eden1
15/38
Clipping the end points
continued
To clip a line, we need to consider only its endpoints, not itsinfinitely many interior points.
If both endpoints of a line lie inside the clip rectangle (e.g.,AB inFig. 3.38), the entire line lies inside the clip rectangle and can be
triviallyaccepted. If one endpoint lies inside and one out side (e.g., CD in the
figure), the line intersects the clip rectangle and we mustcompute the intersection point. lf both endpoints are outside theclip rectangle, the line may (or may not) intersect with the cliprectangle (EF. GH, and IJ in the figure), and
we need to perform further calculations to determine whetherthere are any intersections, and if there are, where they occur.
-
8/13/2019 23 Nov CG Eden1
16/38
-
8/13/2019 23 Nov CG Eden1
17/38
The Cohen-Sutherland Line
Clipping Algorithm
The more efficient Cohen-Sutherland algorithm performs initialtests on a line to determine whether intersection calculations canbe avoided.
First. endpoint pairs are checked for trivial acceptance.
If the line can not be trivially accepted. region checks are done. For instance, two simple comparisons onx show that both
endpoints of line EF in Fig. 3.38 have anx coordinate less thanxminand thus lie in the region to the left of the clip rectangle (l.e.,in the outside half plane defined by the left edge) therefore linesegment EF can be trivially rejected and needs to be neitherclipped nor displayed.
Similarly, we can trivially reject lines with both endpoints inregions to the right of Xmaxbelow Yminand above Ymax.
-
8/13/2019 23 Nov CG Eden1
18/38
To perform trivial accept and reject tests, we extend
the edges of the clip rectangle to divide the plane of
the clip rectangle into nine regions (see Fig. 3.39 ).
Each region is assigned a 4-bit code, determined bywhere the region lies with respect to the outside half
planes of the clip-rectangle edges.
Each bit in the outcode is set to either 1(true) or 0
(false); the 4 bits in the code correspond to thefollowing conditions:
-
8/13/2019 23 Nov CG Eden1
19/38
-
8/13/2019 23 Nov CG Eden1
20/38
Compute OutCode
-
8/13/2019 23 Nov CG Eden1
21/38
Cohen Sutherland Line Clip
Algorithm
-
8/13/2019 23 Nov CG Eden1
22/38
A Parametric Line-Clipping
Algorithm
-
8/13/2019 23 Nov CG Eden1
23/38
CLIPPING CIRCLES AND
ELLIPSES
To clip a circle against a rectangle, we can first do a trivialaccept/reject test by intersecting the circle's extent (a squareof the size of the circle diameter) with the clip rectangle,
Using the algorithm in the next section for polygon clipping.
If the circle intersects the rectangle, we divide it intoquadrants and do the trivial accept/reject test for each.
These tests may lead in turn to tests for octants.
We can then compute the intersection of the circle and the
edge analytically by solving their equations simultaneously,and then scan convert the resulting arcs using theappropriately initialized algorithm with the calculated (andsuitably rounded) starting and ending points.
-
8/13/2019 23 Nov CG Eden1
24/38
CLIPPING CIRCLES AND
ELLIPSESs
If scan conversion is fast or if the circle is not
too large, it s probably more efficient to
scissor on a pixel-by-pixel basis, testing each
boundary pixel against the rectangle boundsbefore it iswritten.
-
8/13/2019 23 Nov CG Eden1
25/38
Viewing in 3D
The 3D viewing process is inherently more complex than is the
2D viewing process. In 2D we simply specify a window on the 2D world and a
viewport on the 2D view surface.
Conceptually objects in the world are dipped against the
window and are then transformed into the viewport for display. The extra complexity of 3D viewing is caused in part by the
added dimension and in part by the fact that display devices are
only 2D.
The solution to the mismatch between 3D objects and 2Ddisplays is accomplished by Introdudngprojections, which
transform 3D objects onto a 2D projection plane.
Much of this chapter is devoted to projections: what they are,
their mathematics, and how they are used in a current graphicssubroutine acka e.
-
8/13/2019 23 Nov CG Eden1
26/38
Conceptual model of 3D
viewing process
-
8/13/2019 23 Nov CG Eden1
27/38
In 3D viewing, we specify a view volume in the world, a
projection onto a projection planeand a viewport on the
view surface.
Conceptually, objects in the 3D world are clipped againstthe 3D view volume and are then projected.
The contents of the projection of the view volume onto
the projection plane. called the window, are then
transformed (mapped) into the viewport for display.
Figure 6.1 shows this conceptual model of the 3D
viewing process, which is the model presented to the
users of numerous 3D graphics subroutine packages.
Just as with 2D viewing, a variety of strategies can be
used to implement the viewing process.
Conceptual model of 3D
viewing process
-
8/13/2019 23 Nov CG Eden1
28/38
PROJECTIONS
In general, projections transform points in a coordinate systemof dimension n into points in a coordinate system of dimension
less than n.
The projection of a 3D object is defined by straight projection
rays (calledprojectors) emanating from a center of projection,passing through each point of the objects and intersecting a
projection plane to form the projection.
-
8/13/2019 23 Nov CG Eden1
29/38
Planar geometr ic p roject ions
The class of projections we deal with here is known asplanar
geometric projections, because the projection is onto a planerather than some curved surface and uses straight rather than
curved projectors.
Many cartographic projections are either non planar or non
geometric. Similarly, the Omnimax film format requires a nongeometric projection.
Planar geometric projections. hereafter referred to simply as
projections, can be divided into two basic classes :perspective
and parallel.
The distinction is in the relation of the center of projection to
the projection plane.
If the distance from the one to the other is finite, then the
projection is perspective; If the distance is infinite, the
projection is parallel.
-
8/13/2019 23 Nov CG Eden1
30/38
Perspective Projections
The perspective projections of any set of parallel lines
that are not parallel to the projection plane converge to a
vanishing point.
ln 3D, the parallel lines meet only at infinity, so thevanishing point can be thought of as the projection of a
point at infinity.
There is of course an infinity of vanishing points, one for
each of the infinity of directions in which a line can be
oriented.
-
8/13/2019 23 Nov CG Eden1
31/38
-
8/13/2019 23 Nov CG Eden1
32/38
Perspective projections are categorized by their number
of principal vanishing points and therefore by the number
of axes the projection plane cuts.
Figure 6.3 shows two different one-point perspectiveprojections of a cube.
It is clear that they are one-point projections because
lines parallel to thex and y axis do not converge; only
lines parallel to the z axis do so.
Figure 6.4 shows the construction of a one-point
perspective with some of the projectors and with the
projection plane cutting only the z axis.
-
8/13/2019 23 Nov CG Eden1
33/38
Fig. 6.4 Construction
of one-point
perspective
projection of cube
onto plane cuttingthe z axis. Projection-
plane normal is
parallel to z axis.
-
8/13/2019 23 Nov CG Eden1
34/38
Figure 6.5 shows the construction of a two-point
perspective.
Notice that lines parallel to the y axis do not converge in
the projection. Two-point perspective is commonly used in architectural,
engineering, industrial design, and in advertising
drawings.
Three-point perspectives are used less frequently. sincethey add little realism beyond that afforded by the two-
point perspective.
-
8/13/2019 23 Nov CG Eden1
35/38
Fig. 6.5 Two-pointperspective projection of a
cube. The projection plane
cuts thex and z axes.
-
8/13/2019 23 Nov CG Eden1
36/38
Parallel Projections
page4
-
8/13/2019 23 Nov CG Eden1
37/38
Next Class
Viewing in 2D/3D
Clipping in 2D/3D
http://www.google.co.in/url?sa=i&source=images&cd=&cad=rja&docid=CEF-PhlEd7UZjM&tbnid=s6FjiYvqs8PpAM:&ved=0CAgQjRwwAA&url=http%3A%2F%2Fjimperdue.me%2Ftag%2Fchurch-growth%2F&ei=v41NUsLVOcbDrAe53oCADg&psig=AFQjCNGWlk2V1YWqKQFFFeZgKA3zb7Td4A&ust=1380900672065510 -
8/13/2019 23 Nov CG Eden1
38/38