Math 217A - Spring 2002 - Assignment #3
due Wednesday, April 24

Goals: Build a torus with a single long, wrapping quad strip, similar to figure 10(b) on page 13 of the book draft.  Animate it, and change the mesh resolution with keyboard controls.    This should help you (a) gain more experience with OpenGL,  (b) confront some of the basic issues in animation with keyboard controls, (c) possibly appreciate the dangers of using floating point numbers.


  1. Download the PC executable program WrapTorus.exe.    Try running it, and observe what it does.  Your assignment is to rewrite this program or something very similar.  Your program should support the following keystroke commands:
    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.
  2. You will have to write much of  this yourself.  To get started, you can download a simple program that makes an unanimated, non-wrapped torus.  WrapStart.c and WrapStart.h.   Download these (and rename them) to serve as the foundation for your homework programming.

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 will need to write a torus drawing routine from scratch.
  3. You do not need to make the keyboard controls in your program work exactly like the keyboard controls for WrapTorus.exe listed as items a.-i. above.  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 good control of the motion.
  4. To toggle quad mode and triangle mode, you can call glVertex3f with the same points in the same order for both modes, just vary the parameter to glBegin().
  5. To toggle "fill" mode and "wireframe" mode, use the OpenGL command (before rendering the torus)

        glPolygonMode(GL_FRONT_AND_BACK, polygonMode);

    where polygonMode is either GL_FILL or GL_LINE.   Then draw everything as polygons (quads or triangles). In line mode, only the outlines of the polygons are drawn.
  6. The torus will look terrible in "filled in polygon" mode.  This will improve in the next assignment when you add lights and material properties.
  7. 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.  Or (2), email me and Frank (, with a report of what you did.    A plain text report is preferred. For the email option, a long report is not needed, but you should at least 

  1. Say what parts of the assignments you did,
  2. Describe any problems or difficulties you encountered.
  3. Describe how your keyboard controls work for controlling animation.
  4. Describe any optional or extra work you did.

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, directory pub/sbuss/turnin217/ma217sXX/WrapTorusProg.     Here, replace "ma217sXX" by your own userid.  Make sure the executable file is uploaded in binary mode.     Click here for more detailed instructions.