WVR_GetTrackerInputAnalogAxis

WVR_EXPORT WVR_Axis_t WVR_GetTrackerInputAnalogAxis(WVR_TrackerId trackerId, WVR_InputId inputId)

Function to get the analog data of a specific input id of the tracker device.

Return
Analog data for WVR_InputId. (Refer to WVR_Axis.)
Version
API Level 8
Parameters
  • trackerId: Indicates what id of the tracker device. (Refer to WVR_TrackerId.)
  • inputId: One of WVR_InputId. This parameter specifies the physical touch on the tracker that retrieves the input data.

How to use

Here is an example for the function:

  1. Header & global variables.
    • The size 20 of array gButtonSupportTouchId0 is based on button definition (enum WVR_InputId on Types in wvr.h).
#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 variables for WVR_TrackerId_0
WVR_TrackerCapabilities_t gCapabilitiesId0; // device capabilities
bool gButtonSupportTouchId0[20] = {false}; // Supports touch/untouch feature or not for all 20 buttons
WVR_AnalogType gTriggerAnalogTypeId0 = WVR_AnalogType_None;
bool gTriggerTouchedId0 = false; // Trigger is currently touched or not
  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 button feature (capability supportsInputDevice) is 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 after WVR_StartTracker for the tracker device which has been connected before.
if (gRunningTR && WVR_IsTrackerConnected(WVR_TrackerId_0)) {
    WVR_Result ret = WVR_GetTrackerCapabilities(WVR_TrackerId_0, &gCapabilitiesId0);
    // Needs gCapabilitiesId0.supportsInputDevice
}
  1. (Timing 2 - When receiving event WVR_EventType_TrackerConnected) Use function WVR_GetTrackerCapabilities to get tracker capabilities to check whether button feature (capability supportsInputDevice) is supported or not.
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("TrackerId_%d, capabilities(ret: %d): %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_GetTrackerInputDeviceCapability (with parameter WVR_InputType_Touch and WVR_InputType_Analog) to check whether the button element supports touch & untouch and analog data features or not.
if (gRunningTR &&
    gCapabilitiesId0.supportsInputDevice &&
    WVR_IsTrackerConnected(WVR_TrackerId_0)) {
    int32_t triggerBit17Value = 1 << 17;
    int32_t touchCap = 0, analogCap = 0;

    // 1. Get the bit map of supporting touch & untouch features for all buttons.
    touchCap = WVR_GetTrackerInputDeviceCapability(WVR_TrackerId_0, WVR_InputType_Touch);
    if (touchCap & triggerBit17Value) { // Trigger supports touch & untouch features
        gButtonSupportTouchId0[WVR_InputId_Alias1_Trigger] = true;
    }

    // 2. Get the bit map of supporting analog data feature for all buttons.
    analogCap = WVR_GetTrackerInputDeviceCapability(WVR_TrackerId_0, WVR_InputType_Analog);
    if (analogCap & triggerBit17Value) { // Trigger supports analog data feature
        // Check supported analog Type of Trigger
        gTriggerAnalogTypeId0 = WVR_GetTrackerInputDeviceAnalogType(WVR_TrackerId_0, WVR_InputId_Alias1_Trigger);
    }
}
  1. Passively waiting for recieving event WVR_EventType_TrackerTouchTapped / WVR_EventType_TrackerTouchUntapped to trigger Step 6.
void ProcessEvent() {
    WVR_Event_t event;
    while(WVR_PollEventQueue(&event)) {
        if(event.common.type == WVR_EventType_TrackerTouchTapped) {
            LOGI("The button %d of tracker %d has just been touched.", event.input.inputId, event.tracker.trackerId);
            if (event.tracker.trackerId == WVR_TrackerId_0 && event.input.inputId == WVR_InputId_Alias1_Trigger {
                gTriggerTouchedId0 = true;
            }
        }

        if(event.common.type == WVR_EventType_TrackerTouchUntapped) {
            LOGI("The button %d of tracker %d has just been untouched.", event.input.inputId, event.tracker.trackerId);
            if (event.tracker.trackerId == WVR_TrackerId_0 && event.input.inputId == WVR_InputId_Alias1_Trigger) {
                gTriggerTouchedId0 = false;
            }
        }
    }
}
  1. Use function WVR_GetTrackerInputAnalogAxis to continuously get analog data of button element until event WVR_EventType_TrackerTouchUntapped is received.
if (gRunningTR &&
    gCapabilitiesId0.supportsInputDevice &&
    WVR_IsTrackerConnected(WVR_TrackerId_0) &&
    gButtonSupportTouchId0[WVR_InputId_Alias1_Trigger] &&
    gTriggerAnalogTypeId0 != WVR_AnalogType_None) {

    while (true) {
        if (gTriggerTouchedId0) {
            WVR_Axis_t axis = WVR_GetTrackerInputAnalogAxis(WVR_TrackerId_0, WVR_InputId_Alias1_Trigger);
            LOGI("TrackerId_%d, Trigger, analog: %f", WVR_TrackerId_0, axis.x);
        }
    }
}

Note

  1. This function works when capability supportsInputDevice of tracker device is true. If button feature is not supported, the returned value will be (0.0f, 0.0f).
  2. Trigger and Grip support 1D analog value. Touchpad and Thumbstick(Joystick) support 2D analog value. The tracker device may not include these button elements physically.
  3. The obtained analog data are meaningful when the touched state of button element remains true.
    • Actively using WVR_GetTrackerInputTouchState to get touched state of button element.
    • Passively waiting for recieving event WVR_EventType_TrackerTouchTapped of button element. (Just like the sample code (step 5) as noted above.)