added vive single pulse haptics

This commit is contained in:
SamGondelman 2016-06-02 18:13:33 -07:00
parent 69971a3439
commit 912b35693b
2 changed files with 20 additions and 0 deletions

View file

@ -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<Input::NamedPair> availableInputs{

View file

@ -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);