Math 217A - Spring 2002 - Assignment #4
due Wednesday, May 1

Goals: Upgrade your torus from the previous assignment to include lights and material properties.   This should help you (a) learn how to use the Phong lighting model, and (b) possibly appreciate the dangers of using floating point numbers.

Tasks:

  1. Download the PC executable program LightTorus.exe.    Try running it, and observe what it does.  (You will need to press "p" to enter polygon mode to see anything interesting.).  Your assignment is to rewrite this program or something very similar.  Your program should support the following keystroke commands: (in addition to the ones already available in WrapTorus).
    1. Press "1" to toggle the first light off and on.
    2. Press "2" to toggle the second light off and on.
    3. Press "l" to toggle local modes on and off (local viewer and positional light; or non-local viewer and directional light).
    4. Press "f" to toggle between flat shading (GL_FLAT) and smooth shading (GL_SMOOTH).
  2. Your torus should be lit so that specular highlights are visible, and the effects of diffuse lighting are visible.  You should be able point out where specular light is seen and where the effects of diffuse light are seen.  You also should be able to point out where purely ambient illumination is seen.
  3. You should be to explain why the local and non-local modes differ in the way they do.
  4. You should be able to explain artifacts from the Phong lighting, these will be particularly noticable when the torus is spinning.
  5. The positions of the lights should be indicated by emissive shapes.
  6. To get started, make a copy of your WrapTorus course files (or of mine, if you prefer), save them in a new directory, and rename them to LightTorus.    Also, (if using a PC), start a new Visual C++ project. 

Hints/Suggestions:  (if you have difficulties, let us know, and I might post more hints to help your fellow students!)

  1. There is a handout available for help with starting a new project in Visual C++.
  2. You may base your program in either your own WrapTorus (preferred, if you are happy with your WrapTorus version) or on mine (also acceptable).  My own solution for the WrapTorus assignment is available online starting Friday at the latest, from the textbook download site. (Ask me if you want an individual copy sooner.)
  3. The SimpleLight program, also available from the textbook download site can give you an example of how to add lights and material properties.
  4. You do not need to make the keyboard controls in your program work exactly like the keyboard controls for LightTorus.exe.  If you prefer to try different functionality, that is OK.  Important:  it should be possible to make the rotation rates slow down and speed up in small-ish increments, so we can get a good look at the specular highlights.
  5. You should use integer values to drive the computations whenever possible.  For example, when keeping track of the current "wrap number" or current segment in a wrap, you should use integer values.  Also, see the section in the textbook draft about the perils of floating point roundoff errors (at the end of chapter 2).

Homework turn-in procedure:  Your turned in results should consist of two parts.  First, a report on your work.  (1) Talk in person to me or Frank Chang, demonstrate your code and discuss the assignment.  When you talk to us, we want to run your program and discuss the visible features of the lighting with you.   Be ready to discuss the following: 

  1. Say what parts of the assignments you did,
  2. Describe any problems or difficulties you encountered.
  3. Describe any optional or extra work you did.
  4. Point out specular highlights, point out the effects of diffuse light and of ambient light.  Point out the emissive lights.  Explain why there is no shadowing.    Point out how the number of wraps and number of quads per wrap affects the specular highlights.  Point out how the local mode affects the specular highlights.

Second, turn in your code and an executable.   Executable files will be made publicly available, so everyone can have their results demoed to the rest of the class.  You should turn in source files and executable, by using anonymous ftp to euclid.ucsd.edu, directory pub/sbuss/turnin217/ma217sXX/LightTorusProg.     Here, replace "ma217sXX" by your own userid.  Make sure the executable file is uploaded in binary mode.     Click here for more detailed instructions.