Computer Science 155: Graphics
Fall 2000
Homework 4
This assignment is due by noon on Friday, Oct. 13.
Please put your name, name of program, and compiling instructions at the
top of your files. In addition, describe the features you've implemented
and comment each function (explaining briefly what it does and what its
arguments are). You should provide sufficient additional comments
for the graders to understand the logic of the program.
The objective in this assignment is to read the description of a 3D object from
a file, transform it according to the user's input, and then render it to the screen.
The major additions over assignment 3 are perspective projection and z-buffering.
For assignment 4, the menu options available to the user should include:
-
File: Reread "polygon.dat".
-
Clear: Clear the frame buffer and z-buffer, set CTM to the identity,
and then render the current object. (The current object is the initial object transformed
by the current transformation matrix CTM.)
-
Translate: Read three floats (dx, dy, and dz) from the keyboard, construct the corresponding
translation matrix T, and replace the current transformation matrix CTM by T*CTM. Then clear
the frame buffer and z-buffer. Finally render the current object.
Note this is a change from assignment 3, where
we post-multiplied CTM by T; i.e set CTM=CTM*T. The effect of this change is that the user will specify
transformations in the order in which they are to be applied, rather than in the reverse order.
This is more intuitive from the user's perspective. (It is not the way OpenGL handles
transformations but we won't worry about that here.)
-
Scale: Read three floats (sx, sy, sz) from the keyboard, construct the corresponding
scale matrix S, and replace CTM by S*CTM.
Clear the frame buffer and z-buffer. Render the current object.
-
Rotate: Read a float (angle) and int (axis of rotation x=0,y=1,z=2)
from the keyboard, construct the corresponding
rotation matrix R, and replace CTM by R*CTM.
Clear the frame buffer and z-buffer. Render the current object.
-
Projection: Toggle the projection type between orthographic and perspective. Set CPM to
reflect the current projection mode. Clear the
and frame buffer and z-buffer. Render the current
object.
The input file "polygon.dat" contains a description of each polygon in the object
and how it is positioned within the object. The file format is described below.
Here are sample data files for a cube and a pyramid .
Note that we are now allowing colors 0 through 7. A new
display() routine handles all 7 colors and
should replace your current version.
-
Number of polygons (int in [1,20])
-
For each polygon:
-
Polygon color (int in [0,7])
-
Number of vertices (int in [3,5])
-
For each vertex in order: x-coordinate, y-coordinate, z-coordinate (floats)
To render the object you should do the following:
-
Transform each vertex of each polygon to world coordinate; i.e. multiply it by
the current transformation matrix CTM.
-
Clip the world-coordinate vertices to the current viewing volume.
Clipping Notes summarize the calculations
you need to clip.
-
In orthographic mode the viewing volume is defined by the planes: x=VVLEFT, x=VVRIGHT,
y=VVTOP, y=VVBOTTOM, z=VVNEAR, and z=VVFAR.
-
In perspective mode the frustrum is defined by the viewpoint (0,0,EYE), two corners of
the projection plane (VVLEFT,VVTOP,VVNEAR) and (VVRIGHT,VVBOTTOM,VVNEAR), and the
far plane z=VVFAR.
The parameters used above are integers and should be defined in the "dim.h" file along
with BUFFWIDTH and BUFFHEIGHT. I suggest you set try setting BUFFWIDTH at 100, 250, or 500
and letting BUFFHEIGHT=BUFFWIDTH,
VVLEFT=VVBOTTOM=VVFAR = -BUFFWIDTH/4, VVRIGHT=VVTOP=VVNEAR=BUFFWIDTH/4,
and EYE=2*BUFFWIDTH.
-
Project the clipped vertices into the projection plan; i.e. multiply it by the current
projection matrix. Read Projection Notes for more details.
-
Normalize the clipped vertices; i.e. divide by the w-coordinate.
-
Transform the normalized coordinates into the viewport coordinate system; i.e. translate
the origin to the lower left corner.
-
Finally scan convert each polygon in the object using your program from assignment
2 or (if that didn't work) this code: polyfill.cpp , lineseg.h .
In either case you
must modify the code to include include z-buffering.
Z-Buffering Notes gives additional information on z-buffering.
If you use your own code you must also modify it to
to handle line segments with non-integer endpoints.
You should round the y-coordinates of the endpoints to get ymin and ymax.
(My code has already been modified.)