History

better calibration event

Dante Ruiz committed 9 years ago

Commit c362ba91 parent d688b602 files · +20 −7Browse files

Showing the changes to plugins/openvr/src/ViveControllerManager.cpp (1 of 2 files). Show all

Unified · Split

plugins/openvr/src/ViveControllerManager.cpp+18−7
@@ -21,6 +21,7 @@ · 20 unmodified lines
2121 #include <NumericalConstants.h>
2222 #include <ui-plugins/PluginContainer.h>
2323 #include <UserActivityLogger.h>
24+#include <NumericalConstants.h>
2425 #include <OffscreenUi.h>
2526 #include <GLMHelpers.h>
2627 #include <glm/ext.hpp>
@@ -40,6 +41,7 @@ void releaseOpenVrSystem(); · 13 unmodified lines
4041
4142
4243 static const char* CONTROLLER_MODEL_STRING = "vr_controller_05_wireless_b";
44+const quint64 CALIBRATION_TIMELAPSE = 3 * USECS_PER_SECOND;
4345
4446 static const char* MENU_PARENT = "Avatar";
4547 static const char* MENU_NAME = "Vive Controllers";
@@ -188,12 +190,19 @@ void ViveControllerManager::InputDevice::update(float deltaTime, const controlle · 142 unmodified lines
188190 _trackedControllers = numTrackedControllers;
189191
190192 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) {
192200 _triggersPressedHandled = true;
193201 calibrateOrUncalibrate(inputCalibrationData);
194202 }
195203 } else {
196204 _triggersPressedHandled = false;
205+ _timeTilCalibrationSet = false;
197206 }
198207
199208 updateCalibratedLimbs();
@@ -232,12 +241,6 @@ void ViveControllerManager::InputDevice::calibrateOrUncalibrate(const controller · 32 unmodified lines
232241 }
233242 }
234243
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−
241244 void ViveControllerManager::InputDevice::calibrate(const controller::InputCalibrationData& inputCalibration) {
242245 // convert the hmd head from sensor space to avatar space
243246 glm::mat4 hmdSensorFlippedMat = inputCalibration.hmdSensorMat * Matrices::Y_180;
@@ -416,6 +419,14 @@ enum ViveButtonChannel { · 172 unmodified lines
416419 RIGHT_APP_MENU
417420 };
418421
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+}
419430
420431 // These functions do translation from the Steam IDs to the standard controller IDs
421432 void ViveControllerManager::InputDevice::handleButtonEvent(float deltaTime, uint32_t button, bool pressed, bool touched, bool isLeftHand) {