Spring 2000

Department of Computer Science

Lab Assignment 4: A Gray Lumpy Donut

In this assignment, you will construct a program that renders objects that look solid. Your program will be able to render 3D objects as wire frames (as in the last assignment) or as solid objects rendered using flat, Gouraud, or Phong shading. The method of rendering will be selected by including commands wire, flat, gouraud, or phong in your view file. Hidden surfaces will be dealt with using the depth buffer algorithm. All shading will be done using a grayscale colormap, so single intensities will be calculated for each point, rather than red, green and blue intensities. (Help with debugging is included at the end of this assignment.)

To complete this assignment, combine your polygon-filling code with your wire frame drawing code and add the following capabilities:

To accomplish this, your program must perform the following steps:

  1. Process the scene data by parsing the vertex list and face list.
  2. Calculate outward-directed normal vectors for each face by averaging the normal vectors for each vertex of a face. Be sure your result is a unit-length vector.
  3. Process the view data to obtain:
  4. Calculate u, v, and n.
  5. Calculate M, the matrix that performs the entire 3-D to 2-D perspective transformation.
  6. Transform all vertices.
  7. Render the scene, depending on the specified render method:

    Input Files

    Make sure your program displays the lumpy donut correctly using this lab4.scene file and this lab4.view file. The format of the scene file is the same as the one used in the previous assignment, except for several additions. After the x, y, and z coordinates of a vertex are three more numbers. These are the x, y, and z coordinates of a unit-length normal vector for the vertex. So, the first few lines of the vertex list might be:
    550
    0.000000 0.000000 0.000000 0.000000 0.000000 1.000000
     2.500000 0.000000 0.000000 0.000000 0.000000 1.000000
     5.000000 0.000000 0.000000 0.000000 0.000000 1.000000
     7.500000 0.000000 0.000000 0.000000 0.000000 1.000000
    
    where 550 is the number of vertices. The face list also has some additions. After the indices into the vertex list for each vertex of the face, the material properties of the face are given as a diffuse coefficient and a specular coefficient and a specular exponent. Just to make this obvious, the file includes the words diffuse and specular before the correponding values. So, the first few lines of the face list (which comes after the entire vertex list), are something like
    455
    
    4
    0 1 6 5  diffuse 0.600000 specular 0.700000 50.000000
    
    4
    1 2 7 6  diffuse 0.500000 specular 0.500000 50.000000
    
    4
    2 3 8 7  diffuse 0.500000 specular 0.500000 50.000000
    
    where 455 is the number of faces and each face shown has four vertices and the diffuse reflection coefficient of the first face is 0.6, the specular reflection coefficient is 0.5, and the specular exponent is 50.

    You may need to redefine some constants in xparms.c so that the text widgets can hold more lines of text. I replaced the obvious line in xparms.c with this one:

    #define MAXLINES  5000
    
    The lab4.scene file contains 1918 lines (use the unix command wc to count the lines).

    Check In

    To check this assignment in, check in a tar file of all of the following files:

    We will grade your program by compiling it and running it with our donut data.

    Here is what your donut should look like.

    Debugging

    To help you debug your program, I ran my program with this short scene file consisting of just two faces. The second appears in front of the other using the lab4.view file. After inserting tons of print statements, I get the this text file of output. I hope this helps.