Projections and Hidden Surface Removal Angel 5.4-5.6 1

advertisement

Projections and Hidden

Surface Removal

Angel 5.4-5.6

Angel: Interactive Computer Graphics5E © Addison-Wesley 2009 1

Objectives

• To discuss projection matrices to achieve desired perspective

• Discuss OpenGL API to achieve desired perspectives

• Explore hidden surface removal APIs in

OpenGL

Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 2

Projections and Normalization

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

• For points within the default view volume x p y p

= x

= y z p

= 0

• 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

Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 3

Homogeneous Coordinate Representation default orthographic projection x p y p

= x

= y z p w p

= 0

= 1

M =

1

 0

0

 0 p p

= Mp

0

1

0

0

0

0

0

0

0

0

0

1

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

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

Camera Setups

Angel: Interactive Computer Graphics5E © Addison-Wesley 2009 5

Simple Perspective

• Center of projection at the origin

• Projection plane z = d , d < 0

Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 6

Perspective Equations

• Consider top and side views x p

= x z / d y p

= y z / d z p

= d

Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 7

Perspective Transformation

• Projection process

– Division by z

– Non-uniform foreshortening

• Farther from COP are smaller

• Closer to COP are larger

• Transform (x,y,z) to (x p

, y p

, z p

)

– Irreversible

– All points along projector results to same point

Angel: Interactive Computer Graphics5E © Addison-Wesley 2009 8

Homogeneous Coordinates

• If w != 0 p

 x z y

1

 wx wy wz w

Angel: Interactive Computer Graphics5E © Addison-Wesley 2009 9

Homogeneous Coordinate Form consider q = Mp where M =

1

0

0

0

0

1

0

0 1 /

0

0

1 d

0

0

0

0

 p =

 x z y

1

 q =

 z / x y z d

Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 10

Perspective Division

• However w

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

• This perspective division yields x p

= x z / d y p

= y z / d z p

= d the desired perspective equations

• We will consider the corresponding clipping volume with the OpenGL functions

Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 11

Perspective Division (cont) q

 x p z y

1 p p

  z z x y d

1 d d

 

Angel: Interactive Computer Graphics5E © Addison-Wesley 2009 12

Orthogonal Projection

 x p y z

1 p p

1

0

0

0

0

1

0

0

0

0

0

0

0

1

0

0

 x y z

1

Angel: Interactive Computer Graphics5E © Addison-Wesley 2009 13

OpenGL Orthogonal Viewing glOrtho(left,right,bottom,top,near,far) near and far measured from camera

Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 14

OpenGL Perspective glFrustum(left,right,bottom,top,near,far)

Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 15

Using Field of View

• With glFrustum it is often difficult to get the desired view

• gluPerpective(fovy, aspect, near, far) often provides a better interface front plane aspect = w/h

Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 16

Download