Assignment #3 -- Hidden Surfaces

Due Date

This assignment is due at 11:59pm on Monday, March 8th. Projects turned in late will lose points as described in the policies handout. This assignment should be done alone or in pairs. You may share ideas with other groups, but you may not share code.


You may submit on either Unix or Windows. The platform you submit on will be the one used to grade assignments.

Do not touch any file after the submission date. Readers will check the file time stamps. Regardless of which platform you used for the assignment, you should have an as3 directory in both of your Unix and Windows accounts. You should put a README file into both of these directories that at the minimum contains the following data:

You should also e-mail your README file to On the subject line you should specify your account names and the assignment number (e.g: cs184-aa, cs184-ab: as3).

All files needed to compile your code should appear in the Windows or Unix directory of the user indicated in your README file. It is your responsibility to make sure that they will compile and run properly. You will also need to set the permissions properly.

Windows: The grader should be able to recompile your program by simply opening the project and rebuilding it from scratch.

Unix: Remember that the grader should be able to recompile your program simply by typing make.

The TAs have provided sample code for you to start with. If you chose to use that code, you are responsible for figuring out how to use properly. If you have questions, post them to the news group or ask the TAs during their office hours.

Do not wait until the last minute to start this assignment. BSP trees can be tricky. If you don't give yourself enough time, you will be most unhappy.


For this assignment you will use both BSP trees and OpenGL's Z-Buffer to implement hidden surface removal. Your program will be given a filename on the command line. It will do the following:
  1. Read a camera description and list of triangles and colors from the files.
  2. Build a BSP Tree that contains the triangles.
  3. Use the BSP Tree to display the triangles in back to front order (with the Z-Buffer TURNED OFF) and print "BSP Tree" to stdout.
  4. Wait for the user to press ENTER.
  5. Redisplay the scene by drawing the polygons in the input order using the OpenGL Z Buffer feature and print "Z Buffer" to stdout.
  6. Wait for the user to press ENTER.
  7. Exit.
Notes: Grave Warning: It will be considered cheating to use Z Buffering, or anything else besides your own BSP Tree code, to render the scene and then print "BSP Tree". In other words, the rendering method should be what you program claims it is. Cheating on an assignment will earn a zero for the assignment and possibly subject you to disciplinary action.

File Format

The first part of the file contains the camera information. The second part contains a list of polygons. For this assignment, you can assume all polygons are triangles.

The camera format is a line with the x,y,z location of the "eye", with the x,y,z location of the "reference point", a line with the x,y,z direction of the "up vector", a line with a scalar for the "field of view" in degrees, line with a scalar for the "aspect ratio", and a line with two scalars for the "near" and "far" clipping planes. See the man pages for gluLookAt and gluPerspective.

For the polygon part, the first line will contain an integer, designating the number of polygons the scene contains. The subsequent lines will have an integer, which is the number of vertices a polygon contains and an RGB color triple, followed by x,y,z triples on each line for all the vertices in order, repeated for each polygon. For example, we can represent a scene containing 2 polygons (one red and one blue) by:

0.0 0.0 0.0
0.0 0.0 1.0
0.0 1.0 0.0
0.1 1.0
3 255 0 0
0.1 0.1 0.2
0.2 0.2 0.3
0.3 0.1 0.2
3 0 0 255
0.5 0.1 0.4
0.6 0.9 0.5
0.2 0.5 0.4

Location of the eye
Location of reference point
Up Vector
Field of view
Aspect ratio
Near and Far clipping planes
Number of triangles
First triangle and its color
Vertex 1 of first triangle
Vertex 2 of first triangle
Vertex 3 of first triangle
Second triangle and its color
Vertex 1 of second triangle
Vertex 2 of second triangle
Vertex 3 of second triangle

RGB triples are three integers values between 0 and 255 (inclusive).
Bold comments are not part of the file.

Questions should be posted to the news group or to