|
 |
 |
To access the contents, click the chapter and section titles.
Cutting Edge Direct 3D Programming
(Publisher: The Coriolis Group)
Author(s): Stan Trujillo
ISBN: 1576100502
Publication Date: 11/01/96
Chapter 2 3D Graphics
- 3D Concepts And Terminology
- Transforming 3D Objects
- Texture Mapping
- Lighting
- Animation
Volumes have been written about 3D graphics and, in a way, this chapter is another installment. However, most of the literature on 3D graphics shows how to implement particular algorithms. A smaller portion of the work addresses how to best represent and manipulate graphical constructs. Because we are using Direct3D, many 3D conceptual issues have already been addressed. Still, you need an understanding of key 3D concepts in order to use Direct3D. Well talk about those concepts in this chapter.
3D Coordinate Systems
The goal of 3D graphics is to present a two-dimensional representation of a three-dimensional scene. The presentation is in two dimensions because the medium on which the scene is viewed, a flat computer screen, is two-dimensional. So, 3D graphics means preparing two representations of the same scene: a three-dimensional representation that remains unseen and a two-dimensional representation that displays on the screen. We will talk about the unseen, three-dimensional representation first.
Representing objects in three dimensions can be accomplished by using a coordinate system that provides three separate axes. These axes are usually named X, Y, and Z.
There are two common variations on the 3D coordinate system: left-handed and right-handed. The difference between the two is the behavior of the Z axis. In the left-handed system, distant coordinates (appearing far away from the viewer) have larger Z values, while closer coordinates have smaller Z values. In the right-handed system, the Z axis is reversed: Distant coordinates have smaller Z values and closer coordinates have larger Z values. Direct3D uses the left-handed system, so well use it in this discussion. Figure 2.1 shows the left-handed coordinate system. The arrows represent the direction in which values increase along each axis.
Figure 2.1 The 3D coordinate system.
Any point in 3D space can be described with a set of three values. These values indicate the points location along each axis and are shown in this book using angle brackets like this: <1,2,3>. The values indicate the points location along the X, Y, and Z axes respectively.
The Origin
The point at which all three axes meet is called the origin. A point located at the origin has X, Y, and Z values of zero <0,0,0>. The farther a value is from zero, the farther the point is from the origin. Points located to the right of the origin have positive X values, and points located to the left have negative X values. Likewise, points located above the origin have positive Y values, and points located below have negative Y values. Figure 2.2 shows some labeled points
Figure 2.2 Some labeled points.
In the figure, the points are represented with spheres. This is just for visual effect, since a point is a location and not an object. Figure 2.3 shows a set of labeled points that appear at various locations along the Z axis.
Figure 2.3 Some points along the Z axis.
Vectors
A vector, like a point, is represented by three values, but a vector describes a direction and a velocity and not a location.
Take, for example, the following values: <0,1,0>. If we treat these numbers as a point, then the numbers represent a location that is one unit above the origin (units are arbitrary: they can represent centimeters, miles, etc.). If, however, we treat these same three numbers as a vector, we are given a direction and a velocity instead of a location. In this case, the direction is up and the velocity is 1. Representing vectors with three numbers is a little sneaky because a vector actually requires six numbers: three for a starting point and three for an ending point. This gives us a direction (the orientation of the second point from the first), and a velocity (the distance between the two points). Vectors can be represented by three values only if it is understood that the starting point is the origin (0, 0, 0).
Lets look at another vector: <2,0,0>. This vector represents the right direction because the vector starts at <0,0,0> and travels to the right along the X axis for two units. Because the <2,0,0> vector represents a line twice the length of the <0,1,0> vector, the <2, 0, 0> vectors velocity is twice that of the <0, 1, 0> vectors velocity. Figure 2.4 shows the two vectors we have discussed so far.
Figure 2.4 Vectors <0,1,0> and <2,0,0>.
It is important to remember that vectors and points are different. A point specifies a location; a vector does not. Locations are used to define a vector, but a vector does not define a location. The vectors in Figure 2.4 are placed at the origin because that is how they are represented numerically, but the arrows in the figure could appear anywhere in the coordinate system.
Planes
A plane is a flat surface that extends to infinity. A plane is not a square or a rectangle, because squares and rectangles have edges and corners. A planes size is undefined. The simplest way to represent a plane is with an axis and an intersection value. For example, a plane represented by a Y value of 3 is located 3 units below the origin, and extends out indefinitely along the X and Z axes. That is, the plane intersects the Y axis perpendicularly at 3. A portion of such a plane is shown in Figure 2.5.
Figure 2.5 A portion of a plane intersecting the Y axis at 3.
Notice that by representing a plane with an axis and a value, we are unable to describe a plane that is not aligned with an axis. If we want to describe a plane that cuts across the Y axis at a 45 degree angle, for example, we need a more sophisticated representation.
We can use a vector to describe the orientation of the plane. If we want a plane that intersects with the Y axis at a 45 degree angle, we could use the vector <0,1,1> to define a plane that is tilted toward the viewer (the plane is perpendicular to the vector). This vector alone doesnt define a plane, only the orientation of the plane. We still need to indicate where the plane is located. Again, we could use a Y value of 3 to indicate that the plane crosses the Y axis three units below the origin. Figure 2.6 shows a portion of this plane.
Figure 2.6 The plane placed at Y= 3 and oriented with the vector <0, 1, 1>.
|