Three-Dimensional Viewing Hearn & Baker Chapter 7.
-
Upload
anabel-bell -
Category
Documents
-
view
309 -
download
19
Transcript of Three-Dimensional Viewing Hearn & Baker Chapter 7.
Three-Dimensional ViewingHearn & Baker Chapter 7
Overview
• 3D viewing involves some tasks that are not present in 2D viewing: – Projection, – Visibility checks, – Lighting effects, – etc.
Copyright ©2011, ©2004 by Pearson Education, Inc.All rights reserved.
Computer Graphics with OpenGL®, Fourth EditionDonald Hearn • M. Pauline Baker • Warren R. Carithers
Figure 10-1 Coordinate reference for obtaining a selected view of a three-dimensional scene.
• First, set up viewing (or camera) coordinate reference The position and
orientation for a view plane (or projection plane) that corresponds to a camera film plane
Overview
Copyright ©2011, ©2004 by Pearson Education, Inc.All rights reserved.
Computer Graphics with OpenGL®, Fourth EditionDonald Hearn • M. Pauline Baker • Warren R. Carithers
Figure 10-2 Three parallel-projection views of an object, showing relative proportions from different viewing positions.
• Parallel projection As used in engineering
and architectural drawings
Shows accurate dimensions
• Perspective projection Objects far away are
shown smaller than nearby same size objects
Projections
Copyright ©2011, ©2004 by Pearson Education, Inc.All rights reserved.
Computer Graphics with OpenGL®, Fourth EditionDonald Hearn • M. Pauline Baker • Warren R. Carithers
• Depth info is important to identify viewing direction Depth cueing: Vary the brightness of
lines according to distance
Depth Cueing
Copyright ©2011, ©2004 by Pearson Education, Inc.All rights reserved.
Computer Graphics with OpenGL®, Fourth EditionDonald Hearn • M. Pauline Baker • Warren R. Carithers
Figure 10-5 Photographing a scene involves selection of the camera position and orientation.
• Choose a viewing position (place the camera)
• Decide on camera orientation Direction and rotation
(up direction)
3D Viewing Pipeline
Copyright ©2011, ©2004 by Pearson Education, Inc.All rights reserved.
Computer Graphics with OpenGL®, Fourth EditionDonald Hearn • M. Pauline Baker • Warren R. Carithers
• Some viewing operations in 3D are same as in 2D 2D viewport, 2D clipping window, etc.
• Some are different Even though clipping window is 2D on the
view plane, the scene is clipped against a volume (view volume)
3D Viewing Pipeline
Copyright ©2011, ©2004 by Pearson Education, Inc.All rights reserved.
Computer Graphics with OpenGL®, Fourth EditionDonald Hearn • M. Pauline Baker • Warren R. Carithers
Figure 10-6 General three-dimensional transformation pipeline, from modeling coordinates (MC) to world coordinates (WC) to viewing coordinates (VC) to projection coordinates (PC) to normalized coordinates (NC) and, ultimately, to device coordinates (DC).
3D Viewing Pipeline
Copyright ©2011, ©2004 by Pearson Education, Inc.All rights reserved.
Computer Graphics with OpenGL®, Fourth EditionDonald Hearn • M. Pauline Baker • Warren R. Carithers
Figure 10-7 A right-handed viewing-coordinate system, with axes x view, y view, and z view, relative to a right-handed world-coordinate frame.
• Select View point (or viewing
position, eye position, camera position) P0=(x0,y0,z0)
View-up vector V to define yview
Direction to define zview
3D Viewing-Coordinate Parameters
Copyright ©2011, ©2004 by Pearson Education, Inc.All rights reserved.
Computer Graphics with OpenGL®, Fourth EditionDonald Hearn • M. Pauline Baker • Warren R. Carithers
Figure 10-8 Orientation of the view plane and view-plane normal vector N.
• Viewing direction is along zview axis
• So, view plane (or projection plane) is normally perpendicular to this axis
• Orientation of the view plane (and direction of positive zview axis) can be defined by a view-plane normal vector N
The View-Plane Normal Vector
Copyright ©2011, ©2004 by Pearson Education, Inc.All rights reserved.
Computer Graphics with OpenGL®, Fourth EditionDonald Hearn • M. Pauline Baker • Warren R. Carithers
Figure 10-9 Three possible positions for the view plane along the z view axis.
• Then, a scalar parameter is used to set the position of the view plane at coordinate zvp along zview axis
The View-Plane Normal Vector
Copyright ©2011, ©2004 by Pearson Education, Inc.All rights reserved.
Computer Graphics with OpenGL®, Fourth EditionDonald Hearn • M. Pauline Baker • Warren R. Carithers
Figure 10-11 Adjusting the input direction of the view-up vector V to an orientation perpendicular to the view-plane normal vector N.
• After view plane normal N, we choose a direction for view-up vector V (used to determine positive yview)
• V should be perpendicular to N Viewing routines typically
adjust user-defined V
• Often, V=(0,1,0) is a convenient choice
The View-Up Vector
Copyright ©2011, ©2004 by Pearson Education, Inc.All rights reserved.
Computer Graphics with OpenGL®, Fourth EditionDonald Hearn • M. Pauline Baker • Warren R. Carithers
• Right-handed viewing systems are more common, but sometimes left-handed viewing systems are used In left-handed viewing systems viewing direction is
towards the positive zview direction
• Left-handed coordinate references are often used to represent screen coordinates and for the normalization transformation
The uvn Viewing-Coordinate Reference Frame
Copyright ©2011, ©2004 by Pearson Education, Inc.All rights reserved.
Computer Graphics with OpenGL®, Fourth EditionDonald Hearn • M. Pauline Baker • Warren R. Carithers
Figure 10-12 A right-handed viewing system defined with unit vectors u, v, and n.
• View-plane normal N defines zview axis direction
• View-up vector V is used to obtain yview axis direction
• We need to determine xview axis direction cross product of N and V
gives U in xview axis direction
cross product of N and U gives adjusted V
u, v, n are unit vectors in directions U, V, N
The uvn Viewing-Coordinate Reference Frame
Copyright ©2011, ©2004 by Pearson Education, Inc.All rights reserved.
Computer Graphics with OpenGL®, Fourth EditionDonald Hearn • M. Pauline Baker • Warren R. Carithers
• By varying viewing parameters, different viewing effects can be achieved
Generating 3D Viewing Effects
Copyright ©2011, ©2004 by Pearson Education, Inc.All rights reserved.
Computer Graphics with OpenGL®, Fourth EditionDonald Hearn • M. Pauline Baker • Warren R. Carithers
• Translate viewing coordinate origin (P0) to the world coordinate origin
• Align xview, yview, zview with xw, yw, zw
Transformation from World to Viewing Coordinates
1000
100
010
001
0
0
0
z
y
x
T
1000
0
0
0
zyx
zyx
zyx
nnn
vvv
uuu
R
Copyright ©2011, ©2004 by Pearson Education, Inc.All rights reserved.
Computer Graphics with OpenGL®, Fourth EditionDonald Hearn • M. Pauline Baker • Warren R. Carithers
• The transformation matrix is the product of these translation and rotation matrices
Transformation from World to Viewing Coordinates
10000
0
0
, Pnnnn
Pvvvv
Puuuu
TRMzyx
zyx
zyx
VCWC
Copyright ©2011, ©2004 by Pearson Education, Inc.All rights reserved.
Computer Graphics with OpenGL®, Fourth EditionDonald Hearn • M. Pauline Baker • Warren R. Carithers
• In parallel projection, coordinate positions are transferred to view plane along parallel lines orthogonal/orthographic oblique
• For perspective projection, coordinates are transferred to view plane along lines that converge at a point
Projection Transformations
Copyright ©2011, ©2004 by Pearson Education, Inc.All rights reserved.
Computer Graphics with OpenGL®, Fourth EditionDonald Hearn • M. Pauline Baker • Warren R. Carithers
Figure 10-17 Orthogonal projections of an object, displaying plan and elevation views.
• Projection along lines parallel to the view-plane normal N
• Front, side, rear orthogonal projections are often called elevations
• The top one is called plan view
Orthogonal Projections
Copyright ©2011, ©2004 by Pearson Education, Inc.All rights reserved.
Computer Graphics with OpenGL®, Fourth EditionDonald Hearn • M. Pauline Baker • Warren R. Carithers
Axonometric and Isometric Orthogonal Projections .
• Orthogonal projections which show more than one face of an object are called axonometric orthogonal projections
• Isometric: Most common axonometric o.p.s that are generated by aligning projection plane so that it intersects principal axes at the same distance from origin
Copyright ©2011, ©2004 by Pearson Education, Inc.All rights reserved.
Computer Graphics with OpenGL®, Fourth EditionDonald Hearn • M. Pauline Baker • Warren R. Carithers
Figure 10-19 An orthogonal projection of a spatial position onto a view plane.
• If projection direction is parallel to zview
xp=x, yp=y
• z coordinate is kept for visibility detection procedures
Orthogonal Projection Coordinates
Copyright ©2011, ©2004 by Pearson Education, Inc.All rights reserved.
Computer Graphics with OpenGL®, Fourth EditionDonald Hearn • M. Pauline Baker • Warren R. Carithers
• Edges of the clipping window specify the x and y limits
• These are used to form the top, bottom, and two sides of a clipping region called the orthogonal-projection view volume
• Limit the volume in zview direction by near-far (or front-back) clipping planes
Clipping Window and Orthogonal Projection View Volume
Copyright ©2011, ©2004 by Pearson Education, Inc.All rights reserved.
Computer Graphics with OpenGL®, Fourth EditionDonald Hearn • M. Pauline Baker • Warren R. Carithers
Figure 10-22 A finite orthogonal view volume with the view plane “in front” of the near plane.
Copyright ©2011, ©2004 by Pearson Education, Inc.All rights reserved.
Computer Graphics with OpenGL®, Fourth EditionDonald Hearn • M. Pauline Baker • Warren R. Carithers
• mapping coordinates into a normalized view volume with coordinates in the range -1 to 1
Normalization Transformation for an Orthogonal Projection
1000
200
02
0
002
minmax
minmax
minmax
minmax
minmax
minmax
,
farnear
farnear
farnear
normortho
zz
zz
zz
ywyw
ywyw
ywyw
xwxw
xwxw
xwxw
M
Copyright ©2011, ©2004 by Pearson Education, Inc.All rights reserved.
Computer Graphics with OpenGL®, Fourth EditionDonald Hearn • M. Pauline Baker • Warren R. Carithers
Figure 10-25 An oblique parallel projection of a cube, shown in a top view (a), produces a view (b) containing multiple surfaces of the cube.
• Projection path is not perpendicular to view plane
• It can be defined with a vector direction
• The effect is same as z-axis shearing transformation
Oblique Parallel Projections
Copyright ©2011, ©2004 by Pearson Education, Inc.All rights reserved.
Computer Graphics with OpenGL®, Fourth EditionDonald Hearn • M. Pauline Baker • Warren R. Carithers
Figure 10-32 Top view of an oblique parallel-projection transformation. The oblique view volume is converted into a rectangular parallelepiped, and objects in the view volume, such as the green block, are mapped to orthogonal-projection coordinates.
Copyright ©2011, ©2004 by Pearson Education, Inc.All rights reserved.
Computer Graphics with OpenGL®, Fourth EditionDonald Hearn • M. Pauline Baker • Warren R. Carithers
Figure 10-33 A perspective projection of two equal-length line segments at different distances from the view plane.
• Project objects to view plane along converging paths to projection reference point (or center of projection)
Perspective Projections
Copyright ©2011, ©2004 by Pearson Education, Inc.All rights reserved.
Computer Graphics with OpenGL®, Fourth EditionDonald Hearn • M. Pauline Baker • Warren R. Carithers
Figure 10-34 A perspective projection of a point P with coordinates (x, y, z) to a selected projection reference point. The intersection position on the view plane is (xp, yp, zvp ).
Perspective Projectionsuxxxx prp )('
uyyyy prp )('
uzzzz prp )('
10 u
On the viewplane, z’=zvp. Solve this for u
zz
zzu
prp
vp
Substitute this u into x’ and y’ equations
zz
zzx
zz
zzxx
prp
vpprp
prp
vpprpp
zz
zzy
zz
zzyy
prp
vpprp
prp
vpprpp
If projection reference point is on zview
zz
zzxx
prp
vpprpp
zz
zzyy
prp
vpprpp
If it is at origin
z
zxx vp
p
z
zyy vp
p
Copyright ©2011, ©2004 by Pearson Education, Inc.All rights reserved.
Computer Graphics with OpenGL®, Fourth EditionDonald Hearn • M. Pauline Baker • Warren R. Carithers
Figure 10-35 A perspective-projection view of an object is upside down when the projection reference point is between the object and the view plane.
Copyright ©2011, ©2004 by Pearson Education, Inc.All rights reserved.
Computer Graphics with OpenGL®, Fourth EditionDonald Hearn • M. Pauline Baker • Warren R. Carithers
Figure 10-36 Changing perspective effects by moving the projection reference point away from the view plane.
Copyright ©2011, ©2004 by Pearson Education, Inc.All rights reserved.
Computer Graphics with OpenGL®, Fourth EditionDonald Hearn • M. Pauline Baker • Warren R. Carithers
Vanishing Points
• Lines parallel to view plane are still parallel
• But, other lines parallel to each other are now converging
• The point such lines converge at are vanishing points
• Vanishing points for lines parallel to principal axes are principal vanishing points
• How many principal v.p.s can be seen depends on projection plane orientation 1-point, 2-point, or 3-point
projections
Copyright ©2011, ©2004 by Pearson Education, Inc.All rights reserved.
Computer Graphics with OpenGL®, Fourth EditionDonald Hearn • M. Pauline Baker • Warren R. Carithers
Perspective Projection View Volume
• An infinite pyramid of vision is chopped off by near and far clipping planes and we get a truncated pyramid (or frustum)
Copyright ©2011, ©2004 by Pearson Education, Inc.All rights reserved.
Computer Graphics with OpenGL®, Fourth EditionDonald Hearn • M. Pauline Baker • Warren R. Carithers
Perspective-Projection Transformation Matrix
• Cannot directly apply a matrix and get the result• 2 steps are required
First, calculate the homogeneous coordinates using perspective projection matrix
Ph=Mpers P
Then, after normalization and clipping, divide by h (homogeneous parameter, h=zprp-z)
• sz (scaling) and tz (translation) factors for normalizing projected z coordinate values (they depend on the selected normalization range
prp
zz
prpprpprpvpprp
prpprpprpvpprp
pers
z
ts
zyyzz
zxxzz
M
100
00
0
0
Copyright ©2011, ©2004 by Pearson Education, Inc.All rights reserved.
Computer Graphics with OpenGL®, Fourth EditionDonald Hearn • M. Pauline Baker • Warren R. Carithers
Symmetric Perspective Projection Frustum
• If the line from perspective reference point through clipping window center (centerline) is perpendicular to view plane, we have a symmetric frustum
• Clipping window can be specified by width and height, or field-of-view angle and aspect ratio
• With a symmetric frustum, perspective transformation is a mapping to orthogonal coordinates (figure on next slide)
Copyright ©2011, ©2004 by Pearson Education, Inc.All rights reserved.
Computer Graphics with OpenGL®, Fourth EditionDonald Hearn • M. Pauline Baker • Warren R. Carithers
Figure 10-44 A symmetric frustum view volume is mapped to an orthogonal parallelepiped by a perspective-projection transformation.
Copyright ©2011, ©2004 by Pearson Education, Inc.All rights reserved.
Computer Graphics with OpenGL®, Fourth EditionDonald Hearn • M. Pauline Baker • Warren R. Carithers
Oblique Perspective-Projection Frustum
• Centerline not perpendicular to view plane
• First, transform this into a symmetric frustum (z-axis shearing)
• Then proceed as before
Copyright ©2011, ©2004 by Pearson Education, Inc.All rights reserved.
Computer Graphics with OpenGL®, Fourth EditionDonald Hearn • M. Pauline Baker • Warren R. Carithers
Viewport Transformation and 3D Screen Coordinates
• Once we have normalized projection coordinates, clipping can be done on the symmetric cube (or unit cube)
• After clipping, cube contents can be transferred to screen coordinates
• For x and y, same as in 2D • Depth info (z coordinates) must be retained
for visibility testing and surface rendering
Copyright ©2011, ©2004 by Pearson Education, Inc.All rights reserved.
Computer Graphics with OpenGL®, Fourth EditionDonald Hearn • M. Pauline Baker • Warren R. Carithers
3D Clipping Algorithms
• No matter what the projection details were, we now have a normalized cube, so we clip against planes parallel to Cartesian planes (either at coordinates 0 and 1, or -1 and 1)
• The task is to identify object sections within the cube (save parts inside and eliminate parts outside)
• Algorithms are extensions of the 2D algorithms
Copyright ©2011, ©2004 by Pearson Education, Inc.All rights reserved.
Computer Graphics with OpenGL®, Fourth EditionDonald Hearn • M. Pauline Baker • Warren R. Carithers
3D Region Codes
• The idea is the same as in 2D (we added 2 more bits for near and far planes)
• A point is now P=(xh,yh,zh,h)
• h can be a value other than 1 (in perspective projection), so, the inequalities to be satisfied are -1<=xh/h<=1
-1<= yh/h<=1
-1<= zh/h<=1
Copyright ©2011, ©2004 by Pearson Education, Inc.All rights reserved.
Computer Graphics with OpenGL®, Fourth EditionDonald Hearn • M. Pauline Baker • Warren R. Carithers
3D Region Codes
• h values should be nonzero and often positive (these can be easily checked)
• So, our inequalities become -h <= xh <= h, -h <= yh <= h, and -h <= zh <= h
• And bit values can be decided by bit 1 = 1 if h + xh < 0 (left)
bit 2 = 1 if h - xh < 0 (right)
bit 3 = 1 if h + yh < 0 (bottom)
bit 4 = 1 if h - yh < 0 (top)
bit 5 = 1 if h + zh < 0 (near)
bit 6 = 1 if h - zh < 0 (far)
Copyright ©2011, ©2004 by Pearson Education, Inc.All rights reserved.
Computer Graphics with OpenGL®, Fourth EditionDonald Hearn • M. Pauline Baker • Warren R. Carithers
Figure 10-50 Values for the three-dimensional, six-bit region code that identifies spatial positions relative to the boundaries of a view volume.
Copyright ©2011, ©2004 by Pearson Education, Inc.All rights reserved.
Computer Graphics with OpenGL®, Fourth EditionDonald Hearn • M. Pauline Baker • Warren R. Carithers
Figure 10-51 Three-dimensional region codes for two line segments. Line P1P2 intersects the right and top clipping boundaries of the view volume, while line P3P4 is completely below the bottom clipping plane.
____
Copyright ©2011, ©2004 by Pearson Education, Inc.All rights reserved.
Computer Graphics with OpenGL®, Fourth EditionDonald Hearn • M. Pauline Baker • Warren R. Carithers
Figure 10-52 Three-dimensional object clipping. Surface sections that are outside the view-volume clipping planes are eliminated from the object description, and new surface facets may need to be constructed.
Copyright ©2011, ©2004 by Pearson Education, Inc.All rights reserved.
Computer Graphics with OpenGL®, Fourth EditionDonald Hearn • M. Pauline Baker • Warren R. Carithers
Figure 10-53 Clipping a line segment against a plane with normal vector N.
Copyright ©2011, ©2004 by Pearson Education, Inc.All rights reserved.
Computer Graphics with OpenGL®, Fourth EditionDonald Hearn • M. Pauline Baker • Warren R. Carithers
Figure 10-54 Clipping the surfaces of a pyramid against a plane with normal vector N. The surfaces in front of the plane are saved, and the surfaces of the pyramid behind the plane are eliminated.