CS40: Computer Graphics, Lab 7

3D Solids

By Jeff Kaufman

In this lab I extended the graphics library I started in lab 2 by adding support for solid objects.

Required Images

Cubism

Transformation Results

Note: in all of these images there are gaps between many polygons. These are the result of pesky off-by-one errors in my scanline fill code which I should go back and track down. Because I've not yet implemented shading, though, they aren't all bad, helping us see the shapes of the objects. And we can use them to see that backfaces really are being clipped properly, as we never get bits of the backs of objects showing through in those gaps.

The images below are all example frames from short movies that demonstrate the appropriate transformations by varying a transformation parameter smoothly over time.

Rotate X

Rotate Y

While in this video there appears to be some sort of Z-ordering going on, such that objects that are close to the viewer don't show up with other objects in front of them, this is just an ugly hack. The code that generated the animation knew which frame it was drawing and for the second half of the frames reversed the order in which the objects were added to the module, reversing the order in which they were drawn.

Rotate Z

Rotate XYZ

Using the rotateXYZ function and a cosine to make smooth movements.

Scale

Translate

Backface Culling

Most solid objects will only ever be seen from either inside or outside. We can make the rendering process more efficient, then, by makeing polygons optionally one sided. To implement this I added a field, Vector polyNorm to the Polygon object to hold a normal. If the normal is set to the zero vector the polygon is visible from both sides. Otherwise the polygon is drawn only if after the application of the perspective transformations the Z component is poistive. To keep compatibility with the spec and previous versions, polygon functions assume that the user wants two sided polygons unless otherwise specified.

The movie below shows a four colored sphere rotating with backfaces not drawn. Backfaces were also culled from the images above.


Jeff Kaufman : 2006
cbr at sccs dot swarthmore dot spam edu. Remove spam.

main page