BU CLA CS 480: Introduction to Computer Graphics

Spring 1995

Programming Assignment 3---due Friday, April 7


For this programming assignment, you will put into practice many of the concepts about the 3-D viewing pipeling we discussed in class. You develop routines that perform 3-D viewing transformations, perspective viewing, and 3-D clipping. As in previous assignments, you will write a few subroutines in C, and then link them with some other routines and a main program that are provided. The resulting program will be a stereo viewing program that allows you to display and rotate 3-D polygonal objects (in wireframe).

You will receive a special pair of red/blue anaglyphic glasses for viewing this stereo display. Briefly, for the chromatic anaglyphic stereo technique, we generate two perspective images, each in a different color: one for the left eye and one for the right eye. When viewed through corresponding colored filters the left eye sees only the left image and the right eye only the right image. The eye-brain system then combines both two-dimensional images into a single three-dimensional image with the correct colors. The general phenomenon of stereo is known as a binocular cue, because you need to use both eyes to perceive depth from stereo.

Copy Some Files

Some basic graphics utilities and the animation tool's main program are provided for you. So, before you begin programming, you will need to copy seven files from the directory /usr3/faculty/sclaroff/program3 on the CGL cluster. These are:

Like the previous assignments, you are expected to complete the program by providing the missing subroutines using the code templates.

Run the Example Camera Tool

In the same directory, you will also find an example of a fully functioning animation program: camera_example . You may run this to see how your program should work. To run the program, type

camera_example filename.asc,

where you specify an ASCII polygon file as input. There are two polygon files provided: box.asc and vw.asc . These are OSU (Ohio State U) format files, which define 3-D polygons in terms of a list of vertices and a connectivity table.

The user interface to the camera tool is through a seperate user interface window. This window has sliders, dials, and buttons. The sliders control parameters for: distance between the eyes (for stereo viewing), the distance of the projection reference point (PRP) to the view plane, and the z clipping planes. There is a special slider for controlling the brightness of the stereo display's red channel. Beside each slider there is a small button that you can push to reset it's value to the default values.

There are also four main buttons on this menu:

The Code You Write

Write a routine that constructs the 4x4 homogeneous transform for rotation about a center point. The rotations should be applied in order: x rotation first, y rotation second, and z rotation third. Note that a 4x4 matrix multiplication has been provided if you wish to use it for the assignment.

  1. Write a routine that computes the 4x4 perspective projection matrix, by first computing 4 intermediate matrices: These matrices are then multiplied together to obtain the final, view-normalized perspective projection matrix Nper. Your code should use 4x4 matrix multiplications for this task.

  2. Write a 3-D line clipping routine based on the parametric line clipper that you wrote for the second programming assignment. Before upgrading to 3-D, please be sure to fix any bugs you had in your 2-D line clipper. This new version of the clipper should take advantage of the fact that all the clip planes are perpendicular to either the x,y, or z axis.
There are comments in the three template files that will help guide you in writing your own subroutines.

Test Cases

There are no test cases provided in this assignment. You should instead make sure that you final program can correctly clip, transform, and perspective display the polygons.

Grading

Demo

As in the previous assignment, part of your grade for this programming assignment will be based on your giving a 4 minute demo in the CGL cluster. You will be expected to talk about how your animation tool works, and we will test it on a few examples. Demos will be scheduled for Friday, Apr. 7, from 1:00 to 5:00. You will be asked to sign up for a slot by next Wednesday.

Write-up

You will also be graded on a very brief write-up that is to be turned in at the beginning of class on Friday, Apr. 7. Basically, this write-up should include a paragraph describing what design choices you made in writing your subroutines, and hard copy of all your code. The code should be commented so that it is easily understood.

Extra Credit

For extra credit, create your camera trajectory, and ``fly by'' for the object of your choice. There is a menu button and call back routine template flyCB provided. During the fly-by, the camera motion should be smooth and remain pointed at the center of the polygonal object.

Academic Policy

You may discuss the programming projects with your classmates; however, you must write and debug your own code. Academic dishonesty will be reported to the academic conduct committee.

Furthermore, copying or translating code from another source is not allowed. Copying anything without acknowledging the source is usually considered to be plagurism.

Start programming early. Late assignments will not be graded.

Utilities provided

The file draw.c contains utilities for opening and managing windows:

  • open_window opens a window and initializes the device event handling
  • close_window closes a window

    There are clipping frame management routines:

  • create_frame allocates a clipping frame data structure
  • free_frame frees a frame

    There are also routines for drawing:

  • redraw redraws both the frame and the polyline to the window
  • draw_line draws a line using GL
  • draw_frame draws a clipping frame

    The file menu.c contains routines that manage the user interface widgets. You don't need to look at these unless you want to.

    The file polygons.c contains utilities for creating and managing polygonal objects:

  • read_osu_polygons reads an OSU format polygon file
  • create_polygon_object creates a 3-D polygonal object
  • free_polygon_object frees a polygonal object
  • points_minmax finds the axis-aligned min/max for an array of points

    Finally, camera.c also contains some routines that are called whenever the user moves something on the user interface menu. These routines are called ``call back'' routines, because the user interface calls back to them when an interaction event occurs. These routines are:

  • quitCB frees up memory, closes window, and then quits
  • resetCB resets the sliders and dials to default values
  • stereoCB toggles between monocular and stereo viewing mode
  • flyCB starts the ``fly by'' extra credit routine
  • setup_sliders initializes the sliders and dials to default values
  • reset_slidersCB resets the sliders and dials to default values
  • resetsliderCB resets a particular slider
  • sliderCB updates appropriate variable when a slider moves
  • rotationCB updates rotation angles if a dial moves

    You will notice that there are some global variables declared in {\em camera.c}. These are needed to support the user interface's call-back routine structure.


    Stan Sclaroff
    Created: March 22, 1995