3D Graphics Programming with QuickDraw 3D
MyEnvironmentHas3DViewer
function defined in Listing 2-1.Listing 2-1 Determining whether the 3D Viewer is available
Boolean MyEnvironmentHas3DViewer
(void)
{
return((Boolean)Q3ViewerNew != kUnresolvedSymbolAddress);
}
The MyEnvironmentHas3DViewer
function checks whether the address of the Q3ViewerNew
function has been resolved. If it hasn't been resolved (that is, if the Code Fragment Manager couldn't find the 3D Viewer shared library when launching your application), MyEnvironmentHas3DViewer
returns the value FALSE
to its caller. Otherwise, if the address of the Q3ViewerNew
function was successfully resolved, MyEnvironmentHas3DViewer
returns TRUE
.
For the function MyEnvironmentHas3DViewer
to work properly, you must establish soft links (also called weak links) between your application and the 3D Viewer shared library. For information on soft links, see the book Inside Macintosh: PowerPC System Software. For specific information on establishing soft links, see the documentation for your software development system.<8bat>u
On the Macintosh Operating System, you can verify that the 3D Viewer is available in the current operating environment by calling the Gestalt
function with the gestaltQuickDraw3DViewer
selector. Gestalt
returns a long word whose value indicates the availability of the 3D Viewer. Currently these values are defined:
enum { gestaltQuickDraw3DViewer = 'q3vc', gestaltQ3ViewerNotAvailable = 0, gestaltQ3ViewerAvailable = 1 }You should ensure that the value gestaltQ3ViewerAvailable is returned before calling any 3D Viewer routines.
For more information on the Gestalt
function, see
Inside Macintosh: Operating System Utilities.<8bat>u
Q3ViewerNew
function. You pass Q3ViewerNew
a pointer to the window in which you want the viewer to appear, the rectangle that is to contain the viewer pane, and a selector indicating which viewer features to enable. Q3ViewerNew
returns a reference to a viewer object. Listing 2-2 illustrates one way to call Q3ViewerNew
. The function MyCreateViewer
defined in Listing 2-2 creates a viewer pane that occupies Listing 2-2 Creating a viewer object
TQ3ViewerObject MyCreateViewer (WindowPtr myWindow) { TQ3ViewerObject myViewer; Rect myRect; /*Get rectangle enclosing the window's content region.*/ myRect = myWindow->portRect; if (EmptyRect(&myRect)) /*make sure we got a nonempty rect*/ goto bail; /*Create a new viewer object in entire content region.*/ myViewer = Q3ViewerNew((CGrafPtr)myWindow, &myRect, kQ3ViewerDefault); if (myViewer == NULL) goto bail; return (myViewer); /*return new viewer object*/ bail: /*If any of the above failed, return an empty viewer object.*/ return (NULL); }The third parameter to the call to
Q3ViewerNew
is a set of viewer flags that specify information about the appearance and behavior of the new viewer object. In Listing 2-2, the viewer flag parameter is set to the value kQ3ViewerDefault
, indicating that the default values of the viewer flags are Q3ViewerUseFile
or Q3ViewerUseData
function. Q3ViewerUseFile
takes a reference to an existing viewer object and a file reference number of an open metafile, as follows:
myErr = Q3ViewerUseFile(myViewer, myFsRefNum);You use the
Q3ViewerUseData
function to specify a 3D model whose data is already in memory (either on the Clipboard or elsewhere in RAM). Q3ViewerUseData
takes a reference to an existing viewer object, a pointer to the metafile data in RAM, and the number of bytes occupied by that data. Here's an example of calling Q3ViewerUseData
:
myErr = Q3ViewerUseData(myViewer, myDataPtr, myDataSize);The data in the buffer whose address and size you pass to
Q3ViewerUseData
must be in the QuickDraw3D Object Metafile format.<8bat>s
Once you attach the metafile data to a visible viewer object, the user is able to see the 3D model in the viewer pane. If, however, the viewer pane was invisible when it was created, you need to call the Q3ViewerDraw
function to make it visible.
The 3D Viewer treats the model data as a single group. You can get a reference to the model data currently displayed in the viewer's picture area by calling the Q3ViewerGetGroup
function. You can change that model data by calling the Q3ViewerUseGroup
function.
You can also retrieve the view object associated with a viewer object by calling the Q3ViewerGetView
function. You can then modify some of the view settings, such as the lights or the camera. If you wish, you can also restore the view settings to their original values by calling the Q3ViewerRestoreView
function.
isViewerEvent = Q3ViewerEvent(myViewer, myEvent);The
Q3ViewerEvent
function determines whether the event specified by the myEvent
event record affects the specified viewer object. If so, Q3ViewerEvent
handles the event and returns TRUE
as it function result. Otherwise, Q3ViewerEvent
returns FALSE
.
Let us know what you think of these prototype pages.
Generated with Harlequin WebMaker