+ All Categories
Home > Documents > VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed...

VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed...

Date post: 14-May-2020
Category:
Upload: others
View: 1 times
Download: 0 times
Share this document with a friend
43
VIEWING Lecture 3 Comp3080 Computer Graphics HKBU
Transcript
Page 1: VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed different techniques for drawing each type of projection Fundamental distinction

VIEWING Lecture 3

Comp3080 Computer Graphics

HKBU

Page 2: VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed different techniques for drawing each type of projection Fundamental distinction

PERSPECTIVE VS PARALLEL

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

Classical viewing developed different techniques for drawing each type of projection

Fundamental distinction is between parallel and perspective viewing even though mathematically parallel viewing is the limit of perspective viewing

9 /26 /2011 COMP3080 COMPUTER GRAPHICS , HKBU 2

Page 3: VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed different techniques for drawing each type of projection Fundamental distinction

PERSPECTIVE PROJECTION

9 /26 /2011 COMP3080 COMPUTER GRAPHICS , HKBU 3

Page 4: VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed different techniques for drawing each type of projection Fundamental distinction

PARALLEL PROJECTION

9 /26 /2011 COMP3080 COMPUTER GRAPHICS , HKBU 4

Page 5: VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed different techniques for drawing each type of projection Fundamental distinction

ORTHOGRAPHIC PROJECTION

Projectors are orthogonal to projection surface

9 /26 /2011 COMP3080 COMPUTER GRAPHICS , HKBU 5

Page 6: VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed different techniques for drawing each type of projection Fundamental distinction

MULTIVIEW ORTHOGRAPHIC

PROJECTION

Projection plane parallel to principal face

Usually form front, top, side views

isometric (not multiview

orthographic view) front

side top

in CAD and architecture,

we often display three

multiviews plus isometric

9 /26 /2011 COMP3080 COMPUTER GRAPHICS , HKBU 6

Page 7: VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed different techniques for drawing each type of projection Fundamental distinction

ADVANTAGES AND DISADVANTAGES

(ORTHOGRAPHIC)

Preserves both distances and angles

Shapes preserved

Can be used for measurements

Building plans

Manuals

Cannot see what object really looks like because many surfaces hidden

from view

Often we add the isometric

9 /26 /2011 COMP3080 COMPUTER GRAPHICS , HKBU 7

Page 8: VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed different techniques for drawing each type of projection Fundamental distinction

COMPUTER VIEWING

There are three aspects of the viewing process, all of which are

implemented in the pipeline,

Positioning the camera

Setting the model-view matrix

Selecting a lens

Setting the projection matrix

Clipping

Setting the view volume

9 /26 /2011 COMP3080 COMPUTER GRAPHICS , HKBU 8

Page 9: VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed different techniques for drawing each type of projection Fundamental distinction

THE OPENGL CAMERA

In 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

9 /26 /2011 COMP3080 COMPUTER GRAPHICS , HKBU 9

Page 10: VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed different techniques for drawing each type of projection Fundamental distinction

ORTHOGONAL PROJECTION

9 /26 /2011 COMP3080 COMPUTER GRAPHICS , HKBU 10

Page 11: VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed different techniques for drawing each type of projection Fundamental distinction

DEFAULT PROJECTION

Default projection is orthogonal

clipped out

z = 0

2

9 /26 /2011 COMP3080 COMPUTER GRAPHICS , HKBU 11

Page 12: VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed different techniques for drawing each type of projection Fundamental distinction

MOVING THE CAMERA FRAME

If we want to visualize object with both positive and negative z values we can either

Move the camera in the positive z direction

Translate the camera frame

Move the objects in the negative z direction

Translate the world frame

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

a translation ( Translatef(0.0, 0.0, -d); )

d > 0

9 /26 /2011 COMP3080 COMPUTER GRAPHICS , HKBU 12

Page 13: VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed different techniques for drawing each type of projection Fundamental distinction

MOVING CAMERA BACK FROM

ORIGIN

default frames

frames after translation by –d

d > 0

9 /26 /2011 COMP3080 COMPUTER GRAPHICS , HKBU 13

Page 14: VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed different techniques for drawing each type of projection Fundamental distinction

PROJECTIONS AND NORMALIZATION

The default projection in the eye (camera) frame is orthogonal

For points within the default view volume

Most graphics systems use view normalization

All other views are converted to the default view by transformations that determine the projection matrix

Allows use of the same pipeline for all views and makes for efficient clipping

xp = x yp = y zp = 0

9 /26 /2011 COMP3080 COMPUTER GRAPHICS , HKBU 14

Page 15: VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed different techniques for drawing each type of projection Fundamental distinction

HOMOGENEOUS COORDINATE

REPRESENTATION

xp = x yp = y zp = 0 wp = 1

pp = Mp

M =

1000

0000

0010

0001

In practice, we can let M = I and set

the z term to zero later

default orthographic projection

9 /26 /2011 COMP3080 COMPUTER GRAPHICS , HKBU 15

Page 16: VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed different techniques for drawing each type of projection Fundamental distinction

ORTHOGONAL NORMALIZATION

Ortho(left, right, bottom, top, near, far)

normalization find transformation to convert

specified clipping volume to default

9 /26 /2011 COMP3080 COMPUTER GRAPHICS , HKBU 16

Page 17: VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed different techniques for drawing each type of projection Fundamental distinction

ORTHOGONAL MATRIX

Two steps

Move center to origin

T(-(left + right)/2, -(bottom + top)/2, (near + far)/2))

Scale to have sides of length 2

S(2/(left - right), 2/(top - bottom), 2/(near - far))

1000

200

02

0

002

nearfar

nearfar

farnear

bottomtop

bottomtop

bottomtop

leftright

leftright

leftright

P = ST =

9 /26 /2011 COMP3080 COMPUTER GRAPHICS , HKBU 17

Page 18: VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed different techniques for drawing each type of projection Fundamental distinction

FINAL PROJECTION

Set z = 0

Equivalent to the homogeneous coordinate transformation

Hence, general orthogonal projection in 4D is

1000

0000

0010

0001

Morth =

P = MorthST

9 /26 /2011 COMP3080 COMPUTER GRAPHICS , HKBU 18

Page 19: VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed different techniques for drawing each type of projection Fundamental distinction

OBLIQUE PROJECTIONS

The OpenGL projection functions cannot produce general parallel projections such as

However if we look at the example of the cube it appears that the cube has been sheared

Oblique Projection = Shear + Orthogonal Projection

9 /26 /2011 COMP3080 COMPUTER GRAPHICS , HKBU 19

Page 20: VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed different techniques for drawing each type of projection Fundamental distinction

ADVANTAGES AND DISADVANTAGES

(OBLIQUE PROJECTION)

Can pick the angles to emphasize a particular face

Angles in faces parallel to projection plane are preserved while we can still see “around” side

In physical world, cannot create with simple camera.

9 /26 /2011 COMP3080 COMPUTER GRAPHICS , HKBU 20

Page 21: VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed different techniques for drawing each type of projection Fundamental distinction

GENERAL SHEAR

side view top view

9 /26 /2011 COMP3080 COMPUTER GRAPHICS , HKBU 21

Page 22: VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed different techniques for drawing each type of projection Fundamental distinction

SHEAR MATRIX

xy shear (z values unchanged)

Projection matrix

General case:

1000

0100

0φcot10

0θcot01

H(θ, ϕ) =

P = Morth H(θ, ϕ)

P = Morth STH(θ, ϕ)

9 /26 /2011 COMP3080 COMPUTER GRAPHICS , HKBU 22

Page 23: VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed different techniques for drawing each type of projection Fundamental distinction

EQUIVALENCY

9 /26 /2011 COMP3080 COMPUTER GRAPHICS , HKBU 23

Page 24: VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed different techniques for drawing each type of projection Fundamental distinction

PERSPECTIVE PROJECTION

9 /26 /2011 COMP3080 COMPUTER GRAPHICS , HKBU 24

Page 25: VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed different techniques for drawing each type of projection Fundamental distinction

ADVANTAGES AND DISADVANTAGES

(PERSPECTIVE PROJECTION)

Objects further from viewer are projected smaller than the same sized objects closer to the viewer (diminution)

Looks realistic

Equal distances along a line are not projected into equal distances (nonuniform foreshortening)

Angles preserved only in planes parallel to the projection plane

More difficult to construct by hand than parallel projections (but not more difficult by computer)

9 /26 /2011 COMP3080 COMPUTER GRAPHICS , HKBU 25

Page 26: VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed different techniques for drawing each type of projection Fundamental distinction

SIMPLE PERSPECTIVE

Center of projection at the origin

Projection plane z = d, d < 0

9 /26 /2011 COMP3080 COMPUTER GRAPHICS , HKBU 26

Page 27: VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed different techniques for drawing each type of projection Fundamental distinction

PERSPECTIVE EQUATIONS

Consider top and side views

xp =

dz

x

/

dz

x

/

yp = dz

y

/zp = d

9 /26 /2011 COMP3080 COMPUTER GRAPHICS , HKBU 27

Page 28: VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed different techniques for drawing each type of projection Fundamental distinction

HOMOGENEOUS COORDINATE

FORM

consider q = Mp where

M =

0/100

0100

0010

0001

d

1

z

y

x

dz

z

y

x

/

q = p =

9 /26 /2011 COMP3080 COMPUTER GRAPHICS , HKBU 28

Page 29: VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed different techniques for drawing each type of projection Fundamental distinction

PERSPECTIVE DIVISION

However w 1, so we must divide by w to return from homogeneous

coordinates

This perspective division yields the desired perspective equations

xp = dz

x

/

yp = dz

y

/zp = d

9 /26 /2011 COMP3080 COMPUTER GRAPHICS , HKBU 29

Page 30: VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed different techniques for drawing each type of projection Fundamental distinction

OPENGL PERSPECTIVE

Frustum(left, right, bottom, top, near, far)

9 /26 /2011 COMP3080 COMPUTER GRAPHICS , HKBU 30

Page 31: VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed different techniques for drawing each type of projection Fundamental distinction

CLIPPING AND MORE

9 /26 /2011 COMP3080 COMPUTER GRAPHICS , HKBU 31

Page 32: VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed different techniques for drawing each type of projection Fundamental distinction

PIPELINE VIEW

9 /26 /2011 COMP3080 COMPUTER GRAPHICS , HKBU 32

modelview

transformation

projection

transformation

perspective

division

clipping projection

nonsingular

4D 3D

against default cube 3D 2D

Page 33: VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed different techniques for drawing each type of projection Fundamental distinction

NOTES

We stay in four-dimensional homogeneous coordinates through both the modelview and projection transformations

Both these transformations are nonsingular

Default to identity matrices (orthogonal view)

Normalization lets us clip against simple cube regardless of type of projection

Delay final projection until end

Important for hidden-surface removal to retain depth information as long as possible

9 /26 /2011 COMP3080 COMPUTER GRAPHICS , HKBU 33

Page 34: VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed different techniques for drawing each type of projection Fundamental distinction

EFFECT ON CLIPPING

The projection matrix P = STH transforms the original clipping volume

to the default clipping volume

top view

DOP DOP

near plane

far plane

object

clipping

volume

z = -1

z = 1

x = -1 x = 1

distorted object

(projects correctly)

9 /26 /2011 COMP3080 COMPUTER GRAPHICS , HKBU 34

Page 35: VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed different techniques for drawing each type of projection Fundamental distinction

SIMPLE PERSPECTIVE

Consider a simple perspective with the COP at the origin, the near

clipping plane at z = -1, and a 90 degree field of view determined by the

planes

x = z, y = z

9 /26 /2011 COMP3080 COMPUTER GRAPHICS , HKBU 35

Page 36: VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed different techniques for drawing each type of projection Fundamental distinction

PERSPECTIVE MATRICES

Simple projection matrix in homogeneous coordinates

Note that this matrix is independent of the far clipping plane

0100

0100

0010

0001

M =

9 /26 /2011 COMP3080 COMPUTER GRAPHICS , HKBU 36

Page 37: VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed different techniques for drawing each type of projection Fundamental distinction

GENERALIZATION

N =

0100

βα00

0010

0001

after perspective division, the point (x, y, z, 1) goes to

x’’ = x/z y’’ = y/z Z’’ = -(α + β / z)

which projects orthogonally to the desired point

regardless of α and β

9 /26 /2011 COMP3080 COMPUTER GRAPHICS , HKBU 37

Page 38: VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed different techniques for drawing each type of projection Fundamental distinction

PICKING α AND β

If we pick a =

b =

nearfar

farnear

farnear

farnear2

the near plane is mapped to z = -1 the far plane is mapped to z =1 and the sides are mapped to x = 1, y = 1

Hence the new clipping volume is the default clipping volume

9 /26 /2011 COMP3080 COMPUTER GRAPHICS , HKBU 38

Page 39: VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed different techniques for drawing each type of projection Fundamental distinction

NORMALIZATION

TRANSFORMATION

original clipping volume

original object new clipping volume

distorted object

projects correctly

9 /26 /2011 COMP3080 COMPUTER GRAPHICS , HKBU 39

Page 40: VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed different techniques for drawing each type of projection Fundamental distinction

NORMALIZATION AND

HIDDEN-SURFACE REMOVAL

Although our selection of the form of the perspective matrices may appear somewhat arbitrary, it was chosen so that if z1 > z2 in the original clipping volume then the for the transformed points z1’ > z2’

Thus hidden surface removal works if we first apply the normalization transformation

However, the formula z’’ = -(α + β / z) implies that the distances are distorted by the normalization which can cause numerical problems especially if the near distance is small

9 /26 /2011 COMP3080 COMPUTER GRAPHICS , HKBU 40

Page 41: VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed different techniques for drawing each type of projection Fundamental distinction

OPENGL PERSPECTIVE

glFrustum allows for an unsymmetric viewing frustum (although

Perspective does not)

9 /26 /2011 COMP3080 COMPUTER GRAPHICS , HKBU 41

Page 42: VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed different techniques for drawing each type of projection Fundamental distinction

OPENGL PERSPECTIVE MATRIX

The normalization in glFrustum requires an initial shear to form a

right viewing pyramid, followed by a scaling to get the normalized

perspective volume. Finally, the perspective matrix results in needing

only a final orthogonal transformation

P = NSH

our previously defined

perspective matrix shear and scale

9 /26 /2011 COMP3080 COMPUTER GRAPHICS , HKBU 42

Page 43: VIEWING - Hong Kong Baptist Universitycomp3080/2011/wp-content/... · Classical viewing developed different techniques for drawing each type of projection Fundamental distinction

WHY DO WE DO IT THIS WAY?

Normalization allows for a single pipeline for both perspective and

orthogonal viewing

We stay in four dimensional homogeneous coordinates as long as

possible to retain three-dimensional information needed for hidden-

surface removal and shading

We simplify clipping

9 /26 /2011 COMP3080 COMPUTER GRAPHICS , HKBU 43


Recommended