three-dimensional viewing hearn & baker chapter 7

45
Three-Dimensional Viewing Hearn & Baker Chapter 7

Upload: anabel-bell

Post on 18-Jan-2016

309 views

Category:

Documents


19 download

TRANSCRIPT

Page 1: Three-Dimensional Viewing Hearn & Baker Chapter 7

Three-Dimensional ViewingHearn & Baker Chapter 7

Page 2: Three-Dimensional Viewing Hearn & Baker Chapter 7

Overview

• 3D viewing involves some tasks that are not present in 2D viewing: – Projection, – Visibility checks, – Lighting effects, – etc.

Page 3: Three-Dimensional Viewing Hearn & Baker Chapter 7

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

Page 4: Three-Dimensional Viewing Hearn & Baker Chapter 7

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

Page 5: Three-Dimensional Viewing Hearn & Baker Chapter 7

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

Page 6: Three-Dimensional Viewing Hearn & Baker Chapter 7

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

Page 7: Three-Dimensional Viewing Hearn & Baker Chapter 7

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

Page 8: Three-Dimensional Viewing Hearn & Baker Chapter 7

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

Page 9: Three-Dimensional Viewing Hearn & Baker Chapter 7

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

Page 10: Three-Dimensional Viewing Hearn & Baker Chapter 7

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

Page 11: Three-Dimensional Viewing Hearn & Baker Chapter 7

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

Page 12: Three-Dimensional Viewing Hearn & Baker Chapter 7

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

Page 13: Three-Dimensional Viewing Hearn & Baker Chapter 7

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

Page 14: Three-Dimensional Viewing Hearn & Baker Chapter 7

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

Page 15: Three-Dimensional Viewing Hearn & Baker Chapter 7

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

Page 16: Three-Dimensional Viewing Hearn & Baker Chapter 7

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

Page 17: Three-Dimensional Viewing Hearn & Baker Chapter 7

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

Page 18: Three-Dimensional Viewing Hearn & Baker Chapter 7

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

Page 19: Three-Dimensional Viewing Hearn & Baker Chapter 7

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

Page 20: Three-Dimensional Viewing Hearn & Baker Chapter 7

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

Page 21: Three-Dimensional Viewing Hearn & Baker Chapter 7

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

Page 22: Three-Dimensional Viewing Hearn & Baker Chapter 7

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

Page 23: Three-Dimensional Viewing Hearn & Baker Chapter 7

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.

Page 24: Three-Dimensional Viewing Hearn & Baker Chapter 7

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

Page 25: Three-Dimensional Viewing Hearn & Baker Chapter 7

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

Page 26: Three-Dimensional Viewing Hearn & Baker Chapter 7

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.

Page 27: Three-Dimensional Viewing Hearn & Baker Chapter 7

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

Page 28: Three-Dimensional Viewing Hearn & Baker Chapter 7

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

Page 29: Three-Dimensional Viewing Hearn & Baker Chapter 7

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.

Page 30: Three-Dimensional Viewing Hearn & Baker Chapter 7

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.

Page 31: Three-Dimensional Viewing Hearn & Baker Chapter 7

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

Page 32: Three-Dimensional Viewing Hearn & Baker Chapter 7

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)

Page 33: Three-Dimensional Viewing Hearn & Baker Chapter 7

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

Page 34: Three-Dimensional Viewing Hearn & Baker Chapter 7

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)

Page 35: Three-Dimensional Viewing Hearn & Baker Chapter 7

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.

Page 36: Three-Dimensional Viewing Hearn & Baker Chapter 7

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

Page 37: Three-Dimensional Viewing Hearn & Baker Chapter 7

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

Page 38: Three-Dimensional Viewing Hearn & Baker Chapter 7

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

Page 39: Three-Dimensional Viewing Hearn & Baker Chapter 7

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

Page 40: Three-Dimensional Viewing Hearn & Baker Chapter 7

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)

Page 41: Three-Dimensional Viewing Hearn & Baker Chapter 7

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.

Page 42: Three-Dimensional Viewing Hearn & Baker Chapter 7

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.

____

Page 43: Three-Dimensional Viewing Hearn & Baker Chapter 7

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.

Page 44: Three-Dimensional Viewing Hearn & Baker Chapter 7

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.

Page 45: Three-Dimensional Viewing Hearn & Baker Chapter 7

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.