From 1f664671f91070e868f4a29b12835b588670d200 Mon Sep 17 00:00:00 2001 From: howard-stearns Date: Fri, 13 May 2016 14:32:54 -0700 Subject: [PATCH 01/13] Remove overlay when velocity first indicates travel, and restore it (with reset) when returning to reset. --- interface/src/ui/OverlayConductor.cpp | 48 ++++++++++++++++++++++----- interface/src/ui/OverlayConductor.h | 4 ++- 2 files changed, 43 insertions(+), 9 deletions(-) diff --git a/interface/src/ui/OverlayConductor.cpp b/interface/src/ui/OverlayConductor.cpp index 95054869e5..543a500188 100644 --- a/interface/src/ui/OverlayConductor.cpp +++ b/interface/src/ui/OverlayConductor.cpp @@ -67,6 +67,32 @@ void OverlayConductor::update(float dt) { } void OverlayConductor::updateMode() { + MyAvatar* myAvatar = DependencyManager::get()->getMyAvatar(); + float speed = glm::length(myAvatar->getVelocity()); + bool nowDriving = _driving; + const float MIN_DRIVING = 0.2; + const float MAX_NOT_DRIVING = 0.01; + if (speed > MIN_DRIVING) { + nowDriving = true; + } + else if (speed < MAX_NOT_DRIVING) { + nowDriving = false; + } + if (nowDriving != _driving) { + if (nowDriving) { + _wantsOverlays = Menu::getInstance()->isOptionChecked(MenuOption::Overlays); + } + else { // reset when coming out of driving + _mode = FLAT; // Seems appropriate to let things reset, below, after the following. + // All reset of, e.g., room-scale location as though by apostrophe key, without all the other adjustments. + qApp->getActiveDisplayPlugin()->resetSensors(); + } + if (_wantsOverlays) { + qDebug() << "flipping" << !nowDriving; + setEnabled(!nowDriving, false); + } + _driving = nowDriving; + } Mode newMode; if (qApp->isHMDMode()) { @@ -84,10 +110,9 @@ void OverlayConductor::updateMode() { qApp->getApplicationCompositor().setModelTransform(identity); break; } - case STANDING: { + case STANDING: { // STANDING mode is not currently used. // enter the STANDING state // place the overlay at the current hmd position in world space - MyAvatar* myAvatar = DependencyManager::get()->getMyAvatar(); auto camMat = cancelOutRollAndPitch(myAvatar->getSensorToWorldMatrix() * qApp->getHMDSensorPose()); Transform t; t.setTranslation(extractTranslation(camMat)); @@ -103,15 +128,18 @@ void OverlayConductor::updateMode() { } _mode = newMode; + } -void OverlayConductor::setEnabled(bool enabled) { +void OverlayConductor::setEnabled(bool enabled, bool toggleQmlEvents) { if (enabled == _enabled) { return; } - Menu::getInstance()->setIsOptionChecked(MenuOption::Overlays, enabled); + if (toggleQmlEvents) { // Could recurse on us with the wrong toggleQmlEvents flag, and not need in the !toggleQmlEvent case anyway. + Menu::getInstance()->setIsOptionChecked(MenuOption::Overlays, enabled); + } _enabled = enabled; // set the new value @@ -124,8 +152,10 @@ void OverlayConductor::setEnabled(bool enabled) { qApp->getOverlays().enable(); // enable QML events - auto offscreenUi = DependencyManager::get(); - offscreenUi->getRootItem()->setEnabled(true); + if (toggleQmlEvents) { + auto offscreenUi = DependencyManager::get(); + offscreenUi->getRootItem()->setEnabled(true); + } if (_mode == STANDING) { // place the overlay at the current hmd position in world space @@ -144,8 +174,10 @@ void OverlayConductor::setEnabled(bool enabled) { qApp->getOverlays().disable(); // disable QML events - auto offscreenUi = DependencyManager::get(); - offscreenUi->getRootItem()->setEnabled(false); + if (toggleQmlEvents) { // I'd really rather always do this, but it looses drive state. bugzid:501 + auto offscreenUi = DependencyManager::get(); + offscreenUi->getRootItem()->setEnabled(false); + } } } diff --git a/interface/src/ui/OverlayConductor.h b/interface/src/ui/OverlayConductor.h index b94c5be7dd..02b2035b07 100644 --- a/interface/src/ui/OverlayConductor.h +++ b/interface/src/ui/OverlayConductor.h @@ -17,7 +17,7 @@ public: ~OverlayConductor(); void update(float dt); - void setEnabled(bool enable); + void setEnabled(bool enable, bool toggleQmlEvents = true); bool getEnabled() const; private: @@ -31,6 +31,8 @@ private: Mode _mode { FLAT }; bool _enabled { false }; + bool _driving { false }; + bool _wantsOverlays { true }; }; #endif From 654ed33dd4e870a6f1973ef6efe0b3b31b4b93dd Mon Sep 17 00:00:00 2001 From: howard-stearns Date: Fri, 13 May 2016 15:32:59 -0700 Subject: [PATCH 02/13] Fix warnings. --- interface/src/ui/OverlayConductor.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interface/src/ui/OverlayConductor.cpp b/interface/src/ui/OverlayConductor.cpp index 543a500188..b44ea91a60 100644 --- a/interface/src/ui/OverlayConductor.cpp +++ b/interface/src/ui/OverlayConductor.cpp @@ -70,8 +70,8 @@ void OverlayConductor::updateMode() { MyAvatar* myAvatar = DependencyManager::get()->getMyAvatar(); float speed = glm::length(myAvatar->getVelocity()); bool nowDriving = _driving; - const float MIN_DRIVING = 0.2; - const float MAX_NOT_DRIVING = 0.01; + const float MIN_DRIVING = 0.2f; + const float MAX_NOT_DRIVING = 0.01f; if (speed > MIN_DRIVING) { nowDriving = true; } From 8381e74fb3478750362de176aa0710b369469c0f Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Thu, 19 May 2016 13:56:40 -0700 Subject: [PATCH 03/13] OpenVRDispalyPlugin: fix one-frame lag in resetSensors. resetSensors() should take place immediately, so that the getHeadPose() after the reset should be identity. (or close to it) --- plugins/openvr/src/OpenVrDisplayPlugin.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/plugins/openvr/src/OpenVrDisplayPlugin.cpp b/plugins/openvr/src/OpenVrDisplayPlugin.cpp index 38719fdca5..1f6b11f862 100644 --- a/plugins/openvr/src/OpenVrDisplayPlugin.cpp +++ b/plugins/openvr/src/OpenVrDisplayPlugin.cpp @@ -122,7 +122,19 @@ void OpenVrDisplayPlugin::customizeContext() { void OpenVrDisplayPlugin::resetSensors() { Lock lock(_poseMutex); glm::mat4 m = toGlm(_trackedDevicePose[0].mDeviceToAbsoluteTracking); + + glm::mat4 oldSensorResetMat = _sensorResetMat; _sensorResetMat = glm::inverse(cancelOutRollAndPitch(m)); + + glm::mat4 undoRedoMat = _sensorResetMat * glm::inverse(oldSensorResetMat); + + // update the device poses, by undoing the previous sensorResetMatrix then applying the new one. + for (int i = 0; i < vr::k_unMaxTrackedDeviceCount; i++) { + _trackedDevicePoseMat4[i] = undoRedoMat * _trackedDevicePoseMat4[i]; + _trackedDeviceLinearVelocities[i] = transformVectorFast(undoRedoMat, _trackedDeviceLinearVelocities[i]); + _trackedDeviceAngularVelocities[i] = transformVectorFast(undoRedoMat, _trackedDeviceAngularVelocities[i]); + } + _currentRenderFrameInfo.renderPose = _trackedDevicePoseMat4[vr::k_unTrackedDeviceIndex_Hmd]; } From 7f131e2c4fe06eb2d2faf3901ebcece4ec3c14ec Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Thu, 19 May 2016 15:00:08 -0700 Subject: [PATCH 04/13] Reset avatar as well as displayPlugin when "driving" --- interface/src/avatar/MyAvatar.cpp | 6 ++++-- interface/src/avatar/MyAvatar.h | 2 +- interface/src/ui/OverlayConductor.cpp | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index a3cf1f9f4f..183a24f252 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -234,7 +234,7 @@ QByteArray MyAvatar::toByteArray(bool cullSmallChanges, bool sendAll) { return AvatarData::toByteArray(cullSmallChanges, sendAll); } -void MyAvatar::reset(bool andRecenter) { +void MyAvatar::reset(bool andRecenter, bool andReload) { if (QThread::currentThread() != thread()) { QMetaObject::invokeMethod(this, "reset", Q_ARG(bool, andRecenter)); @@ -244,7 +244,9 @@ void MyAvatar::reset(bool andRecenter) { // Reset dynamic state. _wasPushing = _isPushing = _isBraking = false; _follow.deactivate(); - _skeletonModel->reset(); + if (andReload) { + _skeletonModel->reset(); + } getHead()->reset(); _targetVelocity = glm::vec3(0.0f); setThrust(glm::vec3(0.0f)); diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 66e6af340e..d7af6b5683 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -94,7 +94,7 @@ public: AudioListenerMode getAudioListenerModeCamera() const { return FROM_CAMERA; } AudioListenerMode getAudioListenerModeCustom() const { return CUSTOM; } - Q_INVOKABLE void reset(bool andRecenter = false); + Q_INVOKABLE void reset(bool andRecenter = false, bool andReload = true); void update(float deltaTime); virtual void postUpdate(float deltaTime) override; void preDisplaySide(RenderArgs* renderArgs); diff --git a/interface/src/ui/OverlayConductor.cpp b/interface/src/ui/OverlayConductor.cpp index b44ea91a60..1ceceb741e 100644 --- a/interface/src/ui/OverlayConductor.cpp +++ b/interface/src/ui/OverlayConductor.cpp @@ -86,6 +86,7 @@ void OverlayConductor::updateMode() { _mode = FLAT; // Seems appropriate to let things reset, below, after the following. // All reset of, e.g., room-scale location as though by apostrophe key, without all the other adjustments. qApp->getActiveDisplayPlugin()->resetSensors(); + myAvatar->reset(true, false); } if (_wantsOverlays) { qDebug() << "flipping" << !nowDriving; From 6568c0563de1c8b95f47be2b1a5dc0a7bdf7cc67 Mon Sep 17 00:00:00 2001 From: howard-stearns Date: Fri, 20 May 2016 16:43:55 -0700 Subject: [PATCH 05/13] Delay on entry/exit. --- interface/src/ui/OverlayConductor.cpp | 26 +++++++++++++++++++------- interface/src/ui/OverlayConductor.h | 1 + 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/interface/src/ui/OverlayConductor.cpp b/interface/src/ui/OverlayConductor.cpp index 1ceceb741e..e9dc766e73 100644 --- a/interface/src/ui/OverlayConductor.cpp +++ b/interface/src/ui/OverlayConductor.cpp @@ -69,27 +69,39 @@ void OverlayConductor::update(float dt) { void OverlayConductor::updateMode() { MyAvatar* myAvatar = DependencyManager::get()->getMyAvatar(); float speed = glm::length(myAvatar->getVelocity()); - bool nowDriving = _driving; const float MIN_DRIVING = 0.2f; const float MAX_NOT_DRIVING = 0.01f; - if (speed > MIN_DRIVING) { + const quint64 REQUIRED_USECS_IN_NEW_MODE_BEFORE_INVISIBLE = 200 * 1000; + const quint64 REQUIRED_USECS_IN_NEW_MODE_BEFORE_VISIBLE = 1000 * 1000; + int fixmeDiff; + bool nowDriving = _driving; // Assume current _driving mode unless... + if (speed > MIN_DRIVING) { // ... we're definitely moving... nowDriving = true; - } - else if (speed < MAX_NOT_DRIVING) { + } else if (speed < MAX_NOT_DRIVING) { // ... or definitely not. nowDriving = false; } + // Check that we're in this new mode for long enough to really trigger a transition. + if (nowDriving == _driving) { // If there's no change in state, clear any attepted timer. + _timeInPotentialMode = 0; + } else if (_timeInPotentialMode == 0) { // We've just changed with no timer, so start timing now. + _timeInPotentialMode = usecTimestampNow(); + nowDriving = _driving; + } else if ((fixmeDiff = (usecTimestampNow() - _timeInPotentialMode)) < (nowDriving ? REQUIRED_USECS_IN_NEW_MODE_BEFORE_INVISIBLE : REQUIRED_USECS_IN_NEW_MODE_BEFORE_VISIBLE)) { + nowDriving = _driving; // Haven't accumulated enough time in new mode, but keep timing. + } else { // a real transition + _timeInPotentialMode = 0; + } + // If we're really in a transition if (nowDriving != _driving) { if (nowDriving) { _wantsOverlays = Menu::getInstance()->isOptionChecked(MenuOption::Overlays); - } - else { // reset when coming out of driving + } else { // reset when coming out of driving _mode = FLAT; // Seems appropriate to let things reset, below, after the following. // All reset of, e.g., room-scale location as though by apostrophe key, without all the other adjustments. qApp->getActiveDisplayPlugin()->resetSensors(); myAvatar->reset(true, false); } if (_wantsOverlays) { - qDebug() << "flipping" << !nowDriving; setEnabled(!nowDriving, false); } _driving = nowDriving; diff --git a/interface/src/ui/OverlayConductor.h b/interface/src/ui/OverlayConductor.h index 02b2035b07..99f4b56584 100644 --- a/interface/src/ui/OverlayConductor.h +++ b/interface/src/ui/OverlayConductor.h @@ -32,6 +32,7 @@ private: Mode _mode { FLAT }; bool _enabled { false }; bool _driving { false }; + quint64 _timeInPotentialMode { 0 }; bool _wantsOverlays { true }; }; From 9a428947e4f9fa6c51e76d69d385dc2eec33b945 Mon Sep 17 00:00:00 2001 From: howard-stearns Date: Fri, 20 May 2016 16:50:17 -0700 Subject: [PATCH 06/13] Simplify code. --- interface/src/ui/OverlayConductor.cpp | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/interface/src/ui/OverlayConductor.cpp b/interface/src/ui/OverlayConductor.cpp index e9dc766e73..fa74989f4f 100644 --- a/interface/src/ui/OverlayConductor.cpp +++ b/interface/src/ui/OverlayConductor.cpp @@ -73,7 +73,6 @@ void OverlayConductor::updateMode() { const float MAX_NOT_DRIVING = 0.01f; const quint64 REQUIRED_USECS_IN_NEW_MODE_BEFORE_INVISIBLE = 200 * 1000; const quint64 REQUIRED_USECS_IN_NEW_MODE_BEFORE_VISIBLE = 1000 * 1000; - int fixmeDiff; bool nowDriving = _driving; // Assume current _driving mode unless... if (speed > MIN_DRIVING) { // ... we're definitely moving... nowDriving = true; @@ -85,14 +84,8 @@ void OverlayConductor::updateMode() { _timeInPotentialMode = 0; } else if (_timeInPotentialMode == 0) { // We've just changed with no timer, so start timing now. _timeInPotentialMode = usecTimestampNow(); - nowDriving = _driving; - } else if ((fixmeDiff = (usecTimestampNow() - _timeInPotentialMode)) < (nowDriving ? REQUIRED_USECS_IN_NEW_MODE_BEFORE_INVISIBLE : REQUIRED_USECS_IN_NEW_MODE_BEFORE_VISIBLE)) { - nowDriving = _driving; // Haven't accumulated enough time in new mode, but keep timing. - } else { // a real transition - _timeInPotentialMode = 0; - } - // If we're really in a transition - if (nowDriving != _driving) { + } else if ((usecTimestampNow() - _timeInPotentialMode) > (nowDriving ? REQUIRED_USECS_IN_NEW_MODE_BEFORE_INVISIBLE : REQUIRED_USECS_IN_NEW_MODE_BEFORE_VISIBLE)) { + _timeInPotentialMode = 0; // a real transition if (nowDriving) { _wantsOverlays = Menu::getInstance()->isOptionChecked(MenuOption::Overlays); } else { // reset when coming out of driving @@ -105,7 +98,7 @@ void OverlayConductor::updateMode() { setEnabled(!nowDriving, false); } _driving = nowDriving; - } + } // Else haven't accumulated enough time in new mode, but keep timing. Mode newMode; if (qApp->isHMDMode()) { From 097b16aadc5e0f135e2df0a93a6bf7a939abccbe Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Mon, 23 May 2016 15:40:29 -0700 Subject: [PATCH 07/13] Fix for sensor reset on oculus. --- plugins/oculus/src/OculusBaseDisplayPlugin.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/oculus/src/OculusBaseDisplayPlugin.cpp b/plugins/oculus/src/OculusBaseDisplayPlugin.cpp index a92c5b5b22..3b6545ae96 100644 --- a/plugins/oculus/src/OculusBaseDisplayPlugin.cpp +++ b/plugins/oculus/src/OculusBaseDisplayPlugin.cpp @@ -13,6 +13,8 @@ void OculusBaseDisplayPlugin::resetSensors() { ovr_RecenterTrackingOrigin(_session); + + _currentRenderFrameInfo.renderPose = glm::mat4(); // identity } void OculusBaseDisplayPlugin::beginFrameRender(uint32_t frameIndex) { From f82c3ba4f2e39e106a634d637c9ebbcbc585cb4a Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Mon, 23 May 2016 16:30:05 -0700 Subject: [PATCH 08/13] Revert "OpenVRDispalyPlugin: fix one-frame lag in resetSensors." This reverts commit 8381e74fb3478750362de176aa0710b369469c0f. --- plugins/openvr/src/OpenVrDisplayPlugin.cpp | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/plugins/openvr/src/OpenVrDisplayPlugin.cpp b/plugins/openvr/src/OpenVrDisplayPlugin.cpp index 1f6b11f862..38719fdca5 100644 --- a/plugins/openvr/src/OpenVrDisplayPlugin.cpp +++ b/plugins/openvr/src/OpenVrDisplayPlugin.cpp @@ -122,19 +122,7 @@ void OpenVrDisplayPlugin::customizeContext() { void OpenVrDisplayPlugin::resetSensors() { Lock lock(_poseMutex); glm::mat4 m = toGlm(_trackedDevicePose[0].mDeviceToAbsoluteTracking); - - glm::mat4 oldSensorResetMat = _sensorResetMat; _sensorResetMat = glm::inverse(cancelOutRollAndPitch(m)); - - glm::mat4 undoRedoMat = _sensorResetMat * glm::inverse(oldSensorResetMat); - - // update the device poses, by undoing the previous sensorResetMatrix then applying the new one. - for (int i = 0; i < vr::k_unMaxTrackedDeviceCount; i++) { - _trackedDevicePoseMat4[i] = undoRedoMat * _trackedDevicePoseMat4[i]; - _trackedDeviceLinearVelocities[i] = transformVectorFast(undoRedoMat, _trackedDeviceLinearVelocities[i]); - _trackedDeviceAngularVelocities[i] = transformVectorFast(undoRedoMat, _trackedDeviceAngularVelocities[i]); - } - _currentRenderFrameInfo.renderPose = _trackedDevicePoseMat4[vr::k_unTrackedDeviceIndex_Hmd]; } From edfce0d5badcac66e0b857c24b47875c37d33b04 Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Mon, 23 May 2016 16:34:19 -0700 Subject: [PATCH 09/13] MyAvatar: reset fix, for both oculus and vive --- interface/src/avatar/MyAvatar.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 2505e258ed..12d2764e74 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -263,8 +263,9 @@ void MyAvatar::reset(bool andRecenter, bool andReload) { setPosition(worldBodyPos); setOrientation(worldBodyRot); - // now sample the new hmd orientation AFTER sensor reset. - updateFromHMDSensorMatrix(qApp->getHMDSensorPose()); + // now sample the new hmd orientation AFTER sensor reset, which should be identity. + glm::mat4 identity; + updateFromHMDSensorMatrix(identity); // update the body in sensor space using the new hmd sensor sample _bodySensorMatrix = deriveBodyFromHMDSensor(); From 8198a1b4d110bd334fe7f272961148fa4caffa5f Mon Sep 17 00:00:00 2001 From: howard-stearns Date: Wed, 25 May 2016 11:30:45 -0700 Subject: [PATCH 10/13] Add preference to control behavior. --- interface/src/avatar/MyAvatar.cpp | 2 + interface/src/avatar/MyAvatar.h | 3 ++ interface/src/ui/OverlayConductor.cpp | 62 +++++++++++++------------- interface/src/ui/PreferencesDialog.cpp | 5 +++ 4 files changed, 42 insertions(+), 30 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 94b213420f..e1159cf962 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -733,6 +733,7 @@ void MyAvatar::saveData() { settings.setValue("displayName", _displayName); settings.setValue("collisionSoundURL", _collisionSoundURL); settings.setValue("useSnapTurn", _useSnapTurn); + settings.setValue("clearOverlayWhenDriving", _clearOverlayWhenDriving); settings.endGroup(); } @@ -855,6 +856,7 @@ void MyAvatar::loadData() { setDisplayName(settings.value("displayName").toString()); setCollisionSoundURL(settings.value("collisionSoundURL", DEFAULT_AVATAR_COLLISION_SOUND_URL).toString()); setSnapTurn(settings.value("useSnapTurn", _useSnapTurn).toBool()); + setSnapTurn(settings.value("clearOverlayWhenDriving", _clearOverlayWhenDriving).toBool()); settings.endGroup(); diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 92f006feb8..135e9f6417 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -160,6 +160,8 @@ public: Q_INVOKABLE bool getSnapTurn() const { return _useSnapTurn; } Q_INVOKABLE void setSnapTurn(bool on) { _useSnapTurn = on; } + Q_INVOKABLE bool getClearOverlayWhenDriving() const { return _clearOverlayWhenDriving; } + Q_INVOKABLE void setClearOverlayWhenDriving(bool on) { _clearOverlayWhenDriving = on; } // get/set avatar data void saveData(); @@ -396,6 +398,7 @@ private: QString _fullAvatarModelName; QUrl _animGraphUrl {""}; bool _useSnapTurn { true }; + bool _clearOverlayWhenDriving { true }; // cache of the current HMD sensor position and orientation // in sensor space. diff --git a/interface/src/ui/OverlayConductor.cpp b/interface/src/ui/OverlayConductor.cpp index fa74989f4f..cb211fd918 100644 --- a/interface/src/ui/OverlayConductor.cpp +++ b/interface/src/ui/OverlayConductor.cpp @@ -68,37 +68,39 @@ void OverlayConductor::update(float dt) { void OverlayConductor::updateMode() { MyAvatar* myAvatar = DependencyManager::get()->getMyAvatar(); - float speed = glm::length(myAvatar->getVelocity()); - const float MIN_DRIVING = 0.2f; - const float MAX_NOT_DRIVING = 0.01f; - const quint64 REQUIRED_USECS_IN_NEW_MODE_BEFORE_INVISIBLE = 200 * 1000; - const quint64 REQUIRED_USECS_IN_NEW_MODE_BEFORE_VISIBLE = 1000 * 1000; - bool nowDriving = _driving; // Assume current _driving mode unless... - if (speed > MIN_DRIVING) { // ... we're definitely moving... - nowDriving = true; - } else if (speed < MAX_NOT_DRIVING) { // ... or definitely not. - nowDriving = false; + if (myAvatar->getClearOverlayWhenDriving()) { + float speed = glm::length(myAvatar->getVelocity()); + const float MIN_DRIVING = 0.2f; + const float MAX_NOT_DRIVING = 0.01f; + const quint64 REQUIRED_USECS_IN_NEW_MODE_BEFORE_INVISIBLE = 200 * 1000; + const quint64 REQUIRED_USECS_IN_NEW_MODE_BEFORE_VISIBLE = 1000 * 1000; + bool nowDriving = _driving; // Assume current _driving mode unless... + if (speed > MIN_DRIVING) { // ... we're definitely moving... + nowDriving = true; + } else if (speed < MAX_NOT_DRIVING) { // ... or definitely not. + nowDriving = false; + } + // Check that we're in this new mode for long enough to really trigger a transition. + if (nowDriving == _driving) { // If there's no change in state, clear any attepted timer. + _timeInPotentialMode = 0; + } else if (_timeInPotentialMode == 0) { // We've just changed with no timer, so start timing now. + _timeInPotentialMode = usecTimestampNow(); + } else if ((usecTimestampNow() - _timeInPotentialMode) > (nowDriving ? REQUIRED_USECS_IN_NEW_MODE_BEFORE_INVISIBLE : REQUIRED_USECS_IN_NEW_MODE_BEFORE_VISIBLE)) { + _timeInPotentialMode = 0; // a real transition + if (nowDriving) { + _wantsOverlays = Menu::getInstance()->isOptionChecked(MenuOption::Overlays); + } else { // reset when coming out of driving + _mode = FLAT; // Seems appropriate to let things reset, below, after the following. + // All reset of, e.g., room-scale location as though by apostrophe key, without all the other adjustments. + qApp->getActiveDisplayPlugin()->resetSensors(); + myAvatar->reset(true, false); + } + if (_wantsOverlays) { + setEnabled(!nowDriving, false); + } + _driving = nowDriving; + } // Else haven't accumulated enough time in new mode, but keep timing. } - // Check that we're in this new mode for long enough to really trigger a transition. - if (nowDriving == _driving) { // If there's no change in state, clear any attepted timer. - _timeInPotentialMode = 0; - } else if (_timeInPotentialMode == 0) { // We've just changed with no timer, so start timing now. - _timeInPotentialMode = usecTimestampNow(); - } else if ((usecTimestampNow() - _timeInPotentialMode) > (nowDriving ? REQUIRED_USECS_IN_NEW_MODE_BEFORE_INVISIBLE : REQUIRED_USECS_IN_NEW_MODE_BEFORE_VISIBLE)) { - _timeInPotentialMode = 0; // a real transition - if (nowDriving) { - _wantsOverlays = Menu::getInstance()->isOptionChecked(MenuOption::Overlays); - } else { // reset when coming out of driving - _mode = FLAT; // Seems appropriate to let things reset, below, after the following. - // All reset of, e.g., room-scale location as though by apostrophe key, without all the other adjustments. - qApp->getActiveDisplayPlugin()->resetSensors(); - myAvatar->reset(true, false); - } - if (_wantsOverlays) { - setEnabled(!nowDriving, false); - } - _driving = nowDriving; - } // Else haven't accumulated enough time in new mode, but keep timing. Mode newMode; if (qApp->isHMDMode()) { diff --git a/interface/src/ui/PreferencesDialog.cpp b/interface/src/ui/PreferencesDialog.cpp index 9b1146340e..8f60844cc3 100644 --- a/interface/src/ui/PreferencesDialog.cpp +++ b/interface/src/ui/PreferencesDialog.cpp @@ -61,6 +61,11 @@ void setupPreferences() { auto setter = [=](bool value) { myAvatar->setSnapTurn(value); }; preferences->addPreference(new CheckPreference(AVATAR_BASICS, "Snap turn when in HMD", getter, setter)); } + { + auto getter = [=]()->bool {return myAvatar->getClearOverlayWhenDriving(); }; + auto setter = [=](bool value) { myAvatar->setClearOverlayWhenDriving(value); }; + preferences->addPreference(new CheckPreference(AVATAR_BASICS, "Clear overlays when driving", getter, setter)); + } { auto getter = []()->QString { return Snapshot::snapshotsLocation.get(); }; auto setter = [](const QString& value) { Snapshot::snapshotsLocation.set(value); }; From dc7d6d470ddc6ba5866131dc04a32c1cb7de5bee Mon Sep 17 00:00:00 2001 From: howard-stearns Date: Wed, 25 May 2016 12:21:50 -0700 Subject: [PATCH 11/13] Don't reset head when we come back. --- interface/src/avatar/MyAvatar.cpp | 6 ++++-- interface/src/avatar/MyAvatar.h | 2 +- interface/src/ui/OverlayConductor.cpp | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 04224d6fa9..358b3d72ba 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -234,7 +234,7 @@ QByteArray MyAvatar::toByteArray(bool cullSmallChanges, bool sendAll) { return AvatarData::toByteArray(cullSmallChanges, sendAll); } -void MyAvatar::reset(bool andRecenter, bool andReload) { +void MyAvatar::reset(bool andRecenter, bool andReload, bool andHead) { if (QThread::currentThread() != thread()) { QMetaObject::invokeMethod(this, "reset", Q_ARG(bool, andRecenter)); @@ -247,7 +247,9 @@ void MyAvatar::reset(bool andRecenter, bool andReload) { if (andReload) { _skeletonModel->reset(); } - getHead()->reset(); + if (andHead) { // which drives camera in desktop + getHead()->reset(); + } setThrust(glm::vec3(0.0f)); if (andRecenter) { diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 135e9f6417..f709f79542 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -94,7 +94,7 @@ public: AudioListenerMode getAudioListenerModeCamera() const { return FROM_CAMERA; } AudioListenerMode getAudioListenerModeCustom() const { return CUSTOM; } - Q_INVOKABLE void reset(bool andRecenter = false, bool andReload = true); + Q_INVOKABLE void reset(bool andRecenter = false, bool andReload = true, bool andHead = true); void update(float deltaTime); virtual void postUpdate(float deltaTime) override; void preDisplaySide(RenderArgs* renderArgs); diff --git a/interface/src/ui/OverlayConductor.cpp b/interface/src/ui/OverlayConductor.cpp index cb211fd918..83d729779c 100644 --- a/interface/src/ui/OverlayConductor.cpp +++ b/interface/src/ui/OverlayConductor.cpp @@ -93,7 +93,7 @@ void OverlayConductor::updateMode() { _mode = FLAT; // Seems appropriate to let things reset, below, after the following. // All reset of, e.g., room-scale location as though by apostrophe key, without all the other adjustments. qApp->getActiveDisplayPlugin()->resetSensors(); - myAvatar->reset(true, false); + myAvatar->reset(true, false, false); } if (_wantsOverlays) { setEnabled(!nowDriving, false); From 991da9e248338898b7ac582a5acaa81fd9d9e83e Mon Sep 17 00:00:00 2001 From: howard-stearns Date: Thu, 26 May 2016 09:51:55 -0700 Subject: [PATCH 12/13] fix cut-paste error in settings. --- interface/src/avatar/MyAvatar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 358b3d72ba..babbcfadbe 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -859,7 +859,7 @@ void MyAvatar::loadData() { setDisplayName(settings.value("displayName").toString()); setCollisionSoundURL(settings.value("collisionSoundURL", DEFAULT_AVATAR_COLLISION_SOUND_URL).toString()); setSnapTurn(settings.value("useSnapTurn", _useSnapTurn).toBool()); - setSnapTurn(settings.value("clearOverlayWhenDriving", _clearOverlayWhenDriving).toBool()); + setClearOverlayWhenDriving(settings.value("clearOverlayWhenDriving", _clearOverlayWhenDriving).toBool()); settings.endGroup(); From 5b6660e7ea23e0561fc709821cf93fef7e457c43 Mon Sep 17 00:00:00 2001 From: Howard Stearns Date: Fri, 27 May 2016 10:35:46 -0700 Subject: [PATCH 13/13] Default preference to false. --- interface/src/avatar/MyAvatar.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index f709f79542..d3da32e0ed 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -398,7 +398,7 @@ private: QString _fullAvatarModelName; QUrl _animGraphUrl {""}; bool _useSnapTurn { true }; - bool _clearOverlayWhenDriving { true }; + bool _clearOverlayWhenDriving { false }; // cache of the current HMD sensor position and orientation // in sensor space.