mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
VR overlay recenter now triggers on hasDriveInput rising edge
This commit is contained in:
parent
e5ce854d2a
commit
4d02e2010f
2 changed files with 6 additions and 40 deletions
|
@ -41,32 +41,6 @@ bool OverlayConductor::headNotCenteredInOverlay() const {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool OverlayConductor::updateAvatarIsAtRest() {
|
||||
auto myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
|
||||
|
||||
const quint64 REST_ENABLE_TIME_USECS = 1000 * 1000; // 1 s
|
||||
const quint64 REST_DISABLE_TIME_USECS = 200 * 1000; // 200 ms
|
||||
|
||||
const float AT_REST_THRESHOLD = 0.01f;
|
||||
bool desiredAtRest = glm::length(myAvatar->getWorldVelocity()) < AT_REST_THRESHOLD;
|
||||
if (desiredAtRest != _desiredAtRest) {
|
||||
// start timer
|
||||
_desiredAtRestTimer = usecTimestampNow() + (desiredAtRest ? REST_ENABLE_TIME_USECS : REST_DISABLE_TIME_USECS);
|
||||
}
|
||||
|
||||
_desiredAtRest = desiredAtRest;
|
||||
|
||||
if (_desiredAtRestTimer != 0 && usecTimestampNow() > _desiredAtRestTimer) {
|
||||
// timer expired
|
||||
// change state!
|
||||
_currentAtRest = _desiredAtRest;
|
||||
// disable timer
|
||||
_desiredAtRestTimer = 0;
|
||||
}
|
||||
|
||||
return _currentAtRest;
|
||||
}
|
||||
|
||||
void OverlayConductor::centerUI() {
|
||||
// place the overlay at the current hmd position in sensor space
|
||||
auto camMat = cancelOutRollAndPitch(qApp->getHMDSensorPose());
|
||||
|
@ -103,16 +77,12 @@ void OverlayConductor::update(float dt) {
|
|||
}
|
||||
|
||||
bool shouldRecenter = false;
|
||||
if (initiateRecenter || _suppressedByHead) {
|
||||
_suppressedByHead = !updateAvatarIsAtRest();
|
||||
shouldRecenter = !_suppressedByHead;
|
||||
}
|
||||
|
||||
bool currentVisible = !desktop->property("pinned").toBool();
|
||||
bool targetVisible = Menu::getInstance()->isOptionChecked(MenuOption::Overlays) && !_suppressedByHead;
|
||||
if (targetVisible != currentVisible) {
|
||||
offscreenUi->setPinned(!targetVisible);
|
||||
bool hasDriveInput = myAvatar->hasDriveInput();
|
||||
if (hasDriveInput && !_lastHasDriveInput && initiateRecenter) {
|
||||
shouldRecenter = true;
|
||||
}
|
||||
_lastHasDriveInput = hasDriveInput;
|
||||
|
||||
if (shouldRecenter) {
|
||||
centerUI();
|
||||
|
|
|
@ -23,17 +23,13 @@ public:
|
|||
|
||||
private:
|
||||
bool headNotCenteredInOverlay() const;
|
||||
bool updateAvatarIsAtRest();
|
||||
|
||||
#if !defined(DISABLE_QML)
|
||||
bool _suppressedByHead { false };
|
||||
bool _hmdMode { false };
|
||||
#endif
|
||||
|
||||
// used by updateAvatarIsAtRest
|
||||
uint64_t _desiredAtRestTimer { 0 };
|
||||
bool _desiredAtRest { true };
|
||||
bool _currentAtRest { true };
|
||||
// This stores value of myAvatar->hasDriveInput() from previous update, so that recentering can be triggered by a rising edge of that function's output
|
||||
bool _lastHasDriveInput { false };
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue