next up previous
Next: Why Map Z? Up: Projections and Projective Previous: Projections and Projective

Projections

Perspective Projection

Projective Transformations:

Cross Ratios
  • Cross ratio: , , , , then

    This can also be used to define a projective transformation (ie, that lines map to lines and cross ratios are preserved).

Comparison:

Perspective Map:
  • Given a point S, we want to find its projection P.

    \

  • Similar triangles: P=(xn/z, n)
  • In 3D,
  • Have identified all points on a line through the origin with a point in the projection plane.
  • Thus, .
  • These are known as homogeneous coordinates.
  • If we have solids or coloured lines,
    then we need to know ``which one is in front''.
  • This map loses all z information, so it is inadequate.

Pseudo-OpenGL version
of the perspective map:
  • Maps a near clipping plane z=n to z'= -1
  • Maps a far clipping plane z=f to z'=1

    \

  • The ``box'' in world space known as ``truncated viewing pyramid'' or ``frustum''
    • Project x, y as before
    • To simplify things, we will project into the z=1 plane.

Derivation:
  • Want to map x to x/z (and similarly for y).
  • Use a matrix multiply followed by a division (normalization):

  • Solve for a, b, c, and d such that maps to .
  • Know that we want to map x to x/z (assuming our projection plane is at z=1) so

    Thus,

  • Our constraints on the near and far clipping planes (e.g., that they map to -1 and 1) give us

    This gives us

  • After normalizing we get

  • Could use this formula instead of performing the matrix multiply followed by the division ...
  • If we multiply this matrix in with the geometric transforms,
    the only additional work is the divide.

Verification:

  • If z=n, then

  • If z=f, then

The OpenGL perspective matrix
uses
  • and b=-1.
    • OpenGL looks down z=-1 rather than z=1.
    • Note that when you specify n and f,
      they are given as positive distances down z=-1.
  • The upper left entries are very different.
    • OpenGL uses this one matrix to both project and map to NDC.
    • How do we set x or y to map to [-1,1]?
    • We don't want to do both because we may not have square windows.
    • Let's do y:

      \

    • Want to map distance d to 1.
    • is the current projection ...
    • gives us the scaling.
    • But we have placed our projection plane at z=1, so this is really

      where c=1.

    • But so

  • Finally, because the x-y aspect ratio may not be 1, we will scale x to give the desired ratio:

    where aspect of the viewport.

Our final matrix is

where the is 1 if we look down the z axis and -1 if we look down the -z axis.

OpenGL uses a slightly more general form of this matrix that allows skewed viewing pyramids.

Readings: Hearn and Baker: 12-3, Red book: Chapter 6, White book: Chapter 6, Blinn: Chapter 17, 18.


next up previous
Next: Why Map Z? Up: Projections and Projective Previous: Projections and Projective

CS488/688: Introduction to Interactive Computer Graphics
University of Waterloo
Computer Graphics Lab

cs488@cgl.uwaterloo.ca