Computer Science 155: Graphics
Spring 1998
Homework 4

The early due date is Saturday, February 21 before midnight.
The regular due date is Sunday, February 22 before midnight.
The late due date is Monday, February 23 before midnight.


This assignment has two parts. In the first part (worth 25% of the assignment) you will be playing with perspective viewing and gluLookAt in OpenGL. In the second part of the assignment (worth 75% of the assignment) you will be adding perspective viewing (assuming a slightly simplified fixed 90 degree field of view), z-buffering, and arbitrary camera position to your 3D mgl implementation from Homework 3.

  1. [25 Points] In this part of the assignment you will write an interactive 3D program in OpenGL. You can do anything you like as long as you use the following OpenGL features:
    1. Use a few simple 3D objects (such as planes, tetrahedra, and cubes) in which each face has a different color. (Alternatively, you can read ahead about lighting and use lit surfaces. Lighting is highly optional and is not worth extra credit nor chocolate.)
    2. Use perspective viewing.
    3. Use mouse and/or keyboard input to vary the eye position and to rotate the up vector, allowing you to interactively view the scene from various positions.
    Submit this as hw4a.cc and include a file called README which explains your user interface.

  2. [75 Points] In this part of the assignment you should add the following functions to your implementation of mgl:
    1. mglFrustum(float far)
      The frustum will be assumed to have a near clipping plane at z= -1 with x-coordinates from -1 to 1 and y-coordinates from -1 to 1. Thus, you need only specify the distance to the far clip plane. As in OpenGL, this should be a positive floating point number. In this case, it should be greater than 1. (For bonus credit and a large chunk of chocolate, implement the full-blown OpenGL mglFrustum. It's not too hard, it just requires a few extra transformations.)
    2. mglLookAt(float eye_x, float eye_y, float eye_z, float center_x, float center_y, float center_z, float up_x, float up_y, float up_z)
      This function establishes the look-at values, constructs the necessary viewing matrix, and multiplies it on the right side of the current modelview matrix. (Use the "Ferrari" method described in class to construct the viewing matrix.)
    3. mglEnd()
      Modify this function so that it uses either the orthographic projection or the perspective projection, depending on whether mglOrtho or mglFrustum was used. Also, make sure to implement the z-buffering algorithm for hidden surface removal.

    Submit this as hw4b.cc.