Alex Benn and Andrew Frampton
In this lab, we added a z Buffer to our graphics library by adding the
appropriate flags and functions to the Image, Line, Polygon, Polyline, and
Scanfill files. For the Image file we added functions to both access and
manipulate the z value for a given pixel. In Line we added a flag to
indicate when to deal with the z buffer, and then augmented the Line_draw()
function to appropriately draw and clip in the 3D space. The inverse z-value
is first calculated for each pixel along the line; a pixel is only drawn to
the output image if its z-value is closer to the viewer than the previous
z-value for that pixel. Finally, we changed the Scanfill algorithm to draw
polygons using the Z-buffer. This is done in a manner very similar to the
Line algorithm: each pixel's z-value is calculated, then compared against
the z-buffer. Finally, we changed the brightness of each pixel according to
its z-value, so that farther objects appear darker. This was done both because
resulting images look nifty and because this feature helped with debugging the
z-buffer algorithm.


Super-Awesome Update! Although the sphere-drawing
code demonstrated in Figure 3 below was developed long after this lab was due,
it demonstrates the Z-buffering techniques on a level unparalleled on this
plane of existence. Check it out.
