computer graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · classical...

45
Computer Graphics Bing-Yu Chen National Taiwan University

Upload: vuhanh

Post on 06-Mar-2018

214 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

Computer Graphics

Bing-Yu ChenNational Taiwan University

Page 2: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

Viewing in 3D

3D Viewing ProcessClassical Viewing and Projections3D Synthetic Camera Model Specification of an Arbitrary 3D ViewParallel ProjectionPerspective Projection3D Clipping for Canonical View Volume

Page 3: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

3D Viewing Process

Transforminto viewportin 2D devicecoordinatesfor display

Project ontoprojection

plane

Clip againstview

volume

2D devicecoordinates

Clippedworld

coordinates

3D world-coordinateoutput primitives

Page 4: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

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

Classical views are based on the relationship among these elements

The viewer picks up the object and orients it how she would like to see it

Each object is assumed to constructed from flat principal faces

Buildings, polyhedra, manufactured objects

Page 5: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

Classical Projections

Front elevation Elevation oblique Plan oblique

Isometric One-point perspective Three-point perspective

Page 6: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

The synthetic camera model involves two components, specified independently:

objects (a.k.a geometry)viewer (a.k.a camera)

3D Synthetic Camera Model

Page 7: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

Imaging with the Synthetic Camera

center of projection

image plane

projector

P

projection of P

The image is rendered onto an image plane or project plane (usually in front of the camera).Projectors emanate from the center of projection(COP) at the center of the lens (or pinhole).The image of an object point P is at the intersection of the projector through P and the image plane.

Page 8: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

Specifying a Viewer

Camera specification requires four kinds of parameters:Position: the COP.Orientation: rotations about axes with origin at the COP.Focal length: determines the size of the image on the film plane, or the field of view.Film plane: its width and height, and possibly orientation.

Page 9: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

ProjectionsProjections transform points in n-space to m-space, where m < n.In 3D, we map points from 3-space to the projection plane (PP) along projectors emanating from the center of projection (COP).

There are two basic type of projections:Perspective – distance from COP to PP finiteParallel – distance from COP to PP infinite

COP

PP

Page 10: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

Perspective vs. Parallel Projections

Computer graphics treats all projections the same and implements them with a single pipelineClassical viewing developed different techniques for drawing each type of projectionFundamental distinction is between parallel and perspective viewing even though mathematically parallel viewing is the limit of perspective viewing

Page 11: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

Perspective vs. Parallel Projections

Page 12: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

Taxonomy ofPlanar Geometric Projections

parallel perspective

axonometricmultivieworthographic

oblique

isometric dimetric trimetric

2 point1 point 3 point

planar geometric projections

Page 13: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

Orthographic Projection

Projectors are orthogonal to projection surface

Page 14: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

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

isometric (not multivieworthographic view) front

sidetop

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

Page 15: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

Advantages and Disadvantages

Preserves both distances and anglesShapes 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 16: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

Axonometric Projections

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

none: trimetrictwo: dimetricthree: isometric

θ 1θ 3θ 2

Allow projection plane to move relative to object

Page 17: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

Types ofAxonometric Projections

IsometricTrimetricDimetric

Page 18: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

Advantages and DisadvantagesLines are scaled (foreshortened) but can find scaling factorsLines preserved but angles are not

Projection of a circle in a plane not parallel to the projection plane is an ellipse

Can see three principal faces of a box-like objectSome optical illusions possible

Parallel lines appear to divergeDoes not look real because far objects are scaled the same as near objectsUsed in CAD applications

Page 19: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

Oblique ProjectionArbitrary relationship between projectors and projection plane

Page 20: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

Advantages and DisadvantagesCan pick the angles to emphasize a particular face

Architecture: plan oblique, elevation obliqueAngles in faces parallel to projection plane are preserved while we can still see “around” side

In physical world, cannot create with simple camera; possible with bellows camera or special lens (architectural)

Page 21: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

Specification ofan Arbitrary 3D View

VRP: view reference pointVPN: view-plane normalVUP: view-up vector

nu

VUP

VPN

VRP

v

Viewplane

Page 22: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

VRC:the viewing-reference coordinate system

CW: center of the window

nu

VPN

VRP

v

CWViewplane

(umax,vmax)

(umin,vmin)

Page 23: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

Infinite Parallelepiped View Volume

DOP: direction of projectionPRP: projection reference point

PRP

DOP

CWViewplane

n

VPNVRP

Page 24: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

Truncated View Volume for an Orthographic Parallel Projection

DOP

VPN

VRP

ViewplaneFront

Clippingplane

BackClippingplane

F

B

Page 25: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

The Mathematics ofOrthographic Parallel Projection

⎥⎥⎥⎥

⎢⎢⎢⎢

=

===

1000000000100001

0;;

ort

ppp

M

zyyxx

y

x

z

z

P(x, y, z)

P(x, y, z)

yp

xp

View along x axis

View along y axis

Projectionplane

Projectionplane

Page 26: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

The Steps of Implementation ofOrthographic Parallel Projection

Translate the VRP to the originRotate VRC such that the VPN becomes the z axisShear such that the DOP becomes parallel to the z axisTranslate and scale into the parallel-projection canonical view volume

)( VRPTRSHTSN parparparpar −••••=

Page 27: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

Perspective Projection

Projectors converge at center of projection

Page 28: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

Truncated View Volume for an Perspective Projection

VPN

VRP

ViewplaneFront

Clippingplane

BackClippingplane

F B

Page 29: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

Perspective Projection(Pinhole Camera)

y

x

z

z

P(x, y, z)

P(x, y, z)

d

d

yp

xp

View along x axis

View along y axis

Projectionplane

Projectionplane

⎥⎥⎥⎥

⎢⎢⎢⎢

=

==

==

0/100010000100001

/;

/

;

d

M

dzyy

dzxx

zy

dy

zx

dx

per

pp

pp

Page 30: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

Perspective Division

However W ≠ 1, so we must divide by W to return from homogeneous coordinates

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

=

⎥⎥⎥⎥

⎢⎢⎢⎢

⎥⎥⎥⎥

⎢⎢⎢⎢

=•=

⎥⎥⎥⎥

⎢⎢⎢⎢

=

⎥⎥⎥⎥

⎢⎢⎢⎢

dzzyx

zyx

d

PM

WZYX

zyx

perp

p

p

10/100010000100001

1

( ) ⎟⎠⎞

⎜⎝⎛=⎟

⎠⎞

⎜⎝⎛= d

dzy

dzx

WZ

WY

WXzyx ppp ,

/,

/,,,,

Page 31: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

The Steps of Implementation ofPerspective Projection

Translate the VRP to the originRotate VRC such that the VPN becomes the z axisTranslate such that the PRP is at the originShear such that the DOP becomes parallel to the z axisScale such that the view volume becomes the canonical perspective view volume

)()( VRPTRPRPTSHSN perperper −••−••=

Page 32: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

Alternative Perspective Projection

y

z

z

P(x, y, z)

P(x, y, z)

d

d

yp

xp

View along x axis

View along y axis

Projectionplane at z=0

Projectionplane at z=0

⎥⎥⎥⎥

⎢⎢⎢⎢

=′

+=

+=

+=

+=

1/100000000100001

1)/(;

1)/(

;

d

M

dzyy

dzxx

dzy

dy

dzx

dx

per

pp

pp

Page 33: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

Vanishing Points

Parallel lines (not parallel to the projection plan) on the object converge at a single point in the projection (the vanishing point) Drawing simple perspectives by hand uses these vanishing point(s)

vanishing point

Page 34: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

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

Page 35: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

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

Page 36: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

One-Point Perspective

One principal face parallel to projection planeOne vanishing point for cube

Page 37: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

Advantages and DisadvantagesObjects further from viewer are projected smaller than the same sized objects closer to the viewer (diminuition)

Looks realisticEqual distances along a line are not projected into equal distances (nonuniformforeshortening)Angles preserved only in planes parallel to the projection planeMore difficult to construct by hand than parallel projections (but not more difficult by computer)

Page 38: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

Canonical View Volume forOrthographic Parallel Projection

x = -1, y = -1, z = 0x = 1, y = 1, z = -1

-1

-1

1

-z

x or y

Backplane Front

plane

Page 39: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

The Extension ofthe Cohen-Sutherland Algorithm

bit 1 – point is above view volume y > 1bit 2 – point is below view volume y < -1bit 3 – point is right of view volume x > 1bit 4 – point is left of view volume x < -1bit 5 – point is behind view volume z < -1bit 6 – point is in front of view volume z > 0

Page 40: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

Intersection of a 3D Line

a line from to can be represented as

so when y = 1

10 ≤≤ t

),,( 0000 zyxP ),,( 1111 zyxP

)()(

)(

010

010

010

zztzzyytyyxxtxx

−+=−+=−+=

01

0100

01

0100

))(1(

))(1(

yyzzyzz

yyxxyxx

−−−

+=

−−−

+=

Page 41: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

Canonical View Volume forPerspective Projection

x = z, y = z, z = -zmin

x = -z, y = -z, z = -1

-1

-1

1

-z

x or y

Backplane Front

plane

Page 42: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

The Extension ofthe Cohen-Sutherland Algorithm

bit 1 – point is above view volume y > -zbit 2 – point is below view volume y < zbit 3 – point is right of view volume x > -zbit 4 – point is left of view volume x < zbit 5 – point is behind view volume z < -1bit 6 – point is in front of view volume z > zmin

Page 43: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

Intersection of a 3D Line

so when y = z

yzzzyy

yzyyyy

zzyyyzxxxx

=−−−

−−+=

−−−−−

+=

)()())(()()(

))((

0101

00010

0101

00010

Page 44: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

Clipping inHomogeneous Coordinates

Why clip inhomogeneous coordinates ?

it is possible to transform the perspective-projection canonical view volume into the parallel-projection canonical view volume

1,

010011

10000100001

min

min

min

min

−≠

⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢

−+−

+= z

zz

zM

Page 45: Computer Graphics - graphics.cmlab.csie.ntu.edu.twrobin/courses/3dcg08/ppt/3... · Classical Viewing Viewing requires three basic elements One or more objects A viewer with a projection

Clipping inHomogeneous Coordinates

The corresponding plane equations areX = -WX = WY = -WY = WZ = -WZ = 0