From 9a5f0dea95a66a2c87c4538ad79d145a1b103562 Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Tue, 28 Nov 2017 13:16:47 -0800 Subject: [PATCH] better solution --- plugins/openvr/src/ViveControllerManager.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/plugins/openvr/src/ViveControllerManager.cpp b/plugins/openvr/src/ViveControllerManager.cpp index b214ec9a2e..512de55ede 100644 --- a/plugins/openvr/src/ViveControllerManager.cpp +++ b/plugins/openvr/src/ViveControllerManager.cpp @@ -280,13 +280,13 @@ void ViveControllerManager::pluginUpdate(float deltaTime, const controller::Inpu _inputDevice->update(deltaTime, inputCalibrationData); }); - if (isDesktopMode() && _registeredWithInputMapper) { + if (_inputDevice->_trackedControllers == 0 && _registeredWithInputMapper) { userInputMapper->removeDevice(_inputDevice->_deviceID); _registeredWithInputMapper = false; _inputDevice->_poseStateMap.clear(); } - if (!_registeredWithInputMapper && !isDesktopMode()) { + if (!_registeredWithInputMapper && _inputDevice->_trackedControllers > 0) { userInputMapper->registerDevice(_inputDevice); _registeredWithInputMapper = true; } @@ -337,6 +337,7 @@ void ViveControllerManager::InputDevice::update(float deltaTime, const controlle _poseStateMap.clear(); _buttonPressedMap.clear(); _validTrackedObjects.clear(); + _trackedControllers = 0; // While the keyboard is open, we defer strictly to the keyboard values if (isOpenVrKeyboardShown()) { @@ -369,20 +370,19 @@ void ViveControllerManager::InputDevice::update(float deltaTime, const controlle } } - int numTrackedControllers = 0; if (leftHandDeviceIndex != vr::k_unTrackedDeviceIndexInvalid) { - numTrackedControllers++; + _trackedControllers++; } if (rightHandDeviceIndex != vr::k_unTrackedDeviceIndexInvalid) { - numTrackedControllers++; + _trackedControllers++; } - _trackedControllers = numTrackedControllers; calibrateFromHandController(inputCalibrationData); calibrateFromUI(inputCalibrationData); updateCalibratedLimbs(inputCalibrationData); _lastSimPoseData = _nextSimPoseData; + qDebug() << _trackedControllers; } void ViveControllerManager::InputDevice::calibrateFromHandController(const controller::InputCalibrationData& inputCalibrationData) { @@ -527,6 +527,7 @@ void ViveControllerManager::InputDevice::handleTrackedObject(uint32_t deviceInde // but _validTrackedObjects remain in sensor frame _validTrackedObjects.push_back(std::make_pair(poseIndex, pose)); + _trackedControllers++; } else { controller::Pose invalidPose; _poseStateMap[poseIndex] = invalidPose; @@ -758,9 +759,9 @@ void ViveControllerManager::InputDevice::handleHmd(uint32_t deviceIndex, const c } else { const mat4& mat = mat4(); const vec3 zero = vec3(); - handleHeadPoseEvent(inputCalibrationData, mat, zero, zero); } + _trackedControllers++; } }