Introduction to Computer Graphics - CAIG...

37
Introduction to Computer Graphics 5. Viewing in 3D (A) National Chiao Tung Univ, Taiwan By: I-Chen Lin, Assistant Professor Textbook: Hearn and Baker, Computer Graphics, 3rd Ed., Prentice Hall Ref: E.Angel, Interactive Computer Graphics, 4 th Ed., Addison Wesley

Transcript of Introduction to Computer Graphics - CAIG...

Page 1: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG07/Lectures/CG_5_ViewingA_S07.pdfIntroduction to Computer Graphics 5. Viewing in 3D (A) National Chiao Tung

Introduction to Computer Graphics5. Viewing in 3D (A)

National Chiao Tung Univ, TaiwanBy: I-Chen Lin, Assistant Professor

Textbook: Hearn and Baker, Computer Graphics, 3rd Ed., Prentice HallRef: E.Angel, Interactive Computer Graphics, 4th Ed., Addison Wesley

Page 2: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG07/Lectures/CG_5_ViewingA_S07.pdfIntroduction to Computer Graphics 5. Viewing in 3D (A) National Chiao Tung

OutlineClassical views

Computer viewing

Projection matrices

Page 3: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG07/Lectures/CG_5_ViewingA_S07.pdfIntroduction to Computer Graphics 5. Viewing in 3D (A) National Chiao Tung

Classical ViewingViewing requires three basic elements

One or more objectsA viewer with a projection surfaceProjectors that go from the object(s) to the projection surface

Each object is assumed to constructed from flat principal faces

Buildings, polyhedra, manufactured objects

Page 4: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG07/Lectures/CG_5_ViewingA_S07.pdfIntroduction to Computer Graphics 5. Viewing in 3D (A) National Chiao Tung

Planar Geometric ProjectionsStandard projections project onto a plane.

Projectors are lines that eitherconverge at a center of projectionare parallel

Such projections preserve linesbut not necessarily angles

When do we need non-planar projections?

Page 5: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG07/Lectures/CG_5_ViewingA_S07.pdfIntroduction to Computer Graphics 5. Viewing in 3D (A) National Chiao Tung

Classical Projections

Page 6: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG07/Lectures/CG_5_ViewingA_S07.pdfIntroduction to Computer Graphics 5. Viewing in 3D (A) National Chiao Tung

Perspective vs ParallelClassical viewing developed different techniques for drawing each type of projection

Mathematically parallel viewing is the limit of perspective viewing

Computer graphics treats all projections the same and implements them with a single pipeline

Page 7: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG07/Lectures/CG_5_ViewingA_S07.pdfIntroduction to Computer Graphics 5. Viewing in 3D (A) National Chiao Tung

Taxonomy of Planar Geometric Projections

parallel perspective

axonometricmultivieworthographic

oblique2 point1 point 3 point

planar geometric projections

isometric dimetric trimetric

Page 8: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG07/Lectures/CG_5_ViewingA_S07.pdfIntroduction to Computer Graphics 5. Viewing in 3D (A) National Chiao Tung

Perspective Projection

Page 9: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG07/Lectures/CG_5_ViewingA_S07.pdfIntroduction to Computer Graphics 5. Viewing in 3D (A) National Chiao Tung

Parallel Projection

Page 10: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG07/Lectures/CG_5_ViewingA_S07.pdfIntroduction to Computer Graphics 5. Viewing in 3D (A) National Chiao Tung

Orthographic ProjectionProjectors are orthogonal to projection surface

Page 11: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG07/Lectures/CG_5_ViewingA_S07.pdfIntroduction to Computer Graphics 5. Viewing in 3D (A) National Chiao Tung

Multiview Orthographic ProjectionProjection plane parallel to principal facesUsually form front, top, side views

isometric (not multivieworthographic view) front

side

in CAD and architecture, we often display three multiviews plus isometric

top

Page 12: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG07/Lectures/CG_5_ViewingA_S07.pdfIntroduction to Computer Graphics 5. Viewing in 3D (A) National Chiao Tung

Advantages and DisadvantagesPreserves both distances and angles

Shapes preservedCan be used for measurements

Building plansManuals

Cannot see what object really looks like because many surfaces hidden from view

Often we add the isometric

Page 13: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG07/Lectures/CG_5_ViewingA_S07.pdfIntroduction to Computer Graphics 5. Viewing in 3D (A) National Chiao Tung

Axonometric ProjectionsAllow projection plane to move relative to object

classify by how many angles ofa corner of a projected cube are the same

none: trimetrictwo: dimetricthree: isometric

θ 1θ 3θ 2

Page 14: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG07/Lectures/CG_5_ViewingA_S07.pdfIntroduction to Computer Graphics 5. Viewing in 3D (A) National Chiao Tung

Types of Axonometric Projections

Page 15: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG07/Lectures/CG_5_ViewingA_S07.pdfIntroduction to Computer Graphics 5. Viewing in 3D (A) National Chiao Tung

Advantages and DisadvantagesLines are scaled (foreshortened) but can find scaling factors

Lines preserved but angles are notProjection of a circle in a plane not parallel to the projection plane is an ellipse

Does not look real because far objects are scaled the same as near objects

Used in CAD applications

Page 16: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG07/Lectures/CG_5_ViewingA_S07.pdfIntroduction to Computer Graphics 5. Viewing in 3D (A) National Chiao Tung

Oblique ProjectionArbitrary relationship between projectors and projection plane

Page 17: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG07/Lectures/CG_5_ViewingA_S07.pdfIntroduction to Computer Graphics 5. Viewing in 3D (A) National Chiao Tung

Perspective ProjectionProjectors coverage at center of projection

Page 18: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG07/Lectures/CG_5_ViewingA_S07.pdfIntroduction to Computer Graphics 5. Viewing in 3D (A) National Chiao Tung

Vanishing PointsParallel lines (not parallel to the projection plan):

converge at a single point in the projection (the vanishing point)

Drawing simple perspectives by hand uses these vanishing point(s)

vanishing point

Page 19: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG07/Lectures/CG_5_ViewingA_S07.pdfIntroduction to Computer Graphics 5. Viewing in 3D (A) National Chiao Tung

Three-Point PerspectiveNo principal face parallel to projection planeThree vanishing points for cube

Page 20: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG07/Lectures/CG_5_ViewingA_S07.pdfIntroduction to Computer Graphics 5. Viewing in 3D (A) National Chiao Tung

Two-Point PerspectiveOn principal direction parallel to projection planeTwo vanishing points for cube

Page 21: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG07/Lectures/CG_5_ViewingA_S07.pdfIntroduction to Computer Graphics 5. Viewing in 3D (A) National Chiao Tung

One-Point PerspectiveOne principal face parallel to projection planeOne vanishing point for cube

Page 22: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG07/Lectures/CG_5_ViewingA_S07.pdfIntroduction to Computer Graphics 5. Viewing in 3D (A) National Chiao Tung

Advantages and DisadvantagesDiminution:

Objects further from viewer are projected smaller (Looks realistic)

Nonuniform foreshortening:Equal distances along a line are not projected into equal distances

Angles preserved only in planes parallel to the projection plane

More difficult to construct by hand than parallel projections

Page 23: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG07/Lectures/CG_5_ViewingA_S07.pdfIntroduction to Computer Graphics 5. Viewing in 3D (A) National Chiao Tung

Computer Viewing

Page 24: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG07/Lectures/CG_5_ViewingA_S07.pdfIntroduction to Computer Graphics 5. Viewing in 3D (A) National Chiao Tung

Pipeline View

ModelingTransformation

ModelingTransformation

ViewingTransformation

ViewingTransformation

ProjectionTransformation

ProjectionTransformation

Normalizationand

clipping

Normalizationand

clipping

ViewportTransformation

ViewportTransformation

MC WC VC

PC NC DC

Let’s skip the clipping temporarily !

Page 25: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG07/Lectures/CG_5_ViewingA_S07.pdfIntroduction to Computer Graphics 5. Viewing in 3D (A) National Chiao Tung

Computer ViewingThree aspects of the viewing process implemented in the pipeline:

Positioning the cameraSetting the model-view matrix

Selecting a lensSetting the projection matrix

ClippingSetting the view volume

Page 26: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG07/Lectures/CG_5_ViewingA_S07.pdfIntroduction to Computer Graphics 5. Viewing in 3D (A) National Chiao Tung

The OpenGL CameraIn OpenGL, initially the object and camera frames are the same

Default model-view matrix is an identity

The camera is located at origin and points in the negative z direction

OpenGL also specifies a default view volume that is a cube with sides of length 2 centered at the origin

Default projection matrix is an identity

Page 27: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG07/Lectures/CG_5_ViewingA_S07.pdfIntroduction to Computer Graphics 5. Viewing in 3D (A) National Chiao Tung

Moving the Camera FrameIf we want to visualize object with both positive and negative z values we can either

Move the camera in the positive z directionTranslate the camera frame

Move the objects in the negative z directionTranslate the world frame

Both of these views are equivalent and are determined by the model-view matrix

Want a translation (glTranslatef(0.0,0.0,-d);)d > 0

Page 28: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG07/Lectures/CG_5_ViewingA_S07.pdfIntroduction to Computer Graphics 5. Viewing in 3D (A) National Chiao Tung

Moving Camera back from Origin

default frames

frames after translation by –dd > 0

Page 29: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG07/Lectures/CG_5_ViewingA_S07.pdfIntroduction to Computer Graphics 5. Viewing in 3D (A) National Chiao Tung

Moving the CameraWe can move the camera to any desired position by a sequence of rotations and translations

Example: side viewRotate the cameraMove it away from originModel-view matrix C = TR

Page 30: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG07/Lectures/CG_5_ViewingA_S07.pdfIntroduction to Computer Graphics 5. Viewing in 3D (A) National Chiao Tung

gluLookAtglLookAt(eyex, eyey, eyez, atx, aty, atz, upx, upy, upz)

Page 31: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG07/Lectures/CG_5_ViewingA_S07.pdfIntroduction to Computer Graphics 5. Viewing in 3D (A) National Chiao Tung

Projections and NormalizationThe default projection in the eye (camera) frame is orthogonal For points within the default view volume

xp = xyp = yzp = 0

Page 32: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG07/Lectures/CG_5_ViewingA_S07.pdfIntroduction to Computer Graphics 5. Viewing in 3D (A) National Chiao Tung

Homogeneous Coordinate Representation

default orthographic projectionxp = xyp = yzp = 0wp = 1

pp = Mp

⎥⎥⎥⎥

⎢⎢⎢⎢

1000000000100001

M =

In practice, we can let M = I and setthe z term to zero later

Page 33: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG07/Lectures/CG_5_ViewingA_S07.pdfIntroduction to Computer Graphics 5. Viewing in 3D (A) National Chiao Tung

Simple PerspectiveCenter of projection at the originProjection plane z = d, d < 0

Page 34: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG07/Lectures/CG_5_ViewingA_S07.pdfIntroduction to Computer Graphics 5. Viewing in 3D (A) National Chiao Tung

Perspective EquationsTop view Side view

dzx/

dzx/ dz

y/

xp = yp = zp = d

Page 35: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG07/Lectures/CG_5_ViewingA_S07.pdfIntroduction to Computer Graphics 5. Viewing in 3D (A) National Chiao Tung

Homogeneous Coordinate Form

M =

⎥⎥⎥⎥

⎢⎢⎢⎢

0/100010000100001

d

⎥⎥⎥⎥

⎢⎢⎢⎢

dzzyx

/

consider q = Mp where

⎥⎥⎥⎥

⎢⎢⎢⎢

1zyx

⇒ q = p =

Page 36: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG07/Lectures/CG_5_ViewingA_S07.pdfIntroduction to Computer Graphics 5. Viewing in 3D (A) National Chiao Tung

Perspective DivisionHowever w ≠ 1, so we must divide by w to return from homogeneous coordinatesThis perspective division yields

the desired perspective equations

dzx/ dz

y/

xp = yp = zp = d

Page 37: Introduction to Computer Graphics - CAIG Labcaig.cs.nctu.edu.tw/course/CG07/Lectures/CG_5_ViewingA_S07.pdfIntroduction to Computer Graphics 5. Viewing in 3D (A) National Chiao Tung

Viewport TransformationFrom the working coordinate to the coordinate of display device.

(1,1)

(-1,-1)

(0,0)

(0,0)

(600,600)

By 2D scaling and translation

Next: clipping and normalization !