bool GetControllerState( vr::TrackedDeviceIndex_t unControllerDeviceIndex, vr::VRControllerState_t *pControllerState )
bool GetControllerStateWithPose( TrackingUniverseOrigin eOrigin, vr::TrackedDeviceIndex_t unControllerDeviceIndex, vr::VRControllerState_t *pControllerState, TrackedDevicePose_t *pTrackedDevicePose )
使用当前控制器的状态数据填充结构体:
1.vr::TrackedDeviceIndex_t unControllerDeviceIndex - 获取状态数据控制器的索引号
2.vr::VRControllerState_t *pControllerState - 存储控制器状态数据的结构体
3.TrackingUniverseOrigin eOrigin - 返回姿态数据所在的追踪设备空间的坐标系
4.TrackedDevicePose_t *pTrackedDevicePose - 当最后一个按键事件产生时,控制器的姿态数据会被存储到该结构体中。
使用当前的控制器状态数据填充这些结构体。如果因为某些原因导致控制器索引无效或状态数据不可取,则返回false。GetControllerStateWithPose会依据控制器最近更新的按钮状态,使用pose数据来填充pose的结构体。当用户按下或释放按钮时,如果需要一个精准的控制器pose作为输入到应用程序,则使用该格式。因为这个pose数据总是比当前的pose数据要旧,所以不应该使用它去做渲染。
控制器状态结构体:
/** Identifies what kind of axis is on the controller at index n. Read this type
* with pVRSystem->Get( nControllerDeviceIndex, Prop_Axis0Type_Int32 + n );
*/
enum EVRControllerAxisType
{
k_eControllerAxis_None = 0,
k_eControllerAxis_TrackPad = 1,
k_eControllerAxis_Joystick = 2,
k_eControllerAxis_Trigger = 3, // Analog trigger data is in the X axis
};
/** contains information about one axis on the controller */
struct VRControllerAxis_t
{
float x; // Ranges from -1.0 to 1.0 for joysticks and track pads. Ranges from 0.0 to 1.0 for triggers were 0 is fully released.
float y; // Ranges from -1.0 to 1.0 for joysticks and track pads. Is always 0.0 for triggers.
};
/** the number of axes in the controller state */
static const uint32_t k_unControllerStateAxisCount = 5;
/** Holds all the state of a controller at one moment in time. */
struct VRControllerState001_t
{
// If packet num matches that on your prior call, then the controller state hasn't been changed since
// your last call and there is no need to process it
uint32_t unPacketNum;
// bit flags for each of the buttons. Use ButtonMaskFromId to turn an ID into a mask
uint64_t ulButtonPressed;
uint64_t ulButtonTouched;
// Axis data for the controller's analog inputs
VRControllerAxis_t rAxis[ k_unControllerStateAxisCount ];
};
typedef VRControllerState001_t VRControllerState_t;
https://github.com/ValveSoftware/openvr/wiki/IVRSystem::GetControllerState