Foley & Van Dam, Chapter 6cs155/Lecture_08.pdf · Oblique Projection • Cavalier projection : –...

27
Viewing in 3D Foley & Van Dam, Chapter 6

Transcript of Foley & Van Dam, Chapter 6cs155/Lecture_08.pdf · Oblique Projection • Cavalier projection : –...

Page 1: Foley & Van Dam, Chapter 6cs155/Lecture_08.pdf · Oblique Projection • Cavalier projection : – Preserves lengths of lines perpendicular to the viewing plane – 3D nature can

Viewing in 3DFoley & Van Dam, Chapter 6

Page 2: Foley & Van Dam, Chapter 6cs155/Lecture_08.pdf · Oblique Projection • Cavalier projection : – Preserves lengths of lines perpendicular to the viewing plane – 3D nature can

Viewing in 3D

• Transformation Pipeline• Viewing Plane• Viewing Coordinate System• Projections

• Orthographic• Perspective

Page 3: Foley & Van Dam, Chapter 6cs155/Lecture_08.pdf · Oblique Projection • Cavalier projection : – Preserves lengths of lines perpendicular to the viewing plane – 3D nature can

OpenGL Transformation PipelineHomogeneous coordinates

in World System

Viewing Coordinates

Clip Coordinates

ModelView MatrixModelView Matrix

Projection MatrixProjection Matrix

ClippingClipping

Viewport TransformationViewport Transformation

Window Coordinates

Page 4: Foley & Van Dam, Chapter 6cs155/Lecture_08.pdf · Oblique Projection • Cavalier projection : – Preserves lengths of lines perpendicular to the viewing plane – 3D nature can

Viewing Coordinate System

yw

zw

xw

world

Tractor System

Front-Wheel System P0

xv

yv

zv

Viewing plane

Viewer System

Page 5: Foley & Van Dam, Chapter 6cs155/Lecture_08.pdf · Oblique Projection • Cavalier projection : – Preserves lengths of lines perpendicular to the viewing plane – 3D nature can

Specifying the Viewing Coordinates• Viewing Coordinates system, [xv, yv, zv], describes 3D objects with respect to a viewer

• A viewing plane (projection plane) is set up perpendicular to zv and aligned with (xv,yv)

• In order to specify a viewing plane we have to specify:

• a vector N normal to the plane• a viewing-up vector V• a point on the viewing plane

Page 6: Foley & Van Dam, Chapter 6cs155/Lecture_08.pdf · Oblique Projection • Cavalier projection : – Preserves lengths of lines perpendicular to the viewing plane – 3D nature can

Specifying the Viewing Coordinates

• P0=(x0,y0,z0) is the point where a camera is located• P is a point to look-at• N=(P0-P)/|P0-P| is the view-plane normal vector• V=zw is the view up vector, whose projection onto the view-plane is directed up

ywxw

zwP

Nv

P0

xv

yv

zv

Viewing plane

Page 7: Foley & Van Dam, Chapter 6cs155/Lecture_08.pdf · Oblique Projection • Cavalier projection : – Preserves lengths of lines perpendicular to the viewing plane – 3D nature can

Viewing Coordinate System

• The transformation M, from world-coordinate into viewing-coordinates is:

• Defining the camera in OpenGL:glMatrixMode(GL_MODELVIEW);glLoadIdentity();gluLookAt(P0x, P0y, P0z, Px, Py, Pz, Vx, Vy, Vz);

vvvvv xzyNVNVxNz ×=

××

== ;;

TRzyx

zzzyyyxxx

Mvvv

vvv

vvv

⋅=

−−−

=

1000100010001

1000000

0

0

0

321

321

321

Page 8: Foley & Van Dam, Chapter 6cs155/Lecture_08.pdf · Oblique Projection • Cavalier projection : – Preserves lengths of lines perpendicular to the viewing plane – 3D nature can

Projections• Viewing 3D objects on a 2D display requires a mapping from 3D to 2D

• A projection is formed by the intersection of certain lines (projectors) with the view plane

• Projectors are lines from the center of projectionthrough each point in the object

Center of Projection

Page 9: Foley & Van Dam, Chapter 6cs155/Lecture_08.pdf · Oblique Projection • Cavalier projection : – Preserves lengths of lines perpendicular to the viewing plane – 3D nature can

Projections• Center of projection at infinity results with a parallel projection

• A finite center of projection results with a perspective projection

Page 10: Foley & Van Dam, Chapter 6cs155/Lecture_08.pdf · Oblique Projection • Cavalier projection : – Preserves lengths of lines perpendicular to the viewing plane – 3D nature can

Projections• Parallel projections preserve relative proportions of objects, but do not give realistic appearance (commonly used in engineering drawing)

• Perspective projections produce realistic appearance, but do not preserve relative proportions

Perspective Projection

Page 11: Foley & Van Dam, Chapter 6cs155/Lecture_08.pdf · Oblique Projection • Cavalier projection : – Preserves lengths of lines perpendicular to the viewing plane – 3D nature can

Parallel Projection• Projectors are all parallel• Orthographic: Projectors are perpendicular to the projection plane• Oblique: Projectors are not necessarily perpendicular to the projection plane

Orthographic Oblique

Page 12: Foley & Van Dam, Chapter 6cs155/Lecture_08.pdf · Oblique Projection • Cavalier projection : – Preserves lengths of lines perpendicular to the viewing plane – 3D nature can

Orthographic ProjectionSince the viewing plane is aligned with (xv,yv), orthographic projection is performed by:

=

=

11000000000100001

10

10 v

v

v

v

v

p

p

zyx

yx

yx

P0

xv

yv

zv

(x,y,z) (x,y)

Page 13: Foley & Van Dam, Chapter 6cs155/Lecture_08.pdf · Oblique Projection • Cavalier projection : – Preserves lengths of lines perpendicular to the viewing plane – 3D nature can

Orthographic Projection

Front view

Top View

Side View

• Lengths and angles of faces parallel to the viewing planes are preserved

• Problem: 3D nature of projected objects is difficult to deduce

Page 14: Foley & Van Dam, Chapter 6cs155/Lecture_08.pdf · Oblique Projection • Cavalier projection : – Preserves lengths of lines perpendicular to the viewing plane – 3D nature can

Oblique Projection• Projectors are not perpendicular to the viewing plane• Angles and lengths are preserved for faces parallel to the plane of projection• Preserves 3D nature of an object

yv

(x,y,z)

(x,y)

xv

(xp,yp)

Page 15: Foley & Van Dam, Chapter 6cs155/Lecture_08.pdf · Oblique Projection • Cavalier projection : – Preserves lengths of lines perpendicular to the viewing plane – 3D nature can

Oblique Projection•Two types of oblique projections are commonly used:

– Cavalier: α=45ο =tan−1(1)– Cabinet: α=tan-1(2) ≈63.4ο

yv

(x,y,1)(x,y)

xv

(xp,yp)

φ

α

a(x,y,z)

b

Page 16: Foley & Van Dam, Chapter 6cs155/Lecture_08.pdf · Oblique Projection • Cavalier projection : – Preserves lengths of lines perpendicular to the viewing plane – 3D nature can

Oblique Projection

++

=

=

10

sincos

1100000000sin100cos01

10

φφ

φφ

azyazx

zyx

aa

yx

vv

vv

v

v

v

p

p

yv

(x,y,1)(x,y)

xv

(xp,yp)

φ

α

a(x,y,z)

b

1/a=tan(α)z/b= 1/a

b=za

xp=z⋅a⋅cos(φ)yp=z⋅a⋅sin(φ)

Page 17: Foley & Van Dam, Chapter 6cs155/Lecture_08.pdf · Oblique Projection • Cavalier projection : – Preserves lengths of lines perpendicular to the viewing plane – 3D nature can

Oblique Projection

φ=45o φ=30o

φ=45o φ=30o

Cavalier Projections of a cube for two values of angle φ

Cabinet Projections of a cube for two values of angle φ

1

1

11

1

1

1

1

0.5 1

1

0.5

Page 18: Foley & Van Dam, Chapter 6cs155/Lecture_08.pdf · Oblique Projection • Cavalier projection : – Preserves lengths of lines perpendicular to the viewing plane – 3D nature can

Oblique Projection• Cavalier projection :

– Preserves lengths of lines perpendicular to the viewing plane– 3D nature can be captured but shape seems distorted– Can display a combination of front, side, and top views

• Cabinet projection:– Lines perpendicular to the viewing plane project at 1/2 of their length– A more realistic view than the Cavalier projection– Can display a combination of front, side, and top views

Page 19: Foley & Van Dam, Chapter 6cs155/Lecture_08.pdf · Oblique Projection • Cavalier projection : – Preserves lengths of lines perpendicular to the viewing plane – 3D nature can

Perspective Projection • In a perspective projection, the center of projection is at a finite distance from the viewing plane• The size of a projected object is inversely proportional to it distance from the viewing plane• Parallel lines that are not parallel to the viewing plane, converge to a vanishing point• A vanishing point is the projection of a point at infinite distance

Z-axis vanishing pointy

x

z

Page 20: Foley & Van Dam, Chapter 6cs155/Lecture_08.pdf · Oblique Projection • Cavalier projection : – Preserves lengths of lines perpendicular to the viewing plane – 3D nature can

Perspective Projection

Page 21: Foley & Van Dam, Chapter 6cs155/Lecture_08.pdf · Oblique Projection • Cavalier projection : – Preserves lengths of lines perpendicular to the viewing plane – 3D nature can

Vanishing Points• There are infinitely many general vanishing points• There can be up to three principal vanishing points (axis vanishing points)• Perspective projections are categorized by the number of principal vanishing points, equal to the number of principal axes intersected by the viewing plane• Most commonly used: one-point and two-points perspective

Page 22: Foley & Van Dam, Chapter 6cs155/Lecture_08.pdf · Oblique Projection • Cavalier projection : – Preserves lengths of lines perpendicular to the viewing plane – 3D nature can

Vanishing Points

x

y

z

One point (z axis) perspective projection

Two pointsperspective projection

z axis vanishing point

x axis vanishing point

Page 23: Foley & Van Dam, Chapter 6cs155/Lecture_08.pdf · Oblique Projection • Cavalier projection : – Preserves lengths of lines perpendicular to the viewing plane – 3D nature can

Perspective Projection

xy

z

(x,y,z)(xp,yp,0)

center of projection

d

d

x

z

(x,y,z)xp

• Using similar triangles it follows:

dzy

dy

dzx

dx pp

+=

+= ;

0;; =+⋅

=+⋅

= ppp zdzydy

dzxdx

Page 24: Foley & Van Dam, Chapter 6cs155/Lecture_08.pdf · Oblique Projection • Cavalier projection : – Preserves lengths of lines perpendicular to the viewing plane – 3D nature can

Perspective ProjectionThus, a perspective projection matrix is defined as:

=

1100000000100001

d

M per

+=

=

ddz

yx

zyx

d

PM per 0

11100000000100001

0;; =+⋅

=+⋅

= ppp zdzydy

dzxdx

Page 25: Foley & Van Dam, Chapter 6cs155/Lecture_08.pdf · Oblique Projection • Cavalier projection : – Preserves lengths of lines perpendicular to the viewing plane – 3D nature can

Perspective Projection• Mper is singular (|Mper|=0), thus Mper is a many to one mapping (for example: MperP=Mper2P)

• Points on the viewing plane (z=0) do not change

• The homogeneous coordinates of a point at infinity directed to (Ux,Uy,Uz) are (Ux,Uy,Uz,0). Thus, The vanishing point of parallel lines directed to (Ux,Uy,Uz) is at [dUx/Uz, dUy/Uz]

• When d→∞, Mper →Mort

Page 26: Foley & Van Dam, Chapter 6cs155/Lecture_08.pdf · Oblique Projection • Cavalier projection : – Preserves lengths of lines perpendicular to the viewing plane – 3D nature can

ProjectionsWhat is the difference between moving the center of projection and moving the projection plane?

Center of Projection

zProjectionplane

Center of Projection

zProjectionplane

Center of Projection

zProjectionplane

Original

Moving the Center of Projection

Moving the Projection Plane

Page 27: Foley & Van Dam, Chapter 6cs155/Lecture_08.pdf · Oblique Projection • Cavalier projection : – Preserves lengths of lines perpendicular to the viewing plane – 3D nature can

ProjectionsPlanar geometric

projections

Parallel Perspective

OrthographicOblique

CabinetOther

Top Front

Side OtherTwo point

One point

Three point

Cavalier