by William Shoaff with lots of help
Jim Blinn's book [Bli96] provides a vivid account of the graphics pipeline, in particular, reading chapters 13 to 18 is enlighting. Each of these chapters were originally published in IEEE Computer Graphics and Applications.
The pipeline can be interpreted as a series of coordinate spaces where objects exist. There is little agreement on the names of these spaces, but, more importantly, architectures and algorithmics may eliminate or add spaces, or change when and how certain operations are made. We will distinguish the following spaces:
At present, we are only interested in model space. Other terms for this space are: master space or object space. In fact, there is not just one model space, but every object contained in the graphics scene is defined in its own model space. An object that appears multiple times is only defined once in its model space, but occurs multiple times in the scene graph.
The objects in which we are interested are mostly three dimensional,
thus model space is most often a three dimensional Euclidean
coordinate system of points denoted by
.
Some objects are inherently two dimensional, for example,
a playing card: For these objects, we can still use a three
dimensional space with z fixed at 0.
Some objects may be most easily described in systems other
than the Euclidean system (e.g., cylindrical or spherical coordinates).
We will not consider these special cases.
Our three dimensional Euclidean model space is right-handed. What this means is that if you hold your right hand with thumb, fore finger, and middle finger at right angles (orthogonal) to each other they form the x, y, and z axes of a model space. Diagrams of three dimensional Euclidean space appears in Figure 1. Only the positive axes are drawn from the origin. In the one on the left you are looking at the xy plane from above the xz plane and to the right of the yz plane. The diagram on the right presents a view where you are looking at the origin. It can be difficult to draw three dimensional objects on a two dimensional surface: You will need to use your imagination.
The primitive objects are: points, lines, and polygons: They are used to create more complex objects.
We will always write points in a rows:
There are several modifiers that are useful when describing polygons.
Object coordinates are defines in model space. Additional attributes can also be be declared. For example, an object's color is often specified, and so are normal vectors at polygon vertices. Delving into these now is not possible.
The subject of creating complex models is beyond the scope of this beginning graphics class. We will take the simple approach that the model objects are stored in one or more files which our programs will scan and store internally in a data structure.
One possible method to organize a model data file follows.
As an example, consider modeling a cylinder by six side faces, a top, and a bottom. This example, comes from the text by Alan Watt [Wat89] and images used were created by a former graphics student (Weigang Li). Watt does not give explicit coordinates, yet they are easy to determine. Refer to Figure 2. It is easy to count that there are 12 vertices and 8 polygons, but we'll declare there are only 3 surfaces: The top, bottom, and the side, which is made from 6 polygons. This information is recorded in Table 1 below, which represents the cylinder data file. (We'll use double slashes to comment the data file.)
Let's assume the origin
is located at the center of
the cylinder, it is 2 units high, and the distance between parallel
side faces is 1 unit. The top and bottom are regular polygons (hexagons).
The interior angle of a regular polygon with n sides is given by
A little trigonometry can now be used to determine that vertex 2
is at coordinates
and symmetry determines
the remaining vertices.
We have to approximate
and this type of error
when combined with other round-off and truncation errors
can cause irregularities in the scene: We must be careful.
In a complete model we would specify a color (red, green, blue),
an opacity (an
value),
and a normal vector
at each vertex.
Sometimes, we may prefer to calculate the normal vector from
information stored in the model data file.
To complete the data file, we'll assign surface number 1, 2, and 3 to the side, top, and bottom, respectively, and polygon numbers. For example, the polygon labeled 1 in Figure 2 is part of the side (belongs to surface 1) and has 4 vertices: 1, 7, 8, 2; polygon 7 from Figure 2 is surface 2 and has 6 vertices: 1, 2, 3, 4, 5, 6. This information is shown in Table 1.
There is a very important, but subtle point in the last paragraph: The order in which vertices are listed. I have chosen the convention that when viewed from the outside all polygons have their vertices listed counter-clockwise. The importance of this will become clear when we discuss normal vectors, and front and back faces. When you create your models be certain you develop a convention for listing the vertices of polygons and stick to it. Debugging this type of input error is frustrating: Spend the time up front to get it right the first time.
| 12 // vertices | |||
| 8 // polygons | |||
| 3 // surfaces | |||
| // Vertex number | x | y | z |
| 1 | -1.0 | 1.0 | 0.0 |
| 2 | -0.5 | 1.0 | -0.86602540 |
| 3 | 0.5 | 1.0 | -0.86602540 |
| 4 | 1.0 | 1.0 | 0 |
| 5 | 0.5 | 1.0 | 0.86602540 |
| 6 | -0.5 | 1.0 | 0.86602540 |
| 7 | -1 | -1.0 | 0.0 |
| 8 | -0.5 | -1.0 | -0.86602540 |
| 9 | 0.5 | -1.0 | -0.86602540 |
| 10 | 1.0 | -1.0 | 0.0 |
| 11 | 0.5 | -1.0 | 0.86602540 |
| 12 | -0.5 | 1.0 | 0.86602540 |
| // Polygon number | Surface number Vertices | Vertex list | |||||||
|---|---|---|---|---|---|---|---|---|---|
| 1 | 1 | 4 | 1 | 7 | 8 | 2 | |||
| 2 | 1 | 4 | 2 | 8 | 9 | 3 | |||
| 3 | 1 | 4 | 3 | 9 | 10 | 4 | |||
| 4 | 1 | 4 | 4 | 10 | 11 | 5 | |||
| 5 | 1 | 4 | 5 | 11 | 12 | 6 | |||
| 6 | 1 | 4 | 6 | 12 | 7 | 1 | |||
| 7 | 2 | 6 | 1 | 2 | 3 | 4 | 5 | 6 | |
| 8 | 3 | 6 | 12 | 11 | 10 | 9 | 8 | 7 | |
The last item we will cover in this section is internal storage of the models. To develop a data structure flexible enough to allow us to implement all of the algorithms we will want to is not trivial. Luckily, we can program at a higher level using a graphics API such as OpenGL, Direct3D, or Java3D that eliminate the need for us to develop complex data structures from scratch. However, in the interest of presenting a complete introduction to computer graphics, I'll include some notes on this subject. Again, I've borrowed from Alan Watts' book [Wat89]. Figure 3 provides a diagram of the data structure. The scene is contained in a list of objects. Note that a better implementation would use a more complex graph (e.g., a directed acyclic graph [DAG]) to allow faster operations (find, insert, delete) on the scene. Each object record contains a reference (pointer) to a list of surfaces that comprise the object. Each surface record contain a reference to a list of polygons that comprise the surface. Each polygon record contains the a reference to the polygon's vertices, a vector normal to the polygon, and a flag that indicates whether should cull (throw away) the polygon from the scene or not. Each vertex has its own local coordinates; currently these are model coordinates, but they will change to other spaces down the pipeline. Watt also saves the world position of the point: This (or view coordinates) are useful for lighting calculations; and the screen or device coordinates of the point. Each vertex has its own normal, which is used in interpolative shading
There are several spaces that make up the graphics pipeline: model, world, view, perspective, clip, normalized, device. We've learned that every object in a graphics scene has a model space where it is defined. Primitive objects are points, lines, and polygons. The basic object used in the standard graphics pipeline is a polygonal mesh. A simple object file format has been proposed and an internal data structure has been described.