From 912b35693b32f5302bbdf32a7b9bac531341dc47 Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Thu, 2 Jun 2016 18:13:33 -0700 Subject: [PATCH] added vive single pulse haptics --- plugins/openvr/src/ViveControllerManager.cpp | 18 ++++++++++++++++++ plugins/openvr/src/ViveControllerManager.h | 2 ++ 2 files changed, 20 insertions(+) diff --git a/plugins/openvr/src/ViveControllerManager.cpp b/plugins/openvr/src/ViveControllerManager.cpp index 6e75454b5f..6b19646512 100644 --- a/plugins/openvr/src/ViveControllerManager.cpp +++ b/plugins/openvr/src/ViveControllerManager.cpp @@ -442,6 +442,24 @@ void ViveControllerManager::InputDevice::handlePoseEvent(float deltaTime, const _poseStateMap[isLeftHand ? controller::LEFT_HAND : controller::RIGHT_HAND] = avatarPose.transform(controllerToAvatar); } +// Vive Controllers do not support duration +bool ViveControllerManager::InputDevice::triggerHapticPulse(float strength, float duration, bool leftHand) { + auto handRole = leftHand ? vr::TrackedControllerRole_LeftHand : vr::TrackedControllerRole_RightHand; + auto deviceIndex = _system->GetTrackedDeviceIndexForControllerRole(handRole); + + if (_system->IsTrackedDeviceConnected(deviceIndex) && + _system->GetTrackedDeviceClass(deviceIndex) == vr::TrackedDeviceClass_Controller && + _trackedDevicePose[deviceIndex].bPoseIsValid) { + // the documentation says the third argument to TriggerHapticPulse is duration + // but it seems to instead be strength, and is between 0 and 3999 + // https://github.com/ValveSoftware/openvr/wiki/IVRSystem::TriggerHapticPulse + const float MAX_HAPTIC_STRENGTH = 3999.0f; + _system->TriggerHapticPulse(deviceIndex, 0, strength*MAX_HAPTIC_STRENGTH); + return true; + } + return false; +} + controller::Input::NamedVector ViveControllerManager::InputDevice::getAvailableInputs() const { using namespace controller; QVector availableInputs{ diff --git a/plugins/openvr/src/ViveControllerManager.h b/plugins/openvr/src/ViveControllerManager.h index bd5d4a39f4..c108d3087f 100644 --- a/plugins/openvr/src/ViveControllerManager.h +++ b/plugins/openvr/src/ViveControllerManager.h @@ -56,6 +56,8 @@ private: void update(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) override; void focusOutEvent() override; + bool triggerHapticPulse(float strength, float duration, bool leftHand) override; + void handleHandController(float deltaTime, uint32_t deviceIndex, const controller::InputCalibrationData& inputCalibrationData, bool isLeftHand); void handleButtonEvent(float deltaTime, uint32_t button, bool pressed, bool touched, bool isLeftHand); void handleAxisEvent(float deltaTime, uint32_t axis, float x, float y, bool isLeftHand);