使用openvr开发Oculus手柄,在操作Oculus手柄时发现trigger键十分灵敏,任何物体只要接触到trigger键都会触发trigger键绑定的事件响应
解决办法:
在openvr中有个结构体
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;
其中名为VRControllerAxis_t rAxis[ k_unControllerStateAxisCount ]的数组,用于Oculus手柄后发现该数组的第二个元素的x值rAxis[1].x在手柄的trigger键被施加不同压力时也会跟着变化,随着压力的增大而增大,减小而减小,范围从0到1。因此,可以通过对该值增加一个判断来控制trigger键的响应,具体设置多少因人而异;