E26/CS40 Computer Graphics: Lab #9
Integrated 3D Modeling System
nick guerette . adem kader . heather jones
12.18.2004

labs home    |    lab1    |    lab3    |    lab4    |    lab5    |    lab6    |    lab7    |    lab8    |    lab9    |    final project


overview.

We implemented a 3D hierarchical modeling system for storing models of objects in three-dimensional space. Models are stored in a data structure called Structure3, which is simply a linked list of nodes of the Node3 data type (it stores pointers to the head and tail of the list). Each Node3 stores either a triangle (Triangle data type) or another Structure3, and also can store a Vertex data structure representing a single point, a Line data structure representing a line segment, or a Polygon data structure representing an arbitrary polygon, although drawing functions for the last three are unimplemented. Each Node3 also stores a local transformation matrix and an enumerated type variable stating what the content of the Node3 is (STRUCTURE3, TRIANGLE3, etc.). Each Triangle simply stores a Vertex array of size 3, and each Line stores a Vertex array of size 2. The Vertex data type stores the following elements:

  • Location vector
  • Surface normal vector, which is a location relative to the location vector, so that all rotations, translations and scales applied to the location can also be applied to the surface normal. If it were stored as the actual surface normal vector, then translations would cause it to be incorrect, and because our system handles translations simply by storing a local transformation matrix with each node, selectively applying some transformations to the location vector and some to the surface normal vector is infeasible without storing a separate matrix for transforming the surface normal and writing special transformation functions that apply themselves to one or both matrices as is fit, but we wanted to avoid doing this. Using our method, shears still make the surface normal incorrect, but calculating a correct surface normal after shearing would definitely require a specialized transformation function, as it would be necessary to calculate based on the shear value and the original surface normal a change in slope of the surface, and then from that obtain a rotation of the surface normal and apply it to the surface normal as a rotation.
  • Surface Color
  • Body Color
  • Specularity
  • Roughness
Functions are provided for creating each of the shape data types, adding nodes to a structure, and freeing memory allocated to a structure and everything it contains. The function drawStructure3 takes a structure and a global transformation matrix, and traverses the structure, calling zFill3 on each Triangle in the structure and recursively calling itself for any substructures stored in the structure. zFill3 takes a Triangle and a transformation matrix (drawStructure3 premultiplies the global transformation matrix passed to it by the local transformation matrix stored in the Node3, and passes the result to zFill3 or drawStructure3), creates a view transformation matrix, applies the position transformation matrix to the location and surface normal vectors, stores the world locations, then applies the view transformation matrix to the locations and performs a z-buffer scanline fill. The COP is transformed into world coordinates in order to find the location of the viewer in world coordinates for the purpose of calculating direction vectors to the viewer from each pixel for illumination. In the process of the scanline fill operation, all the parameters stored in each Vertex are interpolated along edges and scanlines of the triangle, including original location and surface normal relative position, and all illumination parameters. For each pixel drawn, the directions to the viewer and each light source are calculated, and the illumination of the surface at that location is calculated using the Cook-Torrance illumination model, with the ``modification'' of ignoring the distance to the light sources (there is no attenuation based on distance to light sources).

images.

Tritriangular thingy illuminated using the Phong illumination model, with a single light source directly in front of the viewer. We're able to switch between the Phong and Cook-Torrance illumination models with the spiffy method of commenting the Cook-Torrance illumination statement and uncommenting the Phong illumination statement.

The same tritriangular thingy, with a single light source right next to the blue triangle, using Phong illumination, demonstrating realistic specularity possible with surface parameters interpolated across polygons (Phong shading).

Another tritriangular thingy, this one illuminated using the Cook-Torrance illumination model. The bottom green triangle is smooth and the top one is rough, although it doesn't matter because there isn't any specularity on either of them. The blue one is rough on the left and smooth on the right, and it's clearly visible from specularity from the light source directly in front of the viewer. This animation contains some artifacts of compression, and there is an MNG format version available that's better, but for some reason still has problems. In order to view the MNG version, you need a browser with an MNG plugin or a special application for viewing MNG animations.

The star of this webpage. This image demonstrates interpolating everything across the surface of polygons. There are only a few triangles making up the bar, and they all stretch from one side to the other. The idea is for it to look like raw metal ore on the left and polished metal on the right. On the left, the surfaces are rough, unspecular, have a dull grey surface color and a slightly reddish body color, and corners are well-defined. On the right, surfaces are shiny and smooth, the surface color is bluish (visible at the edge of specular reflections), and the body color is grey. The right end of the bar is an octagon, but it looks rounded because surface normal points have been averaged at each corner, and each Vertex at a corner set to have the same surface normal. This results in the surface normal changing smoothly around the circumference of the bar at the right end, and it looking rounded under illumination. It's not immediately obvious, but this image also demonstrates the hierarchichal modeling system, as one side and one corner of the bar were created as a model, and then rotated twice to form the two sides and three corners that are visible over the course of a quarter-rotation of the bar. The entire model is then rotated one quarter turn while the light sources move back and forth, and the animation repeates. This image also contains artifacts of compression, and this one really does look much better in its MNG format version; see above for information on viewing MNG animations.

no copyright; all of the above work was done for the sake of science and engineering