CSCI 384 Computer Graphics

    College of the Holy Cross, Fall 2003

    Home | | Syllabus | | Assignments | | Documentation

    Assignment 6

    Due: Thursday, November 6, in class


    Problem 1: A shaded pyramid
    In this problem, you will develop shading for the 3D pyramid that was developed in class. Copy the threeDpyramid.c code given here. You will modify this program so that you will be able to view a shaded pyramid.

    Part a. Add Flat shading to the pyramid.
    Save the threeDPyramid.c file as username_flatShading.c. In this part of the program you will add code to the program to shade the faces of the pyramid with flat shading. First, add code to the myinit() function to set the lighting at material parameters. Set up a single light source, to be in the direction (1.0, 2.0, 4.0, 0.0) from the origin. The source should emit white light for all three types of parameters: ambient, diffuse and specular. Next, set up the surface properties of the pyramid so that it reflects purple (equal amounts of red and blue light). It should reflect similar amounts of specular, diffuse and ambient light (I used 0.3 for both the red and blue values for these, but you are welcome to play with them to come up with something that looks nice). Use the functions glLightfv(...) to setup the lighting properties and glMaterialfv(...) to set up the material properties. Use glEnable(GL_FLAT) and glShadeModel(GL_FLAT) for this lighting model.

    Now you need to calculate a normal vector for each of the surfaces of the pyramid. You can calculate the normal by taking the cross product of the two vectors defined by 3 of the vertices, as discussed in class. An example of code to compute a cross product from 3 points is given in the lecture slides for lecture 20. Make sure you compute the normals so that they point outward from the surface of the pyramid. Also, you must normalize the normal vectors so that they have a length of 1.0. You will need to calculate 5 normals, one for each face. In your display function, call glNormal3fv(...) before you draw each face of the pyramid, giving the appropriate normal for that face as the parameter. You should also remove the calls to glColor3f() for drawing the pyramid (the color is taken care of by the material properties). When you are done, you should have a spinning, flat-shaded purple pyramid. You should notice some rather abrupt changes in shading between faces for some of the positions of the object. Experiment with rotating around the X, Y and Z axes to see how the shading behaves as the object rotates.

    Save your code in the file username_flatShading.c. You will email a copy of the file to me and turn in a hard-copy in class.

    Part b. Add Smooth shading to the pyramid.
    Save your code from part a in a file named username_smoothShading.c. In this part of the problem, you will use Gouraud shading to get a smoother shading of the pyramid. First change the glEnable() function to say glEnable(GL_SMOOTH) and change the glShadeModel() to be glShadeModel(GL_SMOOTH). Change the specular and diffuse material properties to emit only blue light. Increase the amount of diffuse light reflected to 1.0 (for blue). Keep the ambient light reflecting a low level (.2) of blue and red. Add a shininess level of 200.0.

    Now you will need to compute the normal for each vertex in the pyramid. The normal is computed as the average of all the normals for the faces that meet at that vertex. This will be an average of 3 normals for the bottom vertices, and 4 normals for the top vertex. This is best done by writing a function (or two) to compute the average of 3 (or 4) vectors. The average normal must be normalized to length 1.0. Once you have computed the normals, you should change the drawing code by calling glNormal3fv(...) with the appropriate normal before each call to glVertex3fv(...). When you are done you will get a somewhat smoother shaded smooth pyramid that looks slightly shiny. Experiment with rotating about the X, Y and Z axes to see how it looks (I think rotation about the X axis looks the best for these parameters, but you may disagree).

    Save your code in username_smoothShading.c. You will email a copy of the file to me and turn in a hard-copy in class.


    Problem 2: Computing Intensity with the Phong reflection model.
    In this problem you will get some practice computing the intensity of light reflected from a surface using the Phong reflection model. Consider the following three points:

    P0 = (1.0, 2.0, 3.0, 1.0)

    P1 = (-5.0, 4.0, 6.0, 1.0)

    P2 = (-3.0, 3.0, 6.0, 1.0)

    Part a.
    Compute the normal to the triangular surface defined by these points. The normal should be defined so that it points in the direction determined by the right-hand rule when one traverses the points in the order: P0, P1, P2. (In other words, if you move the fingers of your right hand from P0 to P1 to P2, the thumb will point in the direction of the normal). Make sure to normalize the length to 1.0. Show your work.

    Part b.
    Given the following light source vector: (0.0, 1.0, 0.0, 0.0), compute the reflection vector for this surface. Use the formula given in class:
    r = 2(l . n)n - l
    (where l . n is the dot product between l and n). Check your answer by verifying that the length of r is 1.0.

    Part c., Suppose the direction of the viewer is given by: v = (0.0, 0.0, 1.0, 0.0). If the diffuse, specular and ambient constants for both the light source and the material are all set to 1.0, and there is no attenuation, and the shininess coefficient, alpha is set to 1.0, what is the Intensity reflected from that surface according to the Phong Reflection model? Calculate the Intensity for the following values of alpha: 1.0, 5.0, 10.0. Show your work.


    Problem 3: Write up a project description

    Read the Project Description. Decide what you want to do for your project and write a 1 paragraph description of it. Make sure to be explicit about which parts of the project contain the required elements. Turn in a print-out of this description on November 6, in class.

    Turning in this assignment

    Turn in a hardcopy of the C code for problem 1 parts a and b and the calculations and answers to problem 2 and the paragraph description of your project. This is due in class, Thursday, November 6.

    In addition, email a copy of the files containing your C code to me at croyden@mathcs.holycross.edu. The subject line should read "Graphics Assignment 6". There should be 2 files named "username_flatShading.c", and "username_smoothShading.c". This should be done before class on the due date.


    Home | | Syllabus | | Assignments | | Documentation


    Constance Royden--croyden@mathcs.holycross.edu
    Computer Science 384
    Date Created: August 17, 1999
    Last Modified: October 24, 2003
    Page Expires: August 17, 2004