mirror of
https://github.com/overte-org/overte.git
synced 2025-04-14 07:47:30 +02:00
Merge pull request #7897 from howard-stearns/reset-hud-on-driving
reset hud on driving
This commit is contained in:
commit
76940bad34
6 changed files with 75 additions and 15 deletions
|
@ -234,7 +234,7 @@ QByteArray MyAvatar::toByteArray(bool cullSmallChanges, bool sendAll) {
|
||||||
return AvatarData::toByteArray(cullSmallChanges, sendAll);
|
return AvatarData::toByteArray(cullSmallChanges, sendAll);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyAvatar::reset(bool andRecenter) {
|
void MyAvatar::reset(bool andRecenter, bool andReload, bool andHead) {
|
||||||
|
|
||||||
if (QThread::currentThread() != thread()) {
|
if (QThread::currentThread() != thread()) {
|
||||||
QMetaObject::invokeMethod(this, "reset", Q_ARG(bool, andRecenter));
|
QMetaObject::invokeMethod(this, "reset", Q_ARG(bool, andRecenter));
|
||||||
|
@ -244,8 +244,12 @@ void MyAvatar::reset(bool andRecenter) {
|
||||||
// Reset dynamic state.
|
// Reset dynamic state.
|
||||||
_wasPushing = _isPushing = _isBraking = false;
|
_wasPushing = _isPushing = _isBraking = false;
|
||||||
_follow.deactivate();
|
_follow.deactivate();
|
||||||
_skeletonModel->reset();
|
if (andReload) {
|
||||||
getHead()->reset();
|
_skeletonModel->reset();
|
||||||
|
}
|
||||||
|
if (andHead) { // which drives camera in desktop
|
||||||
|
getHead()->reset();
|
||||||
|
}
|
||||||
setThrust(glm::vec3(0.0f));
|
setThrust(glm::vec3(0.0f));
|
||||||
|
|
||||||
if (andRecenter) {
|
if (andRecenter) {
|
||||||
|
@ -261,8 +265,9 @@ void MyAvatar::reset(bool andRecenter) {
|
||||||
setPosition(worldBodyPos);
|
setPosition(worldBodyPos);
|
||||||
setOrientation(worldBodyRot);
|
setOrientation(worldBodyRot);
|
||||||
|
|
||||||
// now sample the new hmd orientation AFTER sensor reset.
|
// now sample the new hmd orientation AFTER sensor reset, which should be identity.
|
||||||
updateFromHMDSensorMatrix(qApp->getHMDSensorPose());
|
glm::mat4 identity;
|
||||||
|
updateFromHMDSensorMatrix(identity);
|
||||||
|
|
||||||
// update the body in sensor space using the new hmd sensor sample
|
// update the body in sensor space using the new hmd sensor sample
|
||||||
_bodySensorMatrix = deriveBodyFromHMDSensor();
|
_bodySensorMatrix = deriveBodyFromHMDSensor();
|
||||||
|
@ -729,6 +734,7 @@ void MyAvatar::saveData() {
|
||||||
settings.setValue("displayName", _displayName);
|
settings.setValue("displayName", _displayName);
|
||||||
settings.setValue("collisionSoundURL", _collisionSoundURL);
|
settings.setValue("collisionSoundURL", _collisionSoundURL);
|
||||||
settings.setValue("useSnapTurn", _useSnapTurn);
|
settings.setValue("useSnapTurn", _useSnapTurn);
|
||||||
|
settings.setValue("clearOverlayWhenDriving", _clearOverlayWhenDriving);
|
||||||
|
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
}
|
}
|
||||||
|
@ -849,6 +855,7 @@ void MyAvatar::loadData() {
|
||||||
setDisplayName(settings.value("displayName").toString());
|
setDisplayName(settings.value("displayName").toString());
|
||||||
setCollisionSoundURL(settings.value("collisionSoundURL", DEFAULT_AVATAR_COLLISION_SOUND_URL).toString());
|
setCollisionSoundURL(settings.value("collisionSoundURL", DEFAULT_AVATAR_COLLISION_SOUND_URL).toString());
|
||||||
setSnapTurn(settings.value("useSnapTurn", _useSnapTurn).toBool());
|
setSnapTurn(settings.value("useSnapTurn", _useSnapTurn).toBool());
|
||||||
|
setClearOverlayWhenDriving(settings.value("clearOverlayWhenDriving", _clearOverlayWhenDriving).toBool());
|
||||||
|
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
|
|
|
@ -94,7 +94,7 @@ public:
|
||||||
AudioListenerMode getAudioListenerModeCamera() const { return FROM_CAMERA; }
|
AudioListenerMode getAudioListenerModeCamera() const { return FROM_CAMERA; }
|
||||||
AudioListenerMode getAudioListenerModeCustom() const { return CUSTOM; }
|
AudioListenerMode getAudioListenerModeCustom() const { return CUSTOM; }
|
||||||
|
|
||||||
Q_INVOKABLE void reset(bool andRecenter = false);
|
Q_INVOKABLE void reset(bool andRecenter = false, bool andReload = true, bool andHead = true);
|
||||||
void update(float deltaTime);
|
void update(float deltaTime);
|
||||||
virtual void postUpdate(float deltaTime) override;
|
virtual void postUpdate(float deltaTime) override;
|
||||||
void preDisplaySide(RenderArgs* renderArgs);
|
void preDisplaySide(RenderArgs* renderArgs);
|
||||||
|
@ -160,6 +160,8 @@ public:
|
||||||
|
|
||||||
Q_INVOKABLE bool getSnapTurn() const { return _useSnapTurn; }
|
Q_INVOKABLE bool getSnapTurn() const { return _useSnapTurn; }
|
||||||
Q_INVOKABLE void setSnapTurn(bool on) { _useSnapTurn = on; }
|
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
|
// get/set avatar data
|
||||||
void saveData();
|
void saveData();
|
||||||
|
@ -396,6 +398,7 @@ private:
|
||||||
QString _fullAvatarModelName;
|
QString _fullAvatarModelName;
|
||||||
QUrl _animGraphUrl {""};
|
QUrl _animGraphUrl {""};
|
||||||
bool _useSnapTurn { true };
|
bool _useSnapTurn { true };
|
||||||
|
bool _clearOverlayWhenDriving { false };
|
||||||
|
|
||||||
// cache of the current HMD sensor position and orientation
|
// cache of the current HMD sensor position and orientation
|
||||||
// in sensor space.
|
// in sensor space.
|
||||||
|
|
|
@ -67,6 +67,40 @@ void OverlayConductor::update(float dt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void OverlayConductor::updateMode() {
|
void OverlayConductor::updateMode() {
|
||||||
|
MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
|
||||||
|
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, false);
|
||||||
|
}
|
||||||
|
if (_wantsOverlays) {
|
||||||
|
setEnabled(!nowDriving, false);
|
||||||
|
}
|
||||||
|
_driving = nowDriving;
|
||||||
|
} // Else haven't accumulated enough time in new mode, but keep timing.
|
||||||
|
}
|
||||||
|
|
||||||
Mode newMode;
|
Mode newMode;
|
||||||
if (qApp->isHMDMode()) {
|
if (qApp->isHMDMode()) {
|
||||||
|
@ -84,10 +118,9 @@ void OverlayConductor::updateMode() {
|
||||||
qApp->getApplicationCompositor().setModelTransform(identity);
|
qApp->getApplicationCompositor().setModelTransform(identity);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case STANDING: {
|
case STANDING: { // STANDING mode is not currently used.
|
||||||
// enter the STANDING state
|
// enter the STANDING state
|
||||||
// place the overlay at the current hmd position in world space
|
// place the overlay at the current hmd position in world space
|
||||||
MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
|
|
||||||
auto camMat = cancelOutRollAndPitch(myAvatar->getSensorToWorldMatrix() * qApp->getHMDSensorPose());
|
auto camMat = cancelOutRollAndPitch(myAvatar->getSensorToWorldMatrix() * qApp->getHMDSensorPose());
|
||||||
Transform t;
|
Transform t;
|
||||||
t.setTranslation(extractTranslation(camMat));
|
t.setTranslation(extractTranslation(camMat));
|
||||||
|
@ -103,15 +136,18 @@ void OverlayConductor::updateMode() {
|
||||||
}
|
}
|
||||||
|
|
||||||
_mode = newMode;
|
_mode = newMode;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OverlayConductor::setEnabled(bool enabled) {
|
void OverlayConductor::setEnabled(bool enabled, bool toggleQmlEvents) {
|
||||||
|
|
||||||
if (enabled == _enabled) {
|
if (enabled == _enabled) {
|
||||||
return;
|
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
|
_enabled = enabled; // set the new value
|
||||||
|
|
||||||
|
@ -124,8 +160,10 @@ void OverlayConductor::setEnabled(bool enabled) {
|
||||||
qApp->getOverlays().enable();
|
qApp->getOverlays().enable();
|
||||||
|
|
||||||
// enable QML events
|
// enable QML events
|
||||||
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
if (toggleQmlEvents) {
|
||||||
offscreenUi->getRootItem()->setEnabled(true);
|
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
||||||
|
offscreenUi->getRootItem()->setEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
if (_mode == STANDING) {
|
if (_mode == STANDING) {
|
||||||
// place the overlay at the current hmd position in world space
|
// place the overlay at the current hmd position in world space
|
||||||
|
@ -144,8 +182,10 @@ void OverlayConductor::setEnabled(bool enabled) {
|
||||||
qApp->getOverlays().disable();
|
qApp->getOverlays().disable();
|
||||||
|
|
||||||
// disable QML events
|
// disable QML events
|
||||||
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
if (toggleQmlEvents) { // I'd really rather always do this, but it looses drive state. bugzid:501
|
||||||
offscreenUi->getRootItem()->setEnabled(false);
|
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
||||||
|
offscreenUi->getRootItem()->setEnabled(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ public:
|
||||||
~OverlayConductor();
|
~OverlayConductor();
|
||||||
|
|
||||||
void update(float dt);
|
void update(float dt);
|
||||||
void setEnabled(bool enable);
|
void setEnabled(bool enable, bool toggleQmlEvents = true);
|
||||||
bool getEnabled() const;
|
bool getEnabled() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -31,6 +31,9 @@ private:
|
||||||
|
|
||||||
Mode _mode { FLAT };
|
Mode _mode { FLAT };
|
||||||
bool _enabled { false };
|
bool _enabled { false };
|
||||||
|
bool _driving { false };
|
||||||
|
quint64 _timeInPotentialMode { 0 };
|
||||||
|
bool _wantsOverlays { true };
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -61,6 +61,11 @@ void setupPreferences() {
|
||||||
auto setter = [=](bool value) { myAvatar->setSnapTurn(value); };
|
auto setter = [=](bool value) { myAvatar->setSnapTurn(value); };
|
||||||
preferences->addPreference(new CheckPreference(AVATAR_BASICS, "Snap turn when in HMD", getter, setter));
|
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 getter = []()->QString { return Snapshot::snapshotsLocation.get(); };
|
||||||
auto setter = [](const QString& value) { Snapshot::snapshotsLocation.set(value); };
|
auto setter = [](const QString& value) { Snapshot::snapshotsLocation.set(value); };
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
|
|
||||||
void OculusBaseDisplayPlugin::resetSensors() {
|
void OculusBaseDisplayPlugin::resetSensors() {
|
||||||
ovr_RecenterTrackingOrigin(_session);
|
ovr_RecenterTrackingOrigin(_session);
|
||||||
|
|
||||||
|
_currentRenderFrameInfo.renderPose = glm::mat4(); // identity
|
||||||
}
|
}
|
||||||
|
|
||||||
void OculusBaseDisplayPlugin::beginFrameRender(uint32_t frameIndex) {
|
void OculusBaseDisplayPlugin::beginFrameRender(uint32_t frameIndex) {
|
||||||
|
|
Loading…
Reference in a new issue