Math 155A - Winter 2001
Programming Assignment #3
In this assignment, you will create a torus
which can supports the following features: it can be drawn in either wire-frame mode or
fill mode; it can be formed from quadrangles or from triangles; and it can be rotated
under the control of the arrow keys. A novel feature of this torus is that instead
of being broken up into radial pieces, it is modeled as a single strip of polygons wrapped
spirally around the torus.
You will also build a small triangular pyramid placed in a fixed
position to the side of the torus. This will move with the torus and help you see
the movement of the torus.
This is the first of two assignments involving this torus: the next
assignment (programming assignment #4) will ask you to add normal vectors, to set the
material properties of the torus, and to add lights to the environment to make the torus
look attractive in non-wireframe mode.
Due date: Monday, February 12 (midnight).
Main tasks: Build a program with functionality similar to the
sample program in WrappedTorus. Your program will
display a wireframe or solid torus with the following functionality.
- The torus can be toggled between wireframe mode and solid (filled in) mode by use of the
p button (p stands for "polygon"). Draw
the torus and pyramid as (outward facing!) polygons. The OpenGL
commands are given below.
- The torus can be animated with the four arrow keys. Suggestions for how your
animation should work will be made in a hardcopy handout in class lecture. It should
spin both around the x-axis and around the central axis of the torus. The up/down
arrow keys should control the rotation around the x-axis and the left/right arrow keys
should control rotation around the central axis of the torus. It should be possible
to slow down the rotations and to single-step the animation.
- The torus will be built from either: (a) a single strip of non-overlapping
quadrilaterals wrapped around the torus, or (b) a single strip of non-overlapping
triangles wrapped around the torus. This strip will wrapped similarly to a ribbon
around the torus.
- The program will allow toggling between quadrilaterals and triangles by use of the q
key (q for "quadrilateral).
- The number of wraps around the torus will be controlled by the w and W
keys. w will decrease the number of wraps by one, and W
will increase the number of wraps by one.
- Each wrap line will be broken into a number of segments. This number can be
controlled from the keyboard by the n and N keys. n
decreases the number by one and N increases the number by one.
- The small pyramid sits initially on the negative x-axis, just to the left of the
torus. It moves with the torus
- Choose appropriate dimensions for your torus, along with a good viewpoint. For
now, use a perspective viewpoint, similar to what was used in the solar system.
However, you may want to adjust the view position and field of view to make the torus look
good.
Regarding the wireframe versus filled-in modes: in this programming assignment,
the filled-in version will look very featureless and flat. This will be improved on
in the next programming assignment.
A sample programs which displays this functionality can be found as P:/Projects/WrappedTorus/WrappedTorus.exe.
More on animation: The rotations should be performed by
rotating first around the y-axis and then around the x-axis
(the glRotate commands are given in the opposite order in your OpenGL
program). Your program should support the following commands.
- "r" - reset to original position, with no rotational velocity
- "a" - toggle animation on and off
- "s" - single step animation
- "0" (zero) - zero the rotation rates, but leave torus in its
current position.
- up/down arrow keys: control rotation rate around x-axis.
- left/right arrow keys: control rotation rate around the y-axis.
- If you want to debug animation controls before building your wireframe torus, you might
first just use glutSolidTorus (in GL_LINE shade model
mode) to get a torus displayed.
More details:
- You will need to start a new project/workspace for this assignment. Please name it
WrappedTorus and put in the folder H:Projects. There
are directions on how create a new project/workspace.
- The OpenGL commands
glPolygonMode(GL_FRONT_AND_BACK, polygonMode);
where polygonMode equals GL_LINE or GL_FILL
control whether polygons are drawns as solid polygons or in wireframe mode. This
means you do not need to explicitly draw the wireframe edges --- just use the GL_LINE
mode as you draw polygons (quadrilaterals or triangles).
- Be sure to use integers to index vertices being drawn on the surface of the torus.
If you use floating point numbers, roundoff errors may cause serious problems,
especially in the next (fourth) programming assignment.
Homework turn-in: You will need to prepare
- An executable file, plus any supporting files (if any) needed to run the
program.
- All source files
- Your program will be graded in individual sessions with Sam or Malachi,
as usual. Your grade will be established by examination of your program, plus
the oral discussion.