Skip to content

Commit

Permalink
Enable smooth window movement
Browse files Browse the repository at this point in the history
Currently when moving windows, they closely follow the orientation of
the controller. That means that they are prone to the natural small
shaking of human hands. To alleviate that, we can add some linear
interpolation between consecutive orientations. By using a value close
to 0 (in this case 0.1) we ensure that the interpolated value is very
close to the previous value, and thus, the movement is very smooth.
  • Loading branch information
svillar committed Jan 7, 2025
1 parent 4d41ce3 commit 3055f69
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/src/main/cpp/BrowserWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ struct BrowserWorld::State {
#endif
TrackedKeyboardRendererPtr trackedKeyboardRenderer;
float selectThreshold;
std::optional<vrb::Quaternion> prevReorient;

State() : paused(true), glInitialized(false), modelsLoaded(false), env(nullptr), cylinderDensity(0.0f), nearClip(0.1f),
farClip(300.0f), activity(nullptr), windowsInitialized(false), exitImmersiveRequested(false), loaderDelay(0) {
Expand Down Expand Up @@ -1218,6 +1219,18 @@ BrowserWorld::StartFrame() {
if (m.lockMode != LockMode::NO_LOCK) {
OnReorient();
auto reorientTransform = m.lockMode == LockMode::HEAD ? m.device->GetHeadTransform() : GetActiveControllerOrientation();
// Interpolate consecutive rotations to enable smooth window movements.
if (m.lockMode == LockMode::CONTROLLER) {
if (m.prevReorient) {
Quaternion reorientQuaternion(reorientTransform);
m.prevReorient = vrb::Quaternion::Slerp(*m.prevReorient, reorientQuaternion, 0.1f);
auto translation = reorientTransform.GetTranslation();
reorientTransform = vrb::Matrix::Rotation(m.prevReorient->Conjugate());
reorientTransform.TranslateInPlace(translation);
} else {
m.prevReorient = vrb::Quaternion(reorientTransform);
}
}
m.device->Reorient(reorientTransform);
}
if (m.reorientRequested)
Expand Down

0 comments on commit 3055f69

Please sign in to comment.