Date posted:
January 8, 2007
Date due: January 27, 2007 at 11:59 p.m.
Submit to the dropbox on the myCourses website
In this project, you will implement some of the 2D drawing routines we have been discussing in class. This will help improve your understanding of these algorithms. You have the option of doing this project in C or in C++.
Also note that you will not be implementing a main program; instead, your reimplementation of the routines described below will be tested with a set of driver programs I will provide.
You are to implement
the following routines. Implement these using the midpoint line, scan-line
conversion, and Sutherland-Hodgman Clipping algorithms discussed in class and in
the textbook. Your implementation cannot make use of any OpenGL routines.
Instead, you should make use of the method
setPixel(x, y)
which will be provided for you. (See auxiliary code section below)
| Function | Description |
|---|---|
void drawLine(int
x0, int y0, int x1, int y1) |
Draw a line from vertex (x0,y0) to vertex (x1,y1).
|
void drawPolygon(int n, int x[], int y[]) |
Draw a filled polygon. The polygon has n distinct vertices. The
coordinates of the vertices making up the polygon are stored in the
x and
y arrays.
The ith
vertex will have coordinate (x[i],
y[i]) |
void clipPolygon(int in, int inx[], int iny[], int *out, int outx[],
int outy[], int x0, int y0, int x1, int y1) |
Clip the polygon with vertex count
in
and vertices
inx/iny
against the rectangular clipping region specified by lower-left corner
(x0,y0)
and upper-right corner
(x1,y1).
The resulting vertices are placed in
outx/outy,
with the vertex count placed in
out.
|
Below is a list of
links to code that will help you in completing this assignment:
| File | Description |
| paint.c | Source for paint program that will make calls to the functions that you will be implementing. This can be used as a test program. Please see the comments at the top of the file for info on how the program operates. |
| drawStuff.c | Default implementations of the functions that you need to implement. These default implementations make use of OpenGL calls. They are supplied so that you might compile the test programs and see how they should work. Note that the implementation provided for clipPolygon is especially dumb and will not clip correctly. You can use this file as a template, and replace function code with your implementation. |
| setPixel.c | Implementation of setPixel(). Recall that you must use this function in your implementation. No OpenGL calls allowed! |
| header.mak | If you plan on using makemake or gmakemake on the Suns. |
| lineTest.c | Test program for line drawing. |
| fillTest.c | Test program for polygon fill. |
| clipTest.c | Test program for clipping algorithm. |
If you want all of the above files in a single download, here they are in
zip and
tar format.
For your comparison, the correct output for each of the test programs are
provided below:
NOTES:
drawLine may occur in any order - that
is, there is no guarantee that (x0,y0) is the leftmost vertex of
the line segment. Vertices that specify polygons may occur in either clockwise
or counter-clockwise order. You will be submitting
the following files:
| Filename | Description |
| drawStuff.c | Contains implementations of the routines that need to be written. Feel free to use the supplied drawStuff.c as a template, replacing the original code with your implementation |
| aux files | Any additional files that might be needed for your implementation. If you have an executable, please submit it also. |
| README | Indicate on what platform you tested your implementation and provide additional info I may need to know (e.g. auxiliary libraries used) in order to build and run your assignment. |
All submission should be made using
myCourses. Look for the folder
named "Programming Assignment 2" in the dropbox area.
Your grade will be based on your reimplementation of the required routines and their usability with the supplied test programs.