viewing in 3d - biuu.cs.biu.ac.il/~kapaho/cg/07_view3d.pdf · distance results with a perspective...

38
Viewing in 3D (Chapt. 6 in FVD, Chapt. 12 in Hearn & Baker)

Upload: others

Post on 30-Apr-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Viewing in 3D - BIUu.cs.biu.ac.il/~kapaho/CG/07_View3D.pdf · distance results with a perspective projection. •A perspective projection produces realistic appearance, but does not

Viewing in 3D(Chapt. 6 in FVD, Chapt. 12 in Hearn & Baker)

Page 2: Viewing in 3D - BIUu.cs.biu.ac.il/~kapaho/CG/07_View3D.pdf · distance results with a perspective projection. •A perspective projection produces realistic appearance, but does not

Viewing in 3D vs. 2D

world

3D

2D

world Camera

2D 2D

Page 3: Viewing in 3D - BIUu.cs.biu.ac.il/~kapaho/CG/07_View3D.pdf · distance results with a perspective projection. •A perspective projection produces realistic appearance, but does not

Transformation Pipe-Line

world

Viewer

System

Body

System

Front-

Wheel

System

Modeling transformation

Viewing

transformation

Projection

Transformation

Transformation

To viewport

Page 4: Viewing in 3D - BIUu.cs.biu.ac.il/~kapaho/CG/07_View3D.pdf · distance results with a perspective projection. •A perspective projection produces realistic appearance, but does not

Transformation Pipe-Line

Viewing

Transformation

Modeling

Transformation

Workstation

Transformation

Modeling

Coordinates

World Coordinates

Viewing Coordinates

Device Coordinates

Projection

Transformation

Projection Coordinates

Page 5: Viewing in 3D - BIUu.cs.biu.ac.il/~kapaho/CG/07_View3D.pdf · distance results with a perspective projection. •A perspective projection produces realistic appearance, but does not

Specifying the Viewing

Coordinate System

yw

zw

xw

world

P0

xv

yv

zv

Viewer

System

Viewing Coordinates system,

P0, [xv, yv, zv].

Page 6: Viewing in 3D - BIUu.cs.biu.ac.il/~kapaho/CG/07_View3D.pdf · distance results with a perspective projection. •A perspective projection produces realistic appearance, but does not

Specifying the Viewing

Coordinate System

world

P0

xv

yv

zv

Viewer

System

A viewing plane (projection plane)

is set up perpendicular to zv and

aligned with (xv,yv).

Page 7: Viewing in 3D - BIUu.cs.biu.ac.il/~kapaho/CG/07_View3D.pdf · distance results with a perspective projection. •A perspective projection produces realistic appearance, but does not

Specifying the Viewing

Coordinate System

• Camera definition (1 option):

ywxw

zw

L

N

v

P

xv

yv

zv

P=(Px,Py,Pz) camera location.

L - is a point to look-at.

V - is the view-up vector. V

projection onto the view-plane is

directed up.

Page 8: Viewing in 3D - BIUu.cs.biu.ac.il/~kapaho/CG/07_View3D.pdf · distance results with a perspective projection. •A perspective projection produces realistic appearance, but does not

• How to form Viewing coordinate

system :

• The transformation, M, from world-

coordinate into viewing-coordinates

is:

• Defining the camera in OpenGL

glMatrixMode(GL_MODELVIEW);

glLoadIdentity(); # camera “looking” down

gluLookAt(Px,Py,Pz,Lx,Ly,Lz,Vx,Vy,Vz)

vvv

v

vvv XZY

ZV

ZVX

LP

LPZ

;;

TRP

P

P

zzz

yyy

xxx

Mz

y

x

z

v

y

v

x

v

z

v

y

v

x

v

z

v

y

v

x

v

1000

100

010

001

1000

0

0

0

Page 9: Viewing in 3D - BIUu.cs.biu.ac.il/~kapaho/CG/07_View3D.pdf · distance results with a perspective projection. •A perspective projection produces realistic appearance, but does not

Projections

• Viewing 3D objects on a 2D display

requires a mapping from 3D to 2D.

• Projectors are lines from the center

of projection through each point in

the object.

• A projection is formed by the

intersection of the projectors with a

viewing plane.

Center of

Projection

Projectors

Page 10: Viewing in 3D - BIUu.cs.biu.ac.il/~kapaho/CG/07_View3D.pdf · distance results with a perspective projection. •A perspective projection produces realistic appearance, but does not

• Center of projection at infinity

results with a parallel projection.

•A parallel projection preserves

relative proportions of objects, but

does not give realistic appearance

(commonly used in engineering

drawing).

Page 11: Viewing in 3D - BIUu.cs.biu.ac.il/~kapaho/CG/07_View3D.pdf · distance results with a perspective projection. •A perspective projection produces realistic appearance, but does not

• A center of projection at a finite

distance results with a perspective

projection.

• A perspective projection produces

realistic appearance, but does not

preserve relative proportions.

Page 12: Viewing in 3D - BIUu.cs.biu.ac.il/~kapaho/CG/07_View3D.pdf · distance results with a perspective projection. •A perspective projection produces realistic appearance, but does not

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 13: Viewing in 3D - BIUu.cs.biu.ac.il/~kapaho/CG/07_View3D.pdf · distance results with a perspective projection. •A perspective projection produces realistic appearance, but does not

• If the viewing plane is aligned

with (xv,yv), orthographic

projection is performed by:

Orthographic Projection

11000

0000

0010

0001

1

0

1

0 v

v

v

v

v

p

p

z

y

x

y

x

y

x

P0

xv

yv

zv

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

Page 14: Viewing in 3D - BIUu.cs.biu.ac.il/~kapaho/CG/07_View3D.pdf · distance results with a perspective projection. •A perspective projection produces realistic appearance, but does not

• Lengths and angles of faces

parallel to the viewing planes are

preserved (Plan View).

• Problem: 3D nature of projected

objects is difficult to deduce.

Page 15: Viewing in 3D - BIUu.cs.biu.ac.il/~kapaho/CG/07_View3D.pdf · distance results with a perspective projection. •A perspective projection produces realistic appearance, but does not

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 16: Viewing in 3D - BIUu.cs.biu.ac.il/~kapaho/CG/07_View3D.pdf · distance results with a perspective projection. •A perspective projection produces realistic appearance, but does not

=45o =30o

Cavalinear Projections (=45o) of a cube

for two values of angle (angle to the horizon)

1

1

1

1

1

1

Several Oblique Projections

Cavalinear 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.

Page 17: Viewing in 3D - BIUu.cs.biu.ac.il/~kapaho/CG/07_View3D.pdf · distance results with a perspective projection. •A perspective projection produces realistic appearance, but does not

=45o =30o

Cabinet Projections (= 63.4o) of a cube

for two values of angle (angle to horizon)

1

1

0.5 1

1

0.5

Several Oblique Projections

• Cabinet projection:

– lines perpendicular to the viewing

plane project at 1/2 of their length.

– A more realistic view than the

Cavalinear projection.

– Can display a combination of

front, side, and top views.

Page 18: Viewing in 3D - BIUu.cs.biu.ac.il/~kapaho/CG/07_View3D.pdf · distance results with a perspective projection. •A perspective projection produces realistic appearance, but does not

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 its distance

from the viewing plane.

• Parallel lines that are not parallel to the

viewing plane, converge to a vanishing

point.

Page 19: Viewing in 3D - BIUu.cs.biu.ac.il/~kapaho/CG/07_View3D.pdf · distance results with a perspective projection. •A perspective projection produces realistic appearance, but does not

Perspective Projection

• A vanishing point is the projection of a

point at infinity.

Z-axis vanishing pointy

x

z

Page 20: Viewing in 3D - BIUu.cs.biu.ac.il/~kapaho/CG/07_View3D.pdf · distance results with a perspective projection. •A perspective projection produces realistic appearance, but does not
Page 21: Viewing in 3D - BIUu.cs.biu.ac.il/~kapaho/CG/07_View3D.pdf · distance results with a perspective projection. •A perspective projection produces realistic appearance, but does not

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: Viewing in 3D - BIUu.cs.biu.ac.il/~kapaho/CG/07_View3D.pdf · distance results with a perspective projection. •A perspective projection produces realistic appearance, but does not

x

y

z

One point (z axis)

perspective projection

Two points

perspective projection

z axis

vanishing point.

x axis

vanishing point.

Page 23: Viewing in 3D - BIUu.cs.biu.ac.il/~kapaho/CG/07_View3D.pdf · distance results with a perspective projection. •A perspective projection produces realistic appearance, but does not

x

y

z

(x,y,z)

(xp,yp,0)

center of

projection

d

Perspective Projection

d – focal length

Page 24: Viewing in 3D - BIUu.cs.biu.ac.il/~kapaho/CG/07_View3D.pdf · distance results with a perspective projection. •A perspective projection produces realistic appearance, but does not

• Using similar triangles it follows:

dz

y

d

y

dz

x

d

x pp

;

d

x

-z

(x,y,z)

xp

0;;

ppp z

dz

ydy

dz

xdx

(0,0)

Page 25: Viewing in 3D - BIUu.cs.biu.ac.il/~kapaho/CG/07_View3D.pdf · distance results with a perspective projection. •A perspective projection produces realistic appearance, but does not

• Thus, a perspective projection

matrix is defined:

11

00

0000

0010

0001

d

M per

d

dz

y

x

z

y

x

d

PM per 0

111

00

0000

0010

0001

0;;

ppp z

dz

ydy

dz

xdx

Page 26: Viewing in 3D - BIUu.cs.biu.ac.il/~kapaho/CG/07_View3D.pdf · distance results with a perspective projection. •A perspective projection produces realistic appearance, but does not

Observations

• Mper is singular (|Mper|=0), thus Mper is

a many to one mapping.

• 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, Mperspective Mortho

Page 27: Viewing in 3D - BIUu.cs.biu.ac.il/~kapaho/CG/07_View3D.pdf · distance results with a perspective projection. •A perspective projection produces realistic appearance, but does not

What 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 28: Viewing in 3D - BIUu.cs.biu.ac.il/~kapaho/CG/07_View3D.pdf · distance results with a perspective projection. •A perspective projection produces realistic appearance, but does not

Summary

Planar geometric

projections

Parallel Perspective

OrthographicOblique

Cavalinear

Cabinet

Other

TopFront

Side Other

Two

point

One

point

Three

point

Page 29: Viewing in 3D - BIUu.cs.biu.ac.il/~kapaho/CG/07_View3D.pdf · distance results with a perspective projection. •A perspective projection produces realistic appearance, but does not

Demo

Page 30: Viewing in 3D - BIUu.cs.biu.ac.il/~kapaho/CG/07_View3D.pdf · distance results with a perspective projection. •A perspective projection produces realistic appearance, but does not

Viewing Window

• After objects were projected onto the

viewing plane, an image is taken from a

Viewing Window.

• A viewing window can be placed

anywhere on the view plane.

• In general the view window is aligned

with the viewing coordinates and is

defined by its extreme points: (l,b) and

(r,t)

yv

xv

zv

Page 31: Viewing in 3D - BIUu.cs.biu.ac.il/~kapaho/CG/07_View3D.pdf · distance results with a perspective projection. •A perspective projection produces realistic appearance, but does not

Viewing Volume

• Given the specification of the viewing

window, we can set up a Viewing

Volume.

• Only objects inside the viewing volume

will appear in the display, the rest are

clipped.

Page 32: Viewing in 3D - BIUu.cs.biu.ac.il/~kapaho/CG/07_View3D.pdf · distance results with a perspective projection. •A perspective projection produces realistic appearance, but does not

• In order to limit the infinite viewing volume

we define two additional planes: Near Plane

and Far Plane.

• Only objects in the bounded viewing volume

will appear.

• The near and far planes are parallel to the

viewing plane and specified by znear and zfar.

• A limited viewing volume is defined:

– For orthographic: a rectangular

parallelpiped.

– For oblique: an oblique parallelpiped.

– For perspective: a frustum.

zv

Near

Plane

Far

Plane

zv

Near

Plane

Far

Plane

Page 33: Viewing in 3D - BIUu.cs.biu.ac.il/~kapaho/CG/07_View3D.pdf · distance results with a perspective projection. •A perspective projection produces realistic appearance, but does not

• The Viewing Plane can be placed

anywhere along the Zv axis, as long it

does not contain the center of

projection.

zv

Near

Plane

Far

Plane

Page 34: Viewing in 3D - BIUu.cs.biu.ac.il/~kapaho/CG/07_View3D.pdf · distance results with a perspective projection. •A perspective projection produces realistic appearance, but does not

Defining the viewing Volume

zv

far

near

yv

xv

left

righttop

bottom

zv

far

near

yv

xv

left

righttop

bottom

Page 35: Viewing in 3D - BIUu.cs.biu.ac.il/~kapaho/CG/07_View3D.pdf · distance results with a perspective projection. •A perspective projection produces realistic appearance, but does not

Defining the Viewing Volume

• Definition for Orthographic Projection:

glMatrixMode(GL_PROJECTION) ;

glLoadIdentity(); # camera “looks” down.

glOrtho(l,r,b,t,n,f);

zv

far

near

yv

xv

left

righttop

bottom

Page 36: Viewing in 3D - BIUu.cs.biu.ac.il/~kapaho/CG/07_View3D.pdf · distance results with a perspective projection. •A perspective projection produces realistic appearance, but does not

• Definition for general Perspective Projection:

Note: near and far values are quantities, e.g. near=50.0 means that the near plane passes at Zv=-50.

zv

far

near

yv

xv

left

righttop

bottom

glMatrixMode(GL_PROJECTION) ;

glLoadIdentity();

glFrustum(l,r,b,t,n,f);

Page 37: Viewing in 3D - BIUu.cs.biu.ac.il/~kapaho/CG/07_View3D.pdf · distance results with a perspective projection. •A perspective projection produces realistic appearance, but does not

• Definition for standard Perspective Projection:

• Note: aspectRatio=w/h .

glMatrixMode(GL_PROJECTION) ;

glLoadIdentity();

gluPerspective(viewAngle,aspectRatio,n,f);

zv

far

near

yv

xv

h

w

Page 38: Viewing in 3D - BIUu.cs.biu.ac.il/~kapaho/CG/07_View3D.pdf · distance results with a perspective projection. •A perspective projection produces realistic appearance, but does not

OpenGL Transformation

Pipe-Line

Homogeneous coordinates

in World System

ModelView Matrix

Projection Matrix

Clipping

Viewport

Transformation

Viewing Coordinates

Projection Coordinates

Window Coordinates