Using the QuickDraw 3D Pointing Device Manager
This section shows how to use some of the routines in the QuickDraw 3D Pointing Device Manager. In particular, it shows how to reassign a 3D pointing device to control a camera's position.Controlling a Camera Position With a Pointing Device
By default, a 3D pointing device contributes to the position and orientation of the cursor. You can, however, reassign a particular pointing device so that it controls some other element in a user interface view, such as the position and orientation of the view's camera. To do this, you must first find the pointing device. Then you need to disconnect the device from the cursor and connect it to the desired user interface element.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 functionMyBoxNotifyFunc
, 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 theWaitNextEvent
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); }TheMyPollKnobBox
function defined in Listing 18-4 shows how to poll for data from the device. Your application's idle procedure should callMyPollKnobBox
.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(); } }
Main | Top of Section | What's New | Apple Computer, Inc. | Find It | Feedback | Help