Displaying 3D Objects

3D objects that move are usually defined in object space and then displayed at the desired position and orientation in world space. This process of moving 3D objects from object space to world space is called transformation. To transform a 3D object in this manner, we must specify where the object will be positioned in world space, and how it will be rotated around its own object space origin.

The basic function provided for this purpose is fg_3Dsetobject(). Its first three parameters are the world space (x,y,z) position to which the object's origin moves, and its last three parameters define the counterclockwise angles of rotation about the object space coordinate axes. For example, the statement

C/C++ and Delphi:

fg_3Dsetobject(0.0,0.0,100.0,0,180*10,0);

Visual Basic:

Call fg_3Dsetobject(0.0, 0.0, 100.0, 0, 180*10, 0)

will transform objects 100 units down the world space z axis and rotated 180° around each object's object space y axis. If we applied this transformation to our 40x40x40 object space cube, the cube's center would be at the world space coordinate z=100 and its back side would be facing the viewer. The values passed to fg_3Dsetobject() apply to all object space polygon drawing functions and remain in effect until we change the POV or call fg_3Dsetobject() again.

Besides fg_3Dsetobject(), Fastgraph also provides other functions that define an object's position and rotation. These functions are analogous to those that define the POV; in fact, they have the same names but with "object" appended, and they have the same parameters. You can move an object to an absolute position with fg_3Dmoveobject(), or move it relative to its current position with fg_3Dmoveforwardobject() fg_3Dmoverightobject(), and fg_3Dmoveupobject(). You can perform absolute object rotations with fg_3Drotateobject() and fg_3Daxisangleobject(), or perform relative object rotations with fg_3Drollobject(), fg_3Drotaterightobject(), and fg_3Drotateupobject(). Again, all of these functions are analogous to the POV definition functions, but they apply to moving and rotating objects rather than moving and rotating the viewer.

The fg_3Dpolygonobject() function displays a single-color polygon defined in object space, while fg_3Dpolygon() does the same thing for polygons defined in world space. Both functions have two parameters: an array defining the polygon's vertices as a series of (x,y,z) coordinate triples, and the number of vertices in the polygon. The first three elements of the vertex array represent the (x,y,z) values at the polygon's first vertex, the next three elements are for the second vertex, and so forth. For fg_3Dpolygonobject(), the polygon vertices are assumed to be object space coordinates and are transformed using the current object position and rotation settings. For fg_3Dpolygon(), the vertices are assumed to be world space coordinates so the function ignores these settings.

The fg_3Dtexturemapobject() function displays a texture-mapped polygon defined in object space, while fg_3Dtexturemap() does the same thing for polygons defined in world space. Both functions have three parameters: the usual array of polygon vertices, an array containing the (u,v) texture coordinates for each vertex, and the number of vertices in the polygon. The first two elements of the texture coordinate array represent the (u,v) values corresponding to the polygon's first vertex, the next two elements are for the second vertex, and so forth. For fg_3Dtexturemapobject(), the polygon vertices are assumed to be object space coordinates and are transformed using the current object position and rotation settings. For fg_3Dtexturemap(), the vertices are assumed to be world space coordinates so the function ignores these settings.

By default, Fastgraph's texture mapping functions assume their (u,v) texture coordinate arrays contain integer values. But when 3D clipping is applied to textures, floating point (u,v) coordinates can provide more accurate results. The fg_tmunits() function has a single integer parameter that specifies if the (u,v) coordinate arrays use integer or single precision floating point values. If this parameter is zero, the texture mapping functions assume integer (u,v) coordinates; if it is any other value, they assume floating point (u,v) coordinates. Note specifically the use of single precision (32-bit) floating point texture coordinates here, not double precision (64-bit). Single precision floating point means the type float in C and C++, and Single in Delphi and Basic.

Fastgraph's texture mapping functions normally consider zero-value texels to be opaque. We can change this behavior with fg_tmtransparency(), which expects one integer parameter that defines how the texture mapping functions treat zero-value texels. If this parameter is zero, zero-value texels will not be transparent (this is the default behavior). If it is any other value, zero-value texels will be transparent.

The fg_3Dshadeobject() function displays a Gouraud-shaded polygon defined in object space, while fg_3Dshade() does the same thing for polygons defined in world space. Both functions have three parameters: the usual array of polygon vertices, an array containing the RGB color components for each vertex, and the number of vertices in the polygon. The first three elements of the color component array represent the RGB color values at the polygon's first vertex, the next three elements are for the second vertex, and so forth. Each RGB component is a byte value between 0 and 255. For fg_3Dshadeobject(), the polygon vertices are assumed to be object space coordinates and are transformed using the current object position and rotation settings. For fg_3Dshade(), the vertices are assumed to be world space coordinates so the function ignores these settings.

Fastgraph's final 3D drawing function is fg_3Dline(), which draws a line between two world space points. The first three fg_3Dline() parameters define the x, y, and z world space coordinates for one of the line's end points, and its last three parameters define the x, y, and z coordinates for the other end point.

<< Prev

Next >>

Contents
Fastgraph Home Page

 

copyright 2001 Ted Gruber Software, Inc.