Open topic with navigation

# Updating the Tracked Targets

Updating the tracked targets requires only minimal steps:

- Get updated data about the targets. Your application must call zsUpdate() every frame.
- Get the latest stylus pose in tracker space.
- Transform the stylus pose from tracker space to camera space.
- Transform the stylus pose from camera space to world space.

The following partial code example shows these steps. Please refer to the Basic Stereo sample application for a more complete example. For brevity, error handling is omitted.

    void update(ZSHandle stylusHandle, ZSHandle viewportHandle)
    {
      // zSpaceContext initialized by zsInitialize().
      ZSContext zSpaceContext = ...;

      // Update the zSpace SDK. This updates both tracking information
      // as well as the head poses for any frustums that have been created.
      zsUpdate(zSpaceContext);

      // Grab the stylus pose (position and orientation) in tracker space.
      ZSTrackerPose stylusPose;
      zsGetTargetPose(stylusHandle, &stylusPose);

      // Transform the stylus pose from tracker to camera space.
      zsTransformMatrix(viewportHandle,
                        ZS_COORDINATE_SPACE_TRACKER,
                        ZS_COORDINATE_SPACE_CAMERA,
                        &stylusPose.matrix);

      // Transform the stylus pose from camera space to world space.
      // This is done by multiplying the stylus pose matrix (camera space) by the
      // application's camera matrix.
      //
      // For the following pseudocode, StylusCameraSpaceMatrix is simply
      // the stylusPose.matrix after it has been transformed from
      // tracker to camera space.
      //
      // Pseudocode: StylusWorldSpaceMatrix = CameraMatrix * StylusCameraSpaceMatrix
    }

Although we discussed zsUpdate() with regards to stereo in Stereo Basics, zsUpdate() also caches data about the physical devices being tracked.

Updating and converting the stylus pose from tracker space to world space is a critical step. This allows your application to represent the stylus's position and orientation in the application's scene such that any virtual representation will line up with the physical stylus. It is also necessary to determine which objects in the scene the stylus is acting upon.

The transformation from tracker space to camera space is an intermediate step. Camera space is a common coordinate system to both tracker space and world space. Note that zsTransformMatrix() requires a handle to the stereo viewport. For information on the stereo viewport, refer to Stereo Basics.

Open topic with navigation