3D Graphics Programming with QuickDraw 3D
Suppose that the pointing box you want to reassign is a knob box, which consists of a set of 12 knobs and associated alphanumeric displays. Six of
the knobs control the standard position and orientation values, and the remaining 6 knobs are device-specific. Listing 18-1 shows first how to search for the knob box.
Listing 18-1 Searching for a particular 3D pointing device
TQ3ControllerRef gBoxController = NULL; TQ3TrackerObject gBoxTracker = NULL; unsigned long gBoxSerialNumber = 0; void MyFindKnobBox (void) { TQ3ControllerRef controller; char mySig[256]; /*controller signature*/ char *boxSig = "Knob Systems, Inc.::Knob Box Grandé"; TQ3Boolean isActive; /*Find the box controller.*/ for (Q3Controller_Next(NULL, &controller); controller != NULL; Q3Controller_Next(controller, &controller)) { Q3Controller_GetSignature(controller, mySig, 256); Q3Controller_GetActivation(controller, &isActive); if (isActive && strncmp(mySig, boxSig, strlen(boxSig)) == 0) gBoxController = controller; } /*If we found a knob box, remember it.*/ if (gBoxController != NULL) { gBoxTracker = Q3Tracker_New(MyBoxNotifyFunc); if (gBoxTracker != NULL) { Q3Tracker_SetNotifyThresholds(gBoxTracker, 0.05, 0.05); } Q3Controller_SetTracker(gBoxController, gBoxTracker); } }Once you've found a knob box, you must connect it to the camera, but only for as long as your application's window is active. When the window is inactive, the box should revert to its previous function. Listing 18-2 defines two functions you should call when your application becomes active or inactive.
Listing 18-2 Activating and deactivating a pointing device
void MyOnActivation (void) { /*Any knob box data goes to your tracker.*/ if (gBoxController != NULL) Q3Controller_SetTracker(gBoxController, gBoxTracker); } void MyOnDeactivation (void) { /*Any knob box data goes to the default tracker.*/ if (gBoxController != NULL) Q3Controller_SetTracker(gBoxController, NULL); }As long as the knob box is attached to a view's camera, your application receives notification of changes in the knob box through the notify function
MyBoxNotifyFunc
, defined in Listing 18-3. MyBoxNotifyFunc
may be called at interrupt time. On Macintosh computers, you should wake up your process so that it can poll the tracker. This ensures that the application will recover control from the WaitNextEvent
function.Listing 18-3 Receiving notification of changes in a pointing device
TQ3Status MyBoxNotifyFunc
(TQ3TrackerObject tracker,
TQ3ControllerRef controller)
{
MyOSWakeUpMyProcess(); /*wake up app; poll for data later*/
return(kQ3Success);
}
The MyPollKnobBox
function defined in Listing 18-4 shows how to poll for data from the device. Your application's idle procedure should call MyPollKnobBox
.Listing 18-4 Polling for data from a pointing device
void MyPollKnobBox (void) { TQ3Boolean changed; TQ3Point3D position; TQ3Vector3D delta; /*Get the current knob positions.*/ changed = kQ3False; if (gBoxTracker != NULL) { Q3Tracker_GetPosition(gBoxTracker, &position, &delta, &changed, &gBoxSerialNumber); } /*Move camera and redraw if positions are new.*/ if (changed) { MyComputeCameraFromKnobBox(&position, &orientation); MyRedrawScene(); } }
Let us know what you think of these prototype pages.
Generated with Harlequin WebMaker