Showing the changes to plugins/openvr/src/ViveControllerManager.cpp (1 of 2 files). Show all
Unified · Split
| @@ -21,6 +21,7 @@ · 20 unmodified lines | ||
| 21 | 21 | #include <NumericalConstants.h> |
| 22 | 22 | #include <ui-plugins/PluginContainer.h> |
| 23 | 23 | #include <UserActivityLogger.h> |
| 24 | +#include <NumericalConstants.h> | |
| 24 | 25 | #include <OffscreenUi.h> |
| 25 | 26 | #include <GLMHelpers.h> |
| 26 | 27 | #include <glm/ext.hpp> |
| @@ -40,6 +41,7 @@ void releaseOpenVrSystem(); · 13 unmodified lines | ||
| 40 | 41 | |
| 41 | 42 | |
| 42 | 43 | static const char* CONTROLLER_MODEL_STRING = "vr_controller_05_wireless_b"; |
| 44 | +const quint64 CALIBRATION_TIMELAPSE = 3 * USECS_PER_SECOND; | |
| 43 | 45 | |
| 44 | 46 | static const char* MENU_PARENT = "Avatar"; |
| 45 | 47 | static const char* MENU_NAME = "Vive Controllers"; |
| @@ -188,12 +190,19 @@ void ViveControllerManager::InputDevice::update(float deltaTime, const controlle · 142 unmodified lines | ||
| 188 | 190 | _trackedControllers = numTrackedControllers; |
| 189 | 191 | |
| 190 | 192 | if (checkForCalibrationEvent()) { |
| 191 | − if (!_triggersPressedHandled) { | |
| 193 | + quint64 currentTime = usecTimestampNow(); | |
| 194 | + if (!_timeTilCalibrationSet) { | |
| 195 | + _timeTilCalibrationSet = true; | |
| 196 | + _timeTilCalibration = currentTime + CALIBRATION_TIMELAPSE; | |
| 197 | + } | |
| 198 | + | |
| 199 | + if (currentTime > _timeTilCalibration && !_triggersPressedHandled) { | |
| 192 | 200 | _triggersPressedHandled = true; |
| 193 | 201 | calibrateOrUncalibrate(inputCalibrationData); |
| 194 | 202 | } |
| 195 | 203 | } else { |
| 196 | 204 | _triggersPressedHandled = false; |
| 205 | + _timeTilCalibrationSet = false; | |
| 197 | 206 | } |
| 198 | 207 | |
| 199 | 208 | updateCalibratedLimbs(); |
| @@ -232,12 +241,6 @@ void ViveControllerManager::InputDevice::calibrateOrUncalibrate(const controller · 32 unmodified lines | ||
| 232 | 241 | } |
| 233 | 242 | } |
| 234 | 243 | |
| 235 | −bool ViveControllerManager::InputDevice::checkForCalibrationEvent() { | |
| 236 | − auto& leftTrigger = _buttonPressedMap.find(controller::LT); | |
| 237 | − auto& rightTrigger = _buttonPressedMap.find(controller::RT); | |
| 238 | − return ((leftTrigger != _buttonPressedMap.end()) && (rightTrigger != _buttonPressedMap.end())); | |
| 239 | −} | |
| 240 | − | |
| 241 | 244 | void ViveControllerManager::InputDevice::calibrate(const controller::InputCalibrationData& inputCalibration) { |
| 242 | 245 | // convert the hmd head from sensor space to avatar space |
| 243 | 246 | glm::mat4 hmdSensorFlippedMat = inputCalibration.hmdSensorMat * Matrices::Y_180; |
| @@ -416,6 +419,14 @@ enum ViveButtonChannel { · 172 unmodified lines | ||
| 416 | 419 | RIGHT_APP_MENU |
| 417 | 420 | }; |
| 418 | 421 | |
| 422 | +bool ViveControllerManager::InputDevice::checkForCalibrationEvent() { | |
| 423 | + auto& endOfMap = _buttonPressedMap.end(); | |
| 424 | + auto& leftTrigger = _buttonPressedMap.find(controller::LT); | |
| 425 | + auto& rightTrigger = _buttonPressedMap.find(controller::RT); | |
| 426 | + auto& leftAppButton = _buttonPressedMap.find(LEFT_APP_MENU); | |
| 427 | + auto& rightAppButton = _buttonPressedMap.find(RIGHT_APP_MENU); | |
| 428 | + return ((leftTrigger != endOfMap && leftAppButton != endOfMap) && (rightTrigger != endOfMap && rightAppButton != endOfMap)); | |
| 429 | +} | |
| 419 | 430 | |
| 420 | 431 | // These functions do translation from the Steam IDs to the standard controller IDs |
| 421 | 432 | void ViveControllerManager::InputDevice::handleButtonEvent(float deltaTime, uint32_t button, bool pressed, bool touched, bool isLeftHand) { |