1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview...

78
1 Chapter 5 Viewing

Transcript of 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview...

Page 1: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

1

Chapter 5

Viewing

Page 2: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

2

OpenGL Perspective Matrix

parallel perspective

axonometric multivieworthographic

oblique

isometric dimetric trimetric

2 point1 point 3 point

planar geometric projections

Page 3: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

3

Perspective Projection

Page 4: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

4

Parallel Projection

Page 5: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

5

Classical Viewing Viewing requires three basic elements

One or more objects A viewer with a projection surface Projectors 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 6: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

6

Planar Geometric Projections Standard projections project onto a plane Projectors are lines that either

converge at a center of projection are parallel

Such projections preserve lines but not necessarily angles

Page 7: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

7

Classical Projections

Page 8: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

8

Orthographic Projection Projectors are orthogonal to projection surface

Page 9: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

9

Multiview Orthographic Projection

Projection plane parallel to principal face Usually form front, top, side views

isometric (not multivieworthographic view)

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

top

front

side

Page 10: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

10

Advantages and Disadvantages Preserves both distances and angles

Shapes preserved Can 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 11: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

11

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

32

Page 12: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

12

Types of Axonometric Projections

Page 13: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

13

Construction of Axonometric Projections

Projectors are still orthogonal to the projection plane, but Projection plane can have any orientation w.r.t. the object

Page 14: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

14

Advantages and Disadvantages Lines are scaled (foreshortened) but can find scaling factors Lines 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 object Some optical illusions possible

Parallel lines appear to diverge

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

Used in CAD applications

Page 15: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

15

Oblique ProjectionArbitrary relationship between projectors and

projection plane

Page 16: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

16

Advantages and Disadvantages Can pick the angles to emphasize a particular face In physical world, cannot create with simple

camera; possible with bellows camera or special lens (architectural)

Page 17: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

17

Perspective Projection Projectors coverge at center of projection

Page 18: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

18

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 19: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

19

Three-Point Perspective No principal face parallel to projection plane Three vanishing points for cube

Page 20: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

20

Two-Point Perspective On principal direction parallel to projection plane Two vanishing points for cube

Page 21: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

21

One-Point Perspective One principal face parallel to projection plane One vanishing point for cube

Page 22: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

22

Advantages and Disadvantes Objects further from viewer are projected smaller than t

he same sized objects closer to the viewer (diminuition) 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)

Page 23: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

23

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

Page 24: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

24

The OpenGL Camera In OpenGL, initially the world 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 25: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

25

Default ProjectionDefault projection is orthogonal

clipped out

z=0

Page 26: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

26

Moving the Camera Frame If we want to visualize object with both positive and negativ

e 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 determin

ed by the model-view matrix Want a translation (glTranslatef(0.0,0.0,-d);) d > 0

Page 27: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

27

Moving Camera Back from Origin

default frames

frames after translation by –d d > 0

Page 28: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

28

Moving the Camera (Object) We can move the camera to any desired

position by a sequence of rotations and translations

Example: positive x (side view of an object) Rotate the camera Move it away from origin Model-view matrix C = TR

Page 29: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

29

OpenGL Code Remember that last transformation

specified is first to be applied

glMatrixMode(GL_MODELVIEW)glLoadIdentity();glTranslatef(0.0, 0.0, -d);glRotatef(90.0, 0.0, 1.0, 0.0);

We are changing the modelview matrix C. A vertex specified at qthrough glVertex, after the change is still at q in the world frame, but is at Cq in the camera frame known internally to OpenGL.

Page 30: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

30

Manually Generating an Isometric View – 1/3

Rotating about the y axis by 45o

Rotating about the x axis by 35.26o

Translating along the z direction by d

z

y

22

2 z

y

22 2

Page 31: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

31

Manually Generating an Isometric View – 2/3

1000

3/33/33/3

06/63/66/6

02/202/2

1000

03/33/33/3

06/63/66/6

02/202/2

1000

100

0010

0001

1000

02/202/2

0010

02/202/2

1000

03/63/30

03/33/60

0001

1000

100

0010

0001

dd

dRTRM yx

Page 32: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

32

Manually Generating an Isometric View – 3/3

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

glTranslatef(0.0, 0.0, -d);

glRotatef(35.26, 1.0, 0.0, 0.0);

glRotate(45.0, 0.0, 1.0, 0.0);

Page 33: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

33

The LookAt Function – 1/2 The GLU library contains the function glLookAt to fr

om the required modelview matrix through a simple interface

Note the need for setting an up direction Still need to initialize

Can concatenate with modeling transformations Example: isometric view of cube aligned with axes

glMatrixMode(GL_MODELVIEW):glLoadIdentity();gluLookAt(-1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

Page 34: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

34

The LookAt Function – 2/2glLookAt(eyex, eyey, eyez, atx, aty, atz,

upx, upy, upz)

Page 35: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

35

Other Viewing APIs – 1/2 The LookAt function is only one possible

API for positioning the camera Others include

View reference point, view plane normal, view up (PHIGS, GKS-3D)

Yaw, pitch, roll Elevation, azimuth, twist Direction angles

Page 36: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

36

Other Viewing APIs – 2/2

Page 37: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

37

Simple Perspective Center of projection at the origin Projection plane z = d, d < 0

Page 38: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

38

Perspective EquationsConsider top and side views

xp =dz

x

/yp =

dz

y

/zp = d

Page 39: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

39

Homogeneous Coordinate Form

M =

0/100

0100

0010

0001

d

consider q = Mp where

1

z

y

x

dz

z

y

x

/

q = p =

Page 40: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

40

Perspective Division However w 1, so we must divide by w to

return from homogeneous coordinates This perspective division yields

the desired perspective equations We will consider the corresponding clipping

volume with the OpenGL functions

xp =dz

x

/yp =

dz

y

/zp = d

Page 41: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

41

Orthogonal Projections 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

xp = xyp = yzp = 0

Page 42: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

42

Homogeneous Coordinate Representation

xp = xyp = yzp = 0wp = 1

pp = Mp

M =

1000

0000

0010

0001

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

Page 43: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

43

Projections in OpenGL

Page 44: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

44

OpenGL PerspectiveglFrustum(xmin,xmax,ymin,ymax,near,fa

r)

Page 45: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

45

Using Field of View With glFrustum it is often difficult to get the d

esired view gluPerpective(fovy, aspect, near, fa

r) often provides a better interface

aspect = w/h

front plane

Page 46: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

46

OpenGL Orthogonal ViewingglOrtho(xmin,xmax,ymin,ymax,near,far)

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

near and far measured from camera

Page 47: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

47

Hidden-Surface Removal

Page 48: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

48

Z-Buffer Algorithm Keep track of the smallest depth or z value f

or each pixel Z value is initialized to the farthest distance Worst-case time complexity is O(n), where

n is the number of polygons glutInitDisplayMode(GLUT_DEPTH);

glEnable(GL_DEPTH_TEST);glClear(GL_DEPTH_BUFFER_BIT);

Page 49: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

49

Culling Removing all the faces pointing away from

the viewer. For example, rendering n cubes with culling can filter 3n polygons

glEnable(GL_CULL);

Page 50: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

50

Walking Through a Scene – 1/3void keys(unsigned char key, int x, int y)

{

if(key==‘x’) viewer[0]-=1.0;

if(key==‘X’) viewer[0]+=1.0;

if(key==‘y’) viewer[1]-=1.0;

if(key==‘Y’) viewer[1]+=1.0;

if(key==‘z’) viewer[2]-=1.0;

if(key==‘Z’) viewer[2]+=1.0;

glutPostRedisplay();

}

Page 51: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

51

Walking Through a Scene – 2/3void display(void)

{

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glLoadIdentity();

gluLookAt(viewer[0],viewer[1],viewer[2],0.0,0.0,0.0,0.0,1.0,0.0);

glRotatef(theta[0],1.0,0.0,1.0);

glRotatef(theta[1],0.0,1.0,0.0);

glRotatef(theta[2],0.0,0.0,1.0);

colorcube();

glFlush();

glutSwapBuffers();

}

Page 52: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

52

Walking Through a Scene – 3/3void myReshape(int w, int h)

{

glViewport(0, 0, w, h);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

if(w<=h) glFrustum(-2.0, 2.0, -2.0*(GLfloat)h/(GLfloat)w,

2.0*(GLfloat)h/(GLfloat)w, 2.0, 20.0);

else glFrustum(-2.0, 2.0, -2.0*(GLfloat)w/(GLfloat)h,

2.0*(GLfloat)w/(GLfloat)h, 2.0, 20.0);

glMatrixMode(GL_MODELVIEW);

}

Page 53: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

53

Parallel-Projection Matrices

Perspective ViewOrthographic projection of distorted object

Page 54: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

54

Normalization Rather than derive a different projection

matrix for each type of projection, we can convert all projections to orthogonal projections with the default view volume

This strategy allows us to use standard transformations in the pipeline and makes for efficient clipping

Page 55: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

55

Pipeline View

modelviewtransformation

projectiontransformation

perspective division

clipping projection

nonsingular

4D 3D

against default cube 3D 2D

Page 56: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

56

Notes We stay in four-dimensional homogeneous coordinate

s 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 infor

mation as long as possible

Page 57: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

57

Orthogonal NormalizationglOrtho(left,right,bottom,top,near,fa

r)normalization find transformation to convertspecified clipping volume to default

Canonical view volume

-1-1 -11 1 1

Page 58: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

58

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 =

Page 59: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

59

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

Page 60: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

60

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

Page 61: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

61

General Shear

top viewside view

cot

cot

tan

zyy

zxx

xx

z

p

p

p

Page 62: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

62

Shear Matrixxy shear (z values unchanged)

Projection matrix

General case:

1000

0100

0φcot10

0θcot01

H(,) =

P = Morth H(,)

P = Morth STH(,)

Page 63: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

63

Equivalency

Page 64: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

64

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

clippingvolume

z = -1

z = 1

x = -1x = 1

distorted object(projects correctly)

Page 65: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

65

Simple PerspectiveConsider 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

Page 66: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

66

Perspective MatricesSimple projection matrix in homogeneous

coordinates (z=-1, and the center of projection is at the origin)

Note that this matrix is independent of the far clipping plane

0100

0100

0010

0001

M =

Page 67: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

67

Generalization

0100

βα00

0010

0001

Let N =

after persepective divison, the point (x, y, z, 1) goes to

x’’ = -x/zy’’ = -y/zz’’ = -(+/z)

If we apply an orthographic projection along the z-axis to N, we get:

0100

0000

0010

0001

MorthN=

And the projection of an arbitrary point pis, p’=MorthNp = , after perspective division:

z

y

x

0

xp = -x/zyp = -y/z

We get the same result regardless of and

Page 68: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

68

Picking and If we pick

minmax

minmax

zz

zz

minmax

minmax

zz

zz2

the zmin plane is mapped to z = -1the zmax plane is mapped to z =1and the sides are mapped to x = 1, y = 1

Hence the new clipping volume is the default clipping volume

Page 69: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

69

Normalization Transformation

original clipping

volumeoriginal object new clipping

volume

distorted objectprojects correctly

Page 70: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

70

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 we 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

Page 71: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

71

OpenGL Perspective glFrustum allows for an unsymmetric vie

wing frustum (although gluPerspective does not)

Page 72: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

72

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

Page 73: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

73

Normalization DetailsShear the point of ((xmin+xmax)/2,(ymin+ymax)/2, zmax) to (0, 0, zmax)

)

2(cot),

2(cot),(

max

maxmin1

max

maxmin1

z

yy

z

xxHH

So the resulting frustum is described by the planes:

max

min

max

minmax

max

minmax

2

2

zz

zz

zz

yyy

zz

xxx

Next, scale the volume so that x=z, y= z, so the scaling matrix is:S(2zmax/(xmax-xmin),2zmax/(ymax-ymin),1)Finally, we make use of the previous N.

x

z z=zmax

z=zmin

Page 74: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

74

Why do we do it this way? Normalization allows for a single pipeline

for both perspective and orthogonal viewing

We keep in four dimensional homogeneous coordinates as long as possible to retain three-dimensional information needed for hidden-surface removal and shading

We simplify clipping

Page 75: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

75

Projections and Shadows

Idea: put the projectionplane behind the object!For example, in this figure,assume (xl, yl, zl) is a lightsource, then we can set the projection plane on theplane of y=0

Page 76: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

76

Implementing Shadows – 1/2Move the light source to the originby a translation:T(-xl, -yl, -zl), then wecould use a simple perspective projectionthrough the origin, the projection matrix is

Finally we translate everything back.

001

0

0100

0010

0001

ly

M

Page 77: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

77

Implementing Shadows – 2/2GLfloat m[16];

/* shadow projection matrix */

For(i=0;i<15;i++) m[i]=0.0;

m[0]=m[5]=m[10]=1.0;

m[7]=-1.0/yl;

glColor3fv(polygon_color);

glBegin(GL_POLYGON);

. /* draw polygon normally */

.

glEnd();

glMatrixMode(GL_MODELVIEW);

glPushMatrix();

glTranslatef(xl, yl, zl);

glMultMatrixf(m);

glTranslate(-xl, -yl, -zl);

glColor3fv(shadow_color);

glBegin(GL_POLYGON);

. /* draw the polygon again */

.

glEnd();

glPopMatrix(); /* restore state */This works if objects cannot cast shadows on other objects!

Page 78: 1 Chapter 5 Viewing. 2 OpenGL Perspective Matrix parallel perspective axonometric multiview orthographic oblique isometricdimetrictrimetric 2 point1 point3.

78

Summary and Notes Classical Viewing Parallel Projection versus Perspective

Projection OpenGL Projections Projection Normalization Shadows