LightTorus

LightTorus is a C program illustrating the use of OpenGL.   It is intended to accompany the book 3D Computer Graphics: A mathematical approach with OpenGL, by S. Buss, Cambridge University Press, 2003.   However, it can be used independently as well.

LightTorus draws a torus in a non-standard way, as a ribbon of quad strips that wrap around the torus in one long strip.  The C code consists of two source files, LightTorus.c and LightTorus.h.   There are several options available for downloading this program:

Things to try out:

  1. Before running LightTorus, you should try out the simpler WrapTorus program.  For a simpler setting illustrating the use of lights and material properties, see SimpleLight.
  2. Compile and run the program.  Test out the keyboard controls.  The controls j.-l. are new and not in WrapTorus.
    1. Press arrow keys (left, right, up and down) to make the torus rotate.
    2. Press "s" to single step the animation,
    3. Press "a" to start the animation running again without stopping.  (Undoes the "s" effect.)
    4. Press "r" to reset the torus back to its original orientation with no velocity.
    5. Press "0" (zero) to zero the velocity of the torus, but leave its position fixed.
    6. Press "W" to increase the number of wraps,  "w" to decrease the number of wraps.
    7. Press "N" to increase the number of segments per wrap.  "n" to decrease the number of segments per wrap.
    8. Press "q" to toggle between drawing quadrangles and triangles.
    9. Press "p" to toggle between rendering in filled polygon mode, and in wireframe mode.
    10. Press "f" to toggle between flat shading and smooth shading.
    11. Press "0" (zero) and "1" (one) to toggle the lights (Light #0 and light #1) off and on.
    12. Press "l" to toggle local mode off and on.  This command switches between having a local viewer and a positional light and having a non-local viewer (i.e., positioned at a point at infinity) and a directional light.
  3. Observe how the torus now looks three-dimensional in "filled polygon" mode. (Keyboard control: "p".)  This is a big improvement over the WrapTorus program, and is caused by the use of material properties and Phong lighting. 
  4. Try toggling the lights off and on. Observe the effects both diffuse lighting and specular highlights.  Why is the torus still visible when both lights are turned off? (Ans: global ambient light.)  Why does the torus look completely flat shaded, with no three-dimensionality, when both lights are turned off?
  5. When toggling local mode off and on, observe how the specular highlights change.  This is due to the changes in the light vector l and and the view vector v.
  6. Experiment with increasing the resolution of the mesh (controls "N" and "W").  At what point does the torus look smooth?   You answer will vary depending on whether you are in local mode, and whether the torus animation is running.