CS 351: Assignment #4

### Polygons

Due midnight 6 October 2011

In this assignment you'll implement the scanline fill algorithm for polygons. The algorithm is probably going to become the most used piece of code you'll write this semester and will be central to your rendering system. As such, take care to comment the code and understand what is going on.

1. Implement the scanline fill algorithm for polygons. You can write it from scratch, use the version in one of the textbooks, or use this scanfill skeleton code as the basis for your function. Make sure that your algorithm uses the correct placement of the coordinate grid (lower left corner of the pixel). The name for this routine should be Polygon_drawFill(). Your algorithm should not create a border that is a different color than the fill color. Just draw the filled in polygon as a single color (for now).

The updated C Graphics System Specification contains the details of the function prototypes for Polygon objects. The utility functions will be similar to the Polyline functions. For this lab, do not implement the shadeFill function, and do not worry about z-values for now. The drawFill function should just color the polygon a single color.

If you want to do a gradient fill, texture fill, or pattern fill, create separate functions for them.

2. Implement a second polygon fill algorithm, Polygon_drawFillB() that uses barycentric coordinates to determine which pixels to fill given a polygon with only 3 points. Scan over the bounding box of the triangle, filling any pixel whose barycentric coordinates are all in the range [0, 1]. The lecture notes give the equations.

When calculating which pixels to fill, use the center of each pixel to make the determination. That means you need to add 0.5 to the x and y value of the pixel coordinates when calculating the barycentric coordinates.

Don't worry about handling special cases (boundary going through the pixel center) for now. Note that test file B shows that drawing the polygons this way is order dependent.

3. One required image is the same as the previous assignment, a picture of a car, train, plane, or spaceship, except that a majority of the surfaces should be colored/filled in.
4. Use test file A to create the second required image.
5. Use test file B to create the third required image.
6. Create two images for your portfolio using the techniques you have developed so far and any extensions you decided to pursue.
7. If you wish, try running the testbench program for your fillscan and barycentric polygon functions. Note that the program makes use of a Color_set function, so you'll need to add that to your library.

### Extensions

• An animated gif or series of images that demonstrates the scanline fill algorithm (e.g. a short tutorial).
• Allow the use of a fill pattern (e.g. an 8x8 bitmap) in addition to the fill color.
• Allow the user to draw filled graphics primitives with a variety of overlay options so you can easily simulate transparency and other effects.
• Allow the user to specify a gradient across a polygon, circle, or ellipse so that they appear shaded.
• Cool artistic pictures demonstrating some interesting feature of your system.

### Writeup

Make a child wiki page from your main CS 351 wiki page. Give it the label cs351f11project4. Please follow the format below.

1. Abstract: 200 word description (at most) of what you did and a picture to go along with it.
2. Description of the task, in your own words. Be brief, but write it as though explaining it to a fellow student not in the course.
3. Description of how you solved the task, including any key equations or algorithms. You should also include algorithms or descriptions of what you did for any extensions. Include pictures here.
4. More pictures. Please put a caption on each picture explaining something about it. If you have nothing else, give it a name and indicate whose picture it is.
5. Summary of what you learned.

### Handin

Put your code files in your private handin folder as a single zip or tar file. Put your writeup on the wiki. Give it the label cs351f11project4.