Sections:
The Z-Buffer algorithm is very simple in concept. Along with the image that we are drawing to, we keep a z-buffer, which is simply a matrix of doubles that stores the closest z value that has been drawn to the screen at any given (x, y) position. Hence, the z-buffer has the same dimensions as the image itself. As we draw to the image, at every pixel we compare our z value to that in the z-buffer, and only draw if our z value is nearer to the viewer than the value in the z-buffer. If we do draw, we update the z-buffer with the new z value.
Our specific implementation of the z-buffer algorithm is a modification to our polygon scanline fill algorithm. Now polygonRef3Ds know how to render themselves to an image, assuming the image has an initialized z-buffer. Our new scanline fill interpolates z across each scanline and column (actually, 1/z to preserve linearity in the perspective projection.) For each point on each scanline, we check our z value against that in the z-buffer, and only draw and update the z-buffer if our's is closer.
Integration of Z-Buffer and Modeling System
We integrated our Z-Buffer and modeling system, as described above.
Cool Animation Sequences and pyramid3D
We made a cool animation of two square pyramids rotating and orbiting eachother. Notice the aliasing issues on the first animation. This results from the fact that we did not have our polygons share points. Noting this, we designed a subclass of modelPrimative called pyramid3D that takes a top and an arbitrary base and generates a pyramid with polygons that share points as needed. This was only possible because we now render using a separate point list and polygon list.
Animation with Aliasing Issues |
![]() Animation with Shared Points (no aliasing issues) |
Here are some useful links relating to Z-buffers: