The Tracker Event API provides functions for adding and removing event handlers for different types of tracker events. For example, you can add event handlers for stylus movement and button state changes. Refer to the ZSTrackerEventType enum for a complete list of events that can be monitored.
The following partial code example shows creating an event handler for stylus movement, defining the movement threshold, and registering the event handler. For brevity, both initialization and error handling are omitted. For the complete sample code, refer to the Stylus Move Event sample application in the Samples\Device subdirectory.
First, define the event handler for move events:
void handleMove(ZSHandle targetHandle, const ZSTrackerEventData* eventData, const void* userData) { if (eventData->type == ZS_TRACKER_EVENT_MOVE) { printf("Stylus Position: (%f, %f, %f)\n", eventData->poseMatrix.m03, eventData->poseMatrix.m13, eventData->poseMatrix.m23); } }
Next, in main() or some user-defined function, set the thresholds and register the event handler:
// zSpaceContext set during initialization. // ZSContext zSpaceContext = ...; // Get the stylus target. ZSHandle stylusHandle = NULL; zsFindTargetByType(zSpaceContext, ZS_TARGET_TYPE_PRIMARY, 0, &stylusHandle); // Set the stylus' move event threshold to the following: // Time -> 0.01 seconds // Distance -> 0.001 meters // Angle -> 0.01 degrees zsSetTargetMoveEventThresholds(stylusHandle, 0.01f, 0.001f, 0.01f); // Register event handlers. zsAddTrackerEventHandler(stylusHandle, ZS_TRACKER_EVENT_MOVE, &handleMove, 0);
To remove an event handler, call zsRemoveTrackerEventHandler().