CS488 - Introduction to Computer Graphics - Lecture 9

Comments and Questions

Properties of the View Frustum Projection

z' -> (z*(zf + zn) -2*zf*zn ) / z*(zf - zn)

  1. z = zf: z' = 1
  2. z = zn: z' = -1
  3. z = (zf + zn) / 2. z'= (zf - zn) / (zf + zn)

    As zn -> 0 what happens?

  4. What maps to z' = 0? z = 2*zf*zn / (zf + zn ) = 2 / (1/zf + 1/zn)

    Note the possible numeric problems.

  5. z -> +0: z' = -2*zf*zn / \delta -> -infinity
  6. z -> -0: z' -> +infinity
  7. z -> infinity, z' = (zf + zn) / (zf - zn)

Polygons, Clipping



Clipping a polygon reduces to clipping edges against

The clipping algorithm takes an ordered set of vertices [vi] and produces an ordered set of vertices [wi]. It relies on the following

The algorithm is

for each edge of clipping region
   for each edge of polygon // must be in sequence
      clip edge against region
      switch (result of clip)
      case "all inside"
         output leading vertex of edge
      case "all outside"
         do nothing
      case "cross edge leaving region"
         output crossing point
      case "cross entering region"
         output crossing point
         output leading vertex of edge 

Exercise. Hand execute this algorithm on several cases to make sure that you understand exactly how it works.

Projecting a Polygon

Lines project to lines so projecting the vertices projects a polygon in 3D to a polygon on the view plane.


Sooner or later almost all polygons are converted to triangles

Scan Conversion

Scan converting a polygon (in 2D)

sort vertices in direction perpendicular to the scan lines
for each scan line
   if scan line contains the next vertex
      update and sort edge list
   inside = false
   for each pixel
      if on next edge
         inside = !inside
      if (inside)
         paint pixelt

Exercise. Expand "update and sort edge list" to make this a working algorithm.

Exercise. Hand execute your expanded algorithm on a triangle to make sure that you understand how it works.

Exercise. Hand execute your expanded algorithm on a non-convex polygon.

Hidden Surface Removal

Every polygon, in 3D, has two sides

It is very convenient to assume that surfaces are closed

Then we can say that every polygon has only a single side with visual properties

Backface Culling

Do not render any polygon with n.E < 0.

Does not handle occlusion, so we need to finish off with one of the following algorithms

Painter's Algorithm

Sort polygons back to front, then render backmost first.

Warnock's Algorithm

Divide and conquer

  1. Start with whole window
  2. Divide into four subwindows
  3. Keep dividing into subwindows until

    then paint the window

Warnock's algorithm is

Depth-Buffer Algorithm (also called zed-buffer)

Use a second frame buffer with depth values stored in it

  1. Initalize depth-buffer to far plane distance
  2. If a pixel has z less than the current depth buffer value

The depth buffer algorithm is

  1. easy to implement
  2. fast, O(n)
  3. no longer memory-intensive, though it used to be

Almost all graphics cards have hardware depth buffers.

Using the depth buffer may be hard the first time.

Mouse Interface


For assignment 3 you need to be able to rotate with the mouse

The virtual trackball

You need to modify the sample code.


For assignment 3 you need to be able to select graphical objects with the mouse

The simple principle

  1. Mouse gives (x, y).
  2. Render pixel at (x, y ) keeping track of the polygon it comes from.
  3. Associate polygon with object

For the assignment let GL do it for you.

See the notes.

Return to: