Date posted:
September 12, 2011
Due Dates:
Stage 1:
September 21,
2011 at 11:59 p.m.
Stage 2: September 28, 2011 at 11:59 p.m.
Stage 3: October 5, 2011 at 11:59 p.m.
Submit to the appropriate dropbox on myCourses.
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++. You will not be implementing a main program. Instead, the routines you implement will be tested by a set of driver programs which are provided below.
Note: the sample code provided is written in C. You will need to make the necessary modifications if you are using C++
You are to implement the following routines:
| Stage | Function | Description |
|---|---|---|
| 1 | void drawLine(int
x0, int y0, int x1, int y1) |
Draw a line from vertex (x0,y0) to vertex (x1,y1).
|
| 2 |
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. |
| 3 |
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]) |
Implement these using the midpoint line, Sutherland-Hodgman clipping, and scan-line polygon fill algorithms discussed in class and in the textbook.
Your implementation cannot make use of any OpenGL routines with one exception - you should make use of a method setPixel(x, y) which is defined as follows:
void setPixel (int x, int y)
{
glRecti( x, y, x+1, y+1 );
}
Below is a list of
links to code that will help you in completing this assignment.
| File | Description |
| lineTest.c | Test program for line drawing. |
| fillTest.c | Test program for polygon fill. |
| clipTest.c | Test program for clipping algorithm. |
| setPixel.c | Implementation of setPixel(). You must use this function in your implementation. No other OpenGL calls allowed! |
| 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. |
| 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 (optional). Please see the comments at the top of the file for info on how the program operates. |
| header.mak | header.mak file for CS department's Linux systems. |
If you want all of the above files in a single download, here they are in
zip.
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.clipPolygon function only does clipping - it should not
do any drawing.READ THIS SECTION CAREFULLY
For each stage, please submit ALL files necessary to build and run the programs - lineTest (stage 1), clipTest (stage 2), and filltest (stage 3).
Your submission should include a file called drawStuff that contains your implementations of the routines that need to be written.
Finally, your submission must include a README that provides detailed instructions for building and running your submission on the CS Department's Linux lab machines.
All submission should be made using myCourses. Look for the folders named "Programming Assignment 1 Stage #" in the dropbox area.
Your grade will be based on your implementation of the required routines and their usability with the supplied test programs.