WVR_GetTrackerPoseState

WVR_EXPORT WVR_Result WVR_GetTrackerPoseState(WVR_TrackerId trackerId, WVR_PoseOriginModel originModel, uint32_t predictedMilliSec, WVR_PoseState_t * poseState)

Function to get the pose of the tracker device with or without prediction.

Version
API Level 8
Parameters
  • trackerId: Indicates what id of the tracker device. (Refer to WVR_TrackerId.)
  • originModel: Specify the tracking universe of the origin tracking model. (Refer to WVR_PoseOriginModel.)
  • predictedMilliSec: Number of milliseconds from now to predict poses for. Positive numbers are in the future. Pass 0 to get the state at the instant the function is called.
  • poseState: Obtain the pose data. (Refer to WVR_PoseState.)
Return Value
  • WVR_Success: Get the pose of the tracker successfully.
  • Others: means failure. (Refer to WVR_Result.)

Note

  1. Parameter predictedMilliSec can determine the prediction time of tracker pose. (Supported on SDK 4.4.0 or later.)
    • If parameter predictedMilliSec is set as 0, the prediction time will be aligned with prediction time of HMD pose.
    • Developers can turn on/off prediction feature through function WVR_SetPosePredictEnabled (with parameter WVR_DeviceType_Tracker).

How to use

Here is an example for the function:

  1. Header & global variables
#include <wvr/wvr.h> // for enum WVR_SupportedFeature
#include <wvr/wvr_events.h>
#include <wvr/wvr_tracker.h>
#include <wvr/wvr_types.h>

bool gRunningTR = false;

// Global variable for device capabilities of WVR_TrackerId_0
WVR_TrackerCapabilities_t gCapabilitiesId0;
  1. Start tracker feature first if it has not been started yet. (See also WVR Supported Features)
    • And (Timing 1 - After starting tracker feature successfully) use function WVR_GetTrackerCapabilities to get tracker capabilities to check whether the pose tracking features (capability supportsOrientationTracking, supportsPositionTracking) are supported or not.
if (WVR_GetSupportedFeatures() & WVR_SupportedFeature_Tracker) { // the tracker feature is supported or not
    WVR_Result res = WVR_StartTracker();
    if (res == WVR_Success) gRunningTR = true;
}

// Timing 1: Update the tracker capabilities if the tracker device has been connected before.
if (gRunningTR && WVR_IsTrackerConnected(WVR_TrackerId_0)) {
    WVR_Result ret = WVR_GetTrackerCapabilities(event.tracker.trackerId, &gCapabilitiesId0);
    // Needs gCapabilitiesId0.supportsOrientationTracking, gCapabilitiesId0.supportsPositionTracking
}
  1. (Timing 2 - When receiving event WVR_EventType_TrackerConnected) Use function WVR_GetTrackerCapabilities to get tracker capabilities to check whether the pose tracking features (capability supportsOrientationTracking, supportsPositionTracking) are supported or not.

Note

  1. If capability supportsOrientationTracking is true, the tracker pose (obtained from WVR_GetTrackerPoseState) supports rotation.
  2. If capability supportsPositionTracking is true, the tracker pose (obtained from WVR_GetTrackerPoseState) supports position.
void ProcessEvent() {
    WVR_Event_t event;
    while(WVR_PollEventQueue(&event)) {
        switch (event.common.type) {
            /* Timing 2: Update tracker capabilities when tracker device has just been connected.*/
            case WVR_EventType_TrackerConnected:
                {
                    if (gRunningTR && event.tracker.trackerId == WVR_TrackerId_0) {
                        WVR_Result ret = WVR_GetTrackerCapabilities(event.tracker.trackerId, &gCapabilitiesId0);
                        LOGI("Tracker capabilities of TrackerId_%d: ret: %d, capabilities: %d, %d, %d, %d, %d, %d",
                            event.tracker.trackerId, ret,
                            gCapabilitiesId0.supportsOrientationTracking,
                            gCapabilitiesId0.supportsPositionTracking,
                            gCapabilitiesId0.supportsInputDevice,
                            gCapabilitiesId0.supportsHapticVibration,
                            gCapabilitiesId0.supportsBatteryLevel,
                            gCapabilitiesId0.supportsExtendedData);
                    }
                }
                break;
            default:
                break;
        }
    }
}
  1. Use function WVR_GetTrackerPoseState to get tracker pose continuously.
WVR_PoseState_t mPose;
uint32_t predictedMS = 0; // aligned with prediction time of HMD pose
WVR_Result ret = WVR_Error_SystemInvalid;
while(1) {
    if (gRunningTR &&
        WVR_IsTrackerConnected(WVR_TrackerId_0) &&
        (gCapabilitiesId0.supportsOrientationTracking || gCapabilitiesId0.supportsPositionTracking)) {
        ret = WVR_GetTrackerPoseState(WVR_TrackerId_0, WVR_PoseOriginModel_OriginOnGround, predictedMS, &mPose);
        if (ret == WVR_Success && mPose.isValidPose) {
            // Then the pose data in mPose would be valid.
        }
    }
}