WVR_GetCurrentControllerModel

WVR_EXPORT WVR_Result WVR_GetCurrentControllerModel(WVR_DeviceType ctrlerType, WVR_CtrlerModel_t ** ctrlerModel, bool isOneBone = true)

Use this function to get the controller model for the currently connected device. If the controller model does not exist, it will return the default model in the SDK.

Note: It is not recommended to call this function in the render thread or any thread that will block frame update.

Version
API Level 5
Parameters
  • ctrlerType: Device type: WVR_DeviceType_Controller_Right or WVR_DeviceType_Controller_Left.(refer to WVR_DeviceType)
  • ctrlerModel: (Output) A double pointer for receiving the controller model structure. The SDK will allocate the data structure for the controller animation and write the address into ctrlModelAnimData.
Return Value
  • WVR_SUCCESS: The controller model was successfully retrieved from the currently connected device.
  • WVR_Error_CtrlerModel_InvalidModel: The SDK can’t get the controller model information from the connected controller device or asset.
  • WVR_Error_CtrlerModel_DeviceDisconnected: The SDK can’t get the controller model information since the controller you want to get is not connected.
  • WVR_Error_CtrlerModel_Unknown: The SDK can’t get the controller model information since the system has not yet been initialized.
  • WVR_Error_InvalidArgument: If ctrlerModel is nullptr or pointer in *ctrlerModel isn’t nullptr.

Struct and enumeration

  • WVR_VertexBuffer
struct WVR_VertexBuffer

Vertex buffer of component in controller model.

Public Members

float *buffer

Vertex buffer.

uint32_t size

Vertex buffer size.

uint32_t dimension

2 is represents the vertex data in this buffer is 2D, 3 means 3D.

  • WVR_IndexBuffer
struct WVR_IndexBuffer

Index buffer of component in controller model.

Public Members

uint32_t *buffer

Index buffer.

uint32_t size

Index buffer size.

uint32_t type

Number about how many vertices composing a face. 1 : Point, 2 : Line, 3 : Triangle.

  • WVR_CtrlerCompInfo
struct WVR_CtrlerCompInfo

Controller component information.

Public Members

WVR_VertexBuffer_t vertices

Positions.(Size should be same with normal and tex coord buffers)

WVR_VertexBuffer_t normals

Normals. (Size should be same with vertices and tex coord buffers)

WVR_VertexBuffer_t texCoords

Texture coordinates. (Size should be same with vertex and normal buffers)

WVR_IndexBuffer_t indices

Face indices.

int32_t texIndex

Index of the texture in texture table. Default is -1.

float localMat[16]

Pose of this component of ctrler model space.

char name[64]

Name of this component.

bool defaultDraw

Is this component draw at begin.

  • WVR_CtrlerTexBitmap
struct WVR_CtrlerTexBitmap

Texture information.

Public Members

uint8_t *bitmap

Raw data.

uint32_t width

Width of bitmap.

uint32_t height

Height of bitmap.

uint32_t stride

Bytes per row.

int32_t format

0 is none, 1 is RGBA_8888, 4 is RGB565, 7 is RGBA_4444. 8 is OnlyAlpha 8bits. (Same with enum AndroidBitmapFormat in NDK)

  • WVR_TouchPadPlane
struct WVR_TouchPadPlane

Information about touchpad plane of controller model.

Public Members

WVR_Vector3f_t u

U axis of touchpad plane.

WVR_Vector3f_t v

V axis of touchpad plane.

WVR_Vector3f_t w

W axis of touchpad plane.

WVR_Vector3f_t center

Center of touchpad plane in controller model. Unit:(m)

float floatingDistance

Distance between touchpad effect and touchpad plane. Unit:(m)

float radius

Radius of touchpad plane. Unit:(m)

bool valid

Is this information simulated or load from config from device service.

  • WVR_BatteryLevelTable
struct WVR_BatteryLevelTable

Information about battery levels of controller model.

Public Members

WVR_CtrlerTexBitmap_t *texTable

Array that are used to kept textures of each battery level.

int32_t *minLvTable

Lower bounds of each battery level.

int32_t *maxLvTable

Upper bounds of each battery level.

uint32_t size

Size of battery levels.

  • WVR_CtrlerModel
struct WVR_CtrlerModel

Structure about all necessary information of controller model.

Public Members

WVR_CtrlerCompInfoTable_t compInfos

Component information

WVR_CtrlerTexBitmapTable_t bitmapInfos

Texture information

WVR_TouchPadPlane_t touchpadPlane

Touchpad information

WVR_BatteryLevelTable_t batteryLevels

Battery information

char name[256]

Name of controller model.

bool loadFromAsset

Default model from asset or device.

How to use

See the example below:

  1. Create a function for getting the render model.
std::function<void()> loadModelFunc = [this](){
    if (mCachedData != nullptr) {
        WVR_ReleaseControllerModel(&mCachedData); //we will clear cached data ptr to nullptr.
    }
    WVR_Result result = WVR_GetCurrentControllerModel(mCtrlerType, &mCachedData);
    if (result == WVR_Success) {
        //It represent ok, set a flag to notify graphics initialization in render thread.
    }
};
  1. Trigger the function on another thread that doesn’t block the frame update.
//Trigger load model.
loadingThread = std::thread(loadModelFunc);
  1. Calculate the MVP matrix of the controller for rendering.
//MVP matrix of controller.
mvps = Projection * View * iCtrlerPose;

The full example is in the Controller class of the wvr_native_hellovr sample.