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
21#include <NumericalConstants.h>21#include <NumericalConstants.h>
22#include <ui-plugins/PluginContainer.h>22#include <ui-plugins/PluginContainer.h>
23#include <UserActivityLogger.h>23#include <UserActivityLogger.h>
24#include <NumericalConstants.h>
24#include <OffscreenUi.h>25#include <OffscreenUi.h>
25#include <GLMHelpers.h>26#include <GLMHelpers.h>
26#include <glm/ext.hpp>27#include <glm/ext.hpp>
@@ -40,6 +41,7 @@ void releaseOpenVrSystem(); · 13 unmodified lines
40 41
41 42
42static const char* CONTROLLER_MODEL_STRING = "vr_controller_05_wireless_b";43static const char* CONTROLLER_MODEL_STRING = "vr_controller_05_wireless_b";
44const quint64 CALIBRATION_TIMELAPSE = 3 * USECS_PER_SECOND;
43 45
44static const char* MENU_PARENT = "Avatar";46static const char* MENU_PARENT = "Avatar";
45static const char* MENU_NAME = "Vive Controllers";47static const char* MENU_NAME = "Vive Controllers";
@@ -188,12 +190,19 @@ void ViveControllerManager::InputDevice::update(float deltaTime, const controlle · 142 unmodified lines
188 _trackedControllers = numTrackedControllers;190 _trackedControllers = numTrackedControllers;
189 191
190 if (checkForCalibrationEvent()) {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 _triggersPressedHandled = true;200 _triggersPressedHandled = true;
193 calibrateOrUncalibrate(inputCalibrationData);201 calibrateOrUncalibrate(inputCalibrationData);
194 }202 }
195 } else {203 } else {
196 _triggersPressedHandled = false;204 _triggersPressedHandled = false;
205 _timeTilCalibrationSet = false;
197 }206 }
198 207
199 updateCalibratedLimbs();208 updateCalibratedLimbs();
@@ -232,12 +241,6 @@ void ViveControllerManager::InputDevice::calibrateOrUncalibrate(const controller · 32 unmodified lines
232 }241 }
233}242}
234 243
235bool 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
241void ViveControllerManager::InputDevice::calibrate(const controller::InputCalibrationData& inputCalibration) {244void ViveControllerManager::InputDevice::calibrate(const controller::InputCalibrationData& inputCalibration) {
242 // convert the hmd head from sensor space to avatar space245 // convert the hmd head from sensor space to avatar space
243 glm::mat4 hmdSensorFlippedMat = inputCalibration.hmdSensorMat * Matrices::Y_180;246 glm::mat4 hmdSensorFlippedMat = inputCalibration.hmdSensorMat * Matrices::Y_180;
@@ -416,6 +419,14 @@ enum ViveButtonChannel { · 172 unmodified lines
416 RIGHT_APP_MENU419 RIGHT_APP_MENU
417};420};
418 421
422bool 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// These functions do translation from the Steam IDs to the standard controller IDs431// These functions do translation from the Steam IDs to the standard controller IDs
421void ViveControllerManager::InputDevice::handleButtonEvent(float deltaTime, uint32_t button, bool pressed, bool touched, bool isLeftHand) {432void ViveControllerManager::InputDevice::handleButtonEvent(float deltaTime, uint32_t button, bool pressed, bool touched, bool isLeftHand) {