Understanding Graf3D
Volume Number: 3
Issue Number: 3
Column Tag: Pascal Procedures
Understanding Graf3D
By Scott Berfield, Mindscape, Inc.
Almost everybody has heard of GRAF3D for the Mac, but aside from Boxes,
Sinegrid, and BoxSphere, there is little evidence of its use. This is probably because
the only documentation in general distribution is in the form of the source code for the
above programs, and in the interface files for the various compilers. As it turns out,
there is a pre-release tech note from Apple which does a good job of explaining a lot of
how GRAF3D works, if you're a registered developer.
In this article, I will present a brief explanation of some basic concepts of 3D
math, an overview of how the Mac's Graf3D routines deal with those concepts, the data
types and routines that make up Graf3d, and finally, a sample program that tries to
clarify the difference between two of what I consider Graf3D's more confusing
concepts.
The program included with this article was developed in LightSpeed Pascal and
then converted to Borland Turbo Pascal, so the article also presents a small
comparison between the two language implementations.
3D Concepts
There are several basic concepts of 3D graphics with which you will need to be
familiar if you are going to be able to use Graf3D to its fullest extent. Among these are
the coordinate system conventions and the various transformations and their meaning.
The Coordinate System
Three dimensional graphics are generally dealt with using a right-handed
cartesian coordinate system (see fig. 1)
The three axes are labeled X, Y, and Z. Thus, each point in three dimensional
space can be represented by three values. When displaying such a three-dimensional
space on a two-dimensional surface (a Mac's screen, for instance) some basic
trigonometric calculations are used to map the points into their proper positions. The
basics of this were discovered by artists during the renaissance.
Fig. 1 3-D Coordinate System
Transformations
There are three transformations we will want to use to manipulate
three-dimensional images. These are rotation, scaling, and transformation.
Rotation can be about any of the three axes. Rotation about the X axis is called
Pitch. Rotation about the Y axis is called Yaw, and rotation about the Z axis is called
Roll. (These terms come primarily from the aviation world.) Rotations are performed
relative to the coordinate system's origin. Thus, if you wish to rotate an object around