1 / 30

The Projection Matrix

The Projection Matrix. Lecture 29 Mon, Nov 5, 2007. Model Trans. View Trans. Proj Trans. Object Coords. World Coords. Eye Coords. Clip Coords. M. V. P. Lighting Calculations. Clipping. Perspective Divide. Normal Dev Coords. Window Coords. Frame- buffer.

tallis
Télécharger la présentation

The Projection Matrix

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The Projection Matrix Lecture 29 Mon, Nov 5, 2007

  2. Model Trans View Trans Proj Trans Object Coords World Coords Eye Coords Clip Coords M V P Lighting Calculations Clipping Perspective Divide Normal Dev Coords Window Coords Frame- buffer Rasterization, Shading Hidden-surface Removal, Texture Application The Graphics Pipeline

  3. Homogeneous Coordinates • Points are stored in homogeneous coordinates (x, y, z, w). • The true 3D coordinates are (x/w, y/w, z/w). • Therefore, for example, the points (4, 3, 2, 1) and (8, 6, 4, 2) represent the same 3D point (4, 3, 2). • This fact will play a crucial role in the projection matrix.

  4. Coordinate Systems • Eye coordinates • The camera is at the origin, looking in the negative z-direction. • View frustrum (right – left, bottom – top, near – far). • Normalized device coordinates • -1  x  1 • -1  y  1 • -1  z  1

  5. The Transformation • Points in eye coordinates must be transformed into normalized device coordinates. • But first they are transformed to clipping coordinates.

  6. The Transformation • For example, • The point (r, t, -n, 1) is first transformed to the point (n, n, -n, n). • The point (l(f/n), b(f/n), -f, 1) is first transformed to the point (-f, -f, f, f).

  7. The Transformation • Later, OpenGL divides by the w-coordinate to get normalized device coordinates. • (n, n, -n, n)  (1, 1, -1) • (-f, -f, f, f)  (-1, -1, 1) • This is called the homogeneous divide, or perspective division. • It is a nonlinear transformation. • It occurs at a later stage in the pipeline.

  8. The Perspective Transformation – x, y • Points in eye coordinates are projected onto the near plane, sort of. • The x- and y-coordinates are projected onto the near plane. • The z-coordinated is scaled to the range [-n, f].

  9. near plane P(x, y, z) t -n -f b The Perspective Transformation – x, y • Consider the projection in the yz-plane.

  10. The Perspective Transformation – x, y • Consider the projection in the yz-plane. near plane P(x, y, z) t y -f -z b

  11. near plane P(x, y, z) t y -f n b The Perspective Transformation – x, y • Consider the projection in the yz-plane. y -z

  12. The Perspective Transformation – x, y • By similar triangles, y/n = y/(-z), • Therefore, • Similarly,

  13. The Perspective Transformation – x, y • Notice that these transformation are not linear. • That is, x and y are not linear combinations of x, y, and z. • Therefore, this transformation cannot be carried out by matrix multiplication. • We will perform the multiplication by n using a matrix, but dividing by -z, i.e., w, will have to be postponed.

  14. The Perspective Transformation – z • The z-coordinate is handled differently because we must not lose the depth information yet. • In the z-direction, we want to map the interval [-n, -f] to the interval [-n, f]. • Later, the perspective division will map [-n, f] into [-1, 1].

  15. The Perspective Transformation – z • Since this is a linear transformation, we will have z = az + b, for some a and b, to be determined. • We need • Therefore,

  16. The Perspective Transformation • That is, we will map (r, t, -n, 1)  (nr, nt, -n, n), (l(f/n), b(f/n), -f, 1)  (fl, fb, f, f), etc. which is a linear transformation. • These points are equivalent to (r, t, -1), (l, b, 1), etc.

  17. The Perspective Transformation • The perspective matrix is Represents division by –z (perspective division)

  18. The Perspective Transformation • This transforms this frustum… P(x, y, z) t -n -f b

  19. The Perspective Transformation • …into this frustum ft P(x, y, z) nt -n f nb fb

  20. The Perspective Transformation • Later, the perspective division will transform this into a cube. 1 P(x, y, z) 1 -1 -1

  21. The Perspective Transformation • Verify that P1 maps • (r, t, -n, 1)  (nr, nt, -n, n)  (r, t, -1) • (l, t, -n, 1)  (nl, nt, -n, n)  (l, t, -1) • (r, b, -n, 1)  (nr, nb, -n, n)  (r, b, -1) • (l, b, -n, 1)  (nl, nb, -n, n)  (l, b, -1) • (r(f/n), t(f/n), -f, 1)  (fr, ft, -f, f)  (r, t, -1) • (l(f/n), t(f/n), -f, 1)  (fl, ft, -f, f)  (l, t, -1) • (r(f/n), b(f/n), -f, 1)  (fr, fb, -f, f)  (r, b, -1) • (l(f/n), b(f/n), -f, 1)  (fl, fb, -f, f)  (l, b, -1)

  22. The Projection Transformation • The second part of the projection maps • (nr, nt, -n, n)  (n, n, -n, n)  (1, 1, -1) • (nl, nt, -n, n)  (-n, n, -n, n)  (-1, 1, -1) • (nr, nb, -n, n)  (n, -n, -n, n)  (1, -1, -1) • (nl, nb, -n, n)  (-n, -n, -n, n)  (-1, -1, -1) • (fr, ft, -f, f)  (f, f, f, f)  (1, 1, 1) • (fl, ft, -f, f)  (-f, f, f, f)  (-1, 1, 1) • (fr, fb, -f, f)  (f, -f, f, f)  (1, -1, 1) • (fl, fb, -f, f)  (-f, -f, f, f)  (-1, -1, 1)

  23. The Projection Transformation • The matrix of this transformation is

  24. The Projection Matrix • The product of the two transformations is the projection matrix.

  25. The Projection Matrix • The function glFrustum(l, r, b, t, n, f) creates this matrix and multiplies the projection matrix by it. glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(l, r, b, t, n, f);

  26. The Projection Matrix • The function gluPerspective(angle, ratio, near, far) also creates the projection matrix by calculating r, l, t, and b. glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(angle, ratio, n, f);

  27. The Projection Matrix • The formulas are • t = n tan(angle/2) • b = -t • r = t  ratio • l = -r

  28. Question • When choosing the near and far planes in the gluPerspective() call, why not let n be very small, say 0.000001, and let f be very large, say 1000000.0?

  29. Orthogonal Projections • The matrix for an orthogonal projection is much simpler. • All it does is rescale the x-, y-, and z-coordinates to [-1, 1]. • The positive direction of z is reversed. • It represents a linear transformation; the w-coordinate remains 1.

  30. Orthogonal Projections • The matrix of an orthogonal projection is

More Related