WVR_GetInputDeviceState

WVR_EXPORT bool WVR_GetInputDeviceState(WVR_DeviceType type, uint32_t inputType, uint32_t * buttons, uint32_t * touches, WVR_AnalogState_t * analogArray, uint32_t analogArrayCount)

Function to get the WVR_InputType data. InputType is a bitmask that represents the combined input types for WVR_InputType.

Return
False when any of the parameter WVR_InputType fails to get data. For example, if inputType is a combination of WVR_InputType_Button and WVR_InputType_Analog but the WVR_InputType_Button data was not retrieved, the API will return false.
Version
API Level 1
Parameters
  • type: Indicates what device to get the InputDeviceState. (refer to WVR_DeviceType)
  • inputType: Bitmask to represent the combined input type for WVR_InputType. Developers can get a single or combined input status.
  • buttons: Bitmask to represent the button state. Each bit corresponds to WVR_InputId.
  • touches: Bitmast to represent the touches state. Each bit corresponds to WVR_InputId.
  • analogArray: An array of WVR_AnalogState_t to represent all analog data. (refer to WVR_AnalogState)
  • analogArrayCount: Developer should the the array count from the WVR_GetInputTypeCount API.

How to use

This sample shows how to get the button state.

#include <wvr/wvr_device.h>

// Must initialize the VR runtime once before related API.
WVR_InitError eError = WVR_InitError_None;
eError = WVR_Init(WVR_AppType_VRContent);
if (eError != WVR_InitError_None) {
    LOGE("Unable to initialize VR runtime: %s", WVR_GetInitErrorString(eError));
    return;
}

uint32_t inputType = WVR_InputType_Button;
uint32_t buttons = 0, touches = 0;
if (WVR_GetInputDeviceState(WVR_DeviceType_Controller_Right, inputType, &buttons, &touches, nullptr, 0)) {
    for (int i = 0; i < WVR_InputId_Max; i++) {
        int input = 1 << i;
        if ((buttons & input) == input) {
            printf("WVR_DeviceType_Controller_Right InputId_%d is pressed.\n", i);
        }
    }
}

This sample shows how to get the axis state.

#include <wvr/wvr_device.h>

// Must initialize the VR runtime once before related API.
WVR_InitError eError = WVR_InitError_None;
eError = WVR_Init(WVR_AppType_VRContent);
if (eError != WVR_InitError_None) {
    LOGE("Unable to initialize VR runtime: %s", WVR_GetInitErrorString(eError));
    return;
}

uint32_t inputType = WVR_InputType_Touch | WVR_InputType_Analog;
uint32_t buttons = 0, touches = 0;
uint32_t analogCount = WVR_GetInputTypeCount(WVR_DeviceType_Controller_Left, WVR_InputType_Analog);
if (analogCount < 0) retrun;
WVR_AnalogState_t analogState[analogCount];
if (WVR_GetInputDeviceState(WVR_DeviceType_Controller_Left, inputType, &buttons, &touches, analogState, analogCount)) {
    for (int i = 0; i < analogCount; i++) {
        int input = 1 << analogState[i].id;
        if ((touches & input) == input) {
            printf("WVR_DeviceType_Controller_Left InputId_%d analog data(x, y) = (%f, %f)\n",
                analogState[i].id, analogState[i].axis.x, analogState[i].axis.y);
        }
    }
}

When the variable (bit) inside the variable (touches) taken from WVR_GetInputDeviceState is valid, then the corresponding WVR_AnalogState_t is useful.

enum WVR_InputType

Input type for the input id.

Values:

WVR_InputType_Button = 1<<0

Button input type

WVR_InputType_Touch = 1<<1

Touch input type

WVR_InputType_Analog = 1<<2

Analog input type