22
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Projection Matrices Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

Projection Matrices - University of New Mexicoangel/CS433/LECTURES/CS433_17.pdf · •Derive the projection matrices used for standard OpenGL projections •Introduce oblique projections

  • Upload
    vutu

  • View
    222

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Projection Matrices - University of New Mexicoangel/CS433/LECTURES/CS433_17.pdf · •Derive the projection matrices used for standard OpenGL projections •Introduce oblique projections

1Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005

Projection Matrices

Ed AngelProfessor of Computer Science,

Electrical and ComputerEngineering, and Media Arts

University of New Mexico

Page 2: Projection Matrices - University of New Mexicoangel/CS433/LECTURES/CS433_17.pdf · •Derive the projection matrices used for standard OpenGL projections •Introduce oblique projections

2Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005

Objectives

•Derive the projection matrices used forstandard OpenGL projections

• Introduce oblique projections• Introduce projection normalization

Page 3: Projection Matrices - University of New Mexicoangel/CS433/LECTURES/CS433_17.pdf · •Derive the projection matrices used for standard OpenGL projections •Introduce oblique projections

3Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005

Normalization

•Rather than derive a different projectionmatrix for each type of projection, we canconvert all projections to orthogonalprojections with the default view volume

•This strategy allows us to use standardtransformations in the pipeline and makesfor efficient clipping

Page 4: Projection Matrices - University of New Mexicoangel/CS433/LECTURES/CS433_17.pdf · •Derive the projection matrices used for standard OpenGL projections •Introduce oblique projections

4Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005

Pipeline View

modelviewtransformation

projectiontransformation

perspective division

clipping projection

nonsingular4D → 3D

against default cube3D → 2D

Hidden surface removal

Page 5: Projection Matrices - University of New Mexicoangel/CS433/LECTURES/CS433_17.pdf · •Derive the projection matrices used for standard OpenGL projections •Introduce oblique projections

5Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005

Notes

•We stay in four-dimensional homogeneouscoordinates through both the modelview andprojection transformations

- Both these transformations are nonsingular- Default to identity matrices (orthogonal view)

•Normalization lets us clip against simplecube regardless of type of projection

•Delay final projection until end- Important for hidden-surface removal to retain

depth information as long as possible

Page 6: Projection Matrices - University of New Mexicoangel/CS433/LECTURES/CS433_17.pdf · •Derive the projection matrices used for standard OpenGL projections •Introduce oblique projections

6Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005

Orthogonal Normalization

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

normalization ⇒ find transformation to convertspecified clipping volume to default

Page 7: Projection Matrices - University of New Mexicoangel/CS433/LECTURES/CS433_17.pdf · •Derive the projection matrices used for standard OpenGL projections •Introduce oblique projections

7Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005

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 8: Projection Matrices - University of New Mexicoangel/CS433/LECTURES/CS433_17.pdf · •Derive the projection matrices used for standard OpenGL projections •Introduce oblique projections

8Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005

Final Projection

• Set z =0• Equivalent to the homogeneous coordinatetransformation

• Hence, general orthogonal projection in 4D is

!!!!

"

#

$$$$

%

&

1000

0000

0010

0001

Morth =

P = MorthST

Page 9: Projection Matrices - University of New Mexicoangel/CS433/LECTURES/CS433_17.pdf · •Derive the projection matrices used for standard OpenGL projections •Introduce oblique projections

9Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005

Oblique Projections

•The OpenGL projection functions cannotproduce general parallel projections such as

•However if we look at the example of thecube it appears that the cube has beensheared

•Oblique Projection = Shear + OrthogonalProjection

Page 10: Projection Matrices - University of New Mexicoangel/CS433/LECTURES/CS433_17.pdf · •Derive the projection matrices used for standard OpenGL projections •Introduce oblique projections

10Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005

General Shear

top viewside view

Page 11: Projection Matrices - University of New Mexicoangel/CS433/LECTURES/CS433_17.pdf · •Derive the projection matrices used for standard OpenGL projections •Introduce oblique projections

11Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005

Shear Matrix

xy shear (z values unchanged)

Projection matrix

General case:!

1 0 "cot# 0

0 1 "cot$ 0

0 0 1 0

0 0 0 1

%

&

' ' ' '

(

)

* * * *

H(θ,φ) =

P = Morth H(θ,φ)

P = Morth STH(θ,φ)

Page 12: Projection Matrices - University of New Mexicoangel/CS433/LECTURES/CS433_17.pdf · •Derive the projection matrices used for standard OpenGL projections •Introduce oblique projections

12Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005

Equivalency

Page 13: Projection Matrices - University of New Mexicoangel/CS433/LECTURES/CS433_17.pdf · •Derive the projection matrices used for standard OpenGL projections •Introduce oblique projections

13Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005

Effect on Clipping

•The projection matrix P = STH transformsthe original clipping volume to the defaultclipping volume

top view

DOP DOP

near plane

far plane

object

clippingvolume

z = -1

z = 1

x = -1x = 1

distorted object(projects correctly)

Page 14: Projection Matrices - University of New Mexicoangel/CS433/LECTURES/CS433_17.pdf · •Derive the projection matrices used for standard OpenGL projections •Introduce oblique projections

14Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005

Simple Perspective

Consider a simple perspective with the COP at theorigin, the near clipping plane at z = -1, and a 90degree field of view determined by the planes

x = ±z, y = ±z

Page 15: Projection Matrices - University of New Mexicoangel/CS433/LECTURES/CS433_17.pdf · •Derive the projection matrices used for standard OpenGL projections •Introduce oblique projections

15Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005

Perspective Matrices

Simple projection matrix in homogeneouscoordinates

Note that this matrix is independent of thefar clipping plane!

1 0 0 0

0 1 0 0

0 0 1 0

0 0 "1 0

#

$

% % % %

&

'

( ( ( (

M =

Page 16: Projection Matrices - University of New Mexicoangel/CS433/LECTURES/CS433_17.pdf · •Derive the projection matrices used for standard OpenGL projections •Introduce oblique projections

16Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005

Generalization

!

1 0 0 0

0 1 0 0

0 0 " #

0 0 $1 0

%

&

' ' ' '

(

)

* * * *

N =

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

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

which projects orthogonally to the desired point regardless of α and β

Page 17: Projection Matrices - University of New Mexicoangel/CS433/LECTURES/CS433_17.pdf · •Derive the projection matrices used for standard OpenGL projections •Introduce oblique projections

17Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005

Picking α and β

If we pick

α =

β =

nearfar

farnear

!

+

farnear

farnear2

!

"

the near plane is mapped to z = -1the far 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 18: Projection Matrices - University of New Mexicoangel/CS433/LECTURES/CS433_17.pdf · •Derive the projection matrices used for standard OpenGL projections •Introduce oblique projections

18Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005

NormalizationTransformation

original clipping volume original object new clipping

volume

distorted objectprojects correctly

Page 19: Projection Matrices - University of New Mexicoangel/CS433/LECTURES/CS433_17.pdf · •Derive the projection matrices used for standard OpenGL projections •Introduce oblique projections

19Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005

Normalization andHidden-Surface Removal

• Although our selection of the form of theperspective matrices may appear somewhatarbitrary, it was chosen so that if z1 > z2 in theoriginal clipping volume then the for thetransformed points z1’ > z2’

• Thus hidden surface removal works if we firstapply the normalization transformation

• However, the formula z’’ = -(α+β/z) implies that thedistances are distorted by the normalizationwhich can cause numerical problems especially ifthe near distance is small

Page 20: Projection Matrices - University of New Mexicoangel/CS433/LECTURES/CS433_17.pdf · •Derive the projection matrices used for standard OpenGL projections •Introduce oblique projections

20Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005

OpenGL Perspective

•glFrustum allows for an unsymmetricviewing frustum (although gluPerspectivedoes not)

Page 21: Projection Matrices - University of New Mexicoangel/CS433/LECTURES/CS433_17.pdf · •Derive the projection matrices used for standard OpenGL projections •Introduce oblique projections

21Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005

OpenGL Perspective Matrix

•The normalization in glFrustum requiresan initial shear to form a right viewingpyramid, followed by a scaling to get thenormalized perspective volume. Finally,the perspective matrix results in needingonly a final orthogonal transformation

P = NSH

our previously defined perspective matrix

shear and scale

Page 22: Projection Matrices - University of New Mexicoangel/CS433/LECTURES/CS433_17.pdf · •Derive the projection matrices used for standard OpenGL projections •Introduce oblique projections

22Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005

Why do we do it this way?

•Normalization allows for a single pipelinefor both perspective and orthogonalviewing

•We stay in four dimensionalhomogeneous coordinates as long aspossible to retain three-dimensionalinformation needed for hidden-surfaceremoval and shading

•We simplify clipping