Presentation is loading. Please wait.

Presentation is loading. Please wait.

Projection Matrices CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.

Similar presentations


Presentation on theme: "Projection Matrices CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel."— Presentation transcript:

1 Projection Matrices CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel

2 Objectives Derive the projection matrices used for standard OpenGL projections. Introduce oblique projections. Introduce projection normalization. CS4395: Computer Graphics 2

3 Projection Normalization Convert all projections to orthogonal projections with the default view volume. The same pipeline of operations for all types of projections Clip against simple cube regardless of type of projection. Simplifies clipping because sides of the object are aligned with coordinate axes. Delay final projection until end: important for hidden-surface removal. CS4395: Computer Graphics 3

4 Projection Normalization Work in 4D using homogeneous coordinates. Convert all projections into orthogonal projections: – Distort objects such that the orthogonal projection of distorted objects is the same as desired projection of original objects. Concatenation of normalization matrix (for distortion) and orthogonal projection matrix yields desired homogeneous coordinate matrix. CS4395: Computer Graphics 4

5 Pictorial Representation CS4395: Computer Graphics 5

6 Pipeline View CS4395: Computer Graphics 6 modelview transformation projection transformation perspective division clippingprojection nonsingular 4D  3D against default cube 3D  2D Stay in 4D coordinates for both the modelview and projection transformations (nonsingular transformations).

7 Orthogonal Normalization glOrtho(left,right,bottom,top,near,far) CS4395: Computer Graphics 7 Normalization  find transformation to convert specified clipping volume to default.

8 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/(right-left), 2/(top-bottom), 2/(near-far)) CS4395: Computer Graphics 8 P = ST =

9 Final Projection Set z =0 Equivalent to the homogeneous coordinate transformation: General orthogonal projection in 4D: CS4395: Computer Graphics 9 M orth = P = M orth ST

10 Oblique Projections The OpenGL projection functions cannot produce general parallel projections such as: However the cube it appears to have been sheared. Oblique Projection = Shear + Orthogonal Projection! CS4395: Computer Graphics 10

11 General Shear side view CS4395: Computer Graphics 11 top view

12 Shear Matrix For x-y shear ( z values unchanged): Projection matrix: General case: See Section 5.8. CS4395: Computer Graphics 12 H( ,  ) = P = M orth H( ,  ) P = M orth STH( ,  )

13 Equivalency CS4395: Computer Graphics 13

14 Effect on Clipping Projection matrix P = STH transforms the original clipping volume to the default clipping volume. CS4395: Computer Graphics 14 top view DOP near plane far plane object clipping volume z = -1 z = 1 x = -1 x = 1 distorted object (projects correctly)

15 Simple Perspective Consider a simple perspective : COP at origin, the near clipping plane at z = -1, and a 90 o field of view determined by planes: x =  z, y =  z. CS4395: Computer Graphics 15

16 Perspective Matrices Simple projection matrix in homogeneous coordinates: This matrix is independent of the far clipping plane. CS4395: Computer Graphics 16 M =

17 Generalization (Section 5.9) N = CS4395: Computer Graphics 17 Perspective normalization matrix: After perspective division, the point (x, y, z, 1) goes to: Orthogonal projection to the desired point regardless of and.

18 Picking  and  CS4395: Computer Graphics 18  =  = If we pick: The near plane is mapped to z = -1 The far plane is mapped to z =1 The sides are mapped to x =  1, y =  1 The new clipping volume is the default volume.

19 Normalization Transformation CS4395: Computer Graphics 19 original object new clipping volume distorted object projects correctly original clipping volume

20 Normalization and Hidden-Surface Removal The perspective projection matrices are chosen such that if z 1 > z 2 in the original clipping volume then for the transformed points: z 1 ’ > z 2 ’ Thus hidden surface removal works if the normalization transformation is applied first. However, the formula z’’ = -(  +  /z) implies that the distances are distorted by the normalization which can cause numerical problems if the near distance is small. CS4395: Computer Graphics 20

21 OpenGL Perspective Function glFrustum allows for an un-symmetric viewing frustum (although gluPerspective does not). CS4395: Computer Graphics 21

22 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 needs only a orthogonal transformation: See Section 5.9.2. CS4395: Computer Graphics 22 P = NSH previously defined perspective matrix shear and scale N =

23 Recap: Why do we do it this way? Normalization allows for a single pipeline for both perspective and orthogonal viewing. Stay in 4D homogeneous coordinates as long as possible to retain three-dimensional information needed for hidden-surface removal and shading. Simplifies clipping. CS4395: Computer Graphics 23


Download ppt "Projection Matrices CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel."

Similar presentations


Ads by Google