Computer Science 155: Graphics
Fall 2000
Homework 3
This assignment is due by the start of class on Wed., Oct. 4.
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 of the assignments for the next 2.5 weeks is to implement
a graphics pipeline that draws a polygon mesh entered by the user. For
the first part of the assignment we will focus on constructing the pipeline
for a single polygon. You will
read in a polygon represented by vertices in 2D model coordinates. You should convert each
vertex to 3D homogenous model coordinates. (Situate the polygon in the z=0 plane.)
When the users asks that the polygon be drawn you should process the vertices through
the graphics pipeline.
The steps of the pipeline are:
-
Transform each vertex of the polygon to world coordinate; i.e. multiply it by
the current transformation matrix.
-
Clip the world-coordinate vertices to the current viewing volume. For the current
assignment you need only worry about orthographic projection with the viewing
volume bounded by the planes x=-250, x=250, y=-250, y=250, z=250, and z=-250, where far is
specified by the user.
-
Project the clipped vertices into the projection plan; i.e. multiply it by the current
projection matrix.
-
Scan convert the polygon defined by the projected vertices; i.e. use your polygon filling
routine from the last assignment. Note you should not outline the polygon nor draw its
vertices; just fill it.
Your program should read in the vertices of a polygon
from a file called "polygon.dat". The user is allowed to specify the color
of the polygon (white, black, red, green, blue), and how the polygon should be
transformed in 3D space via rotations, translations, and scaling. The user
will also specify the type of projection to be used; i.e. orthographic or perspective.
For the current asignment you are only required to implement orthographic projection.
In the case of orthographic projection the user will specify the distance between the
near and far planes. The near plane is always at z=0.
-
You should define (at least) two classes (or structs if you are programming
in C) for this assignment.
-
The class vertex contains four floats xCoord, yCoord, zCoord, and wCoord.
-
The class polygon contains four vertex arrays to store the vertices of the
polygon in the various coordinate systems: ModelVertices, WorldVertices, ClipVertices,
and ProjectedVertices. We will limit the number of allowable vertices per polygon to
20 so, to simplify your task, you can used fixed-size arrays. The class should also
contain the number of vertices in the original model, the number of vertices in the clipped
version (which may be less), and the polygon color.
You may, of course, add any additional information you find useful.
-
You should implement the following routines.
-
LoadIdentity(float* M) which initializes a 4X4 matrix of floats to the indentity matrix.
-
Three transformation routines:
translate(float dx, float dy, float dz), scale(float sx, float sy, float sz),
rotate(float angle, axis rotationaxis).
Each modifies the current transformation matrix, which is a global
4X4 matrix of floats called CTM.
-
Translate computes the transformation matrix M to translate
by (dx,dy,dz) and then sets CTM=CTM*M.
-
Scale computes the transformation matrix M to scale
by (sx,sy,sz) and sets CTM=CTM*M.
-
Rotate computes the transformation matrix M to rotate "angle" degrees about
"rotationaxis" (where axis is defined: enum axis {xaxis, yaxis, zaxis}).
It then sets CTM=CTM*M. The user will input the angle in degrees but be
sure to convert to radians before calling the cos/sin functions.
-
A 3D polygon clipping routine int polyClip(vertex* vertexlist).
When in orthographic projection mode the routine clips the polygon defined by vertexlist to the
standard viewing volume, i.e. the region bounded by the planes x=-250,
x=250, y=-250, y=250,
z=0, and z=far.
The routine overwrites vertexlist with the clipped vertices and returns
the number of vertices in the clipped polygon.
If you are using C++ you may want to make this a member function of the polygon class
(in which case you don't need to pass it vertexlist).
-
A projection routine void Ortho() that sets the current projection matrix for
orthographic projection. The current projection matrix is a global variable called
CPM.
The file hw3.cpp has the user interface and some routines for matrix/vector arithmetic.
It has several "hooks" where you should insert your code.