Defining 3D ObjectsWe can define 3D objects in either object space or world space. Objects that move are usually defined in object space and then displayed at their current position and orientation in world space. Stationary objects such as walls are usually defined in world space because they exist at fixed positions in our 3D universe. Fastgraph uses one set of functions to display objects in object space and another set of functions to display objects in world space. In either case, we define a 3D object as a group of convex polygons. For example, we can construct a cube from six squares joined at the corners:
The cube's front face is the polygon defined by the vertices ABCD in the above diagram. If this is a 40x40x40 cube defined in object space, it will have (x,y,z) coordinates extending from -20 to +20 in each direction. The cube will be centered at the origin, so its front face ABCD extends from -20 to +20 in both the x and y directions, and is situated at -20 along the z axis. The polygon representing the front face could be defined like this:
C/C++:
Delphi:
Visual Basic:
The front face has four vertices, with each vertex consisting of an (x,y,z) coordinate triple, for a total of twelve floating point values. The first three elements of the FrontFace array are the (x,y,z) coordinates for vertex A, the next three elements are the (x,y,z) coordinates for vertex B, and so forth. To form the complete cube, we would have five additional vertex arrays, one for each of the other five faces. Why would we want to define 3D objects in object space, and not just define them in world space to begin with? There are two reasons for this. First, object space lets us use the same vertex arrays to display the same 3D object in different locations. If we wanted to display 20 cubes, for instance, we only need to define the cube once in object space, and then display that one cube at 20 different world space positions. Defining objects in world space would mean having 20 sets of vertex arrays, one for each cube at each world space position. A less obvious reason for defining objects in world space is that we rotate 3D objects around their origin. Without object space, we would need to move world space objects to the world space origin, perform the rotation, and then move them back to their original world space position. Object space simplifies this considerably.
|
 
copyright 2001 Ted Gruber Software, Inc.