Skip to content

Commit

Permalink
Restore headlock rotation with roll
Browse files Browse the repository at this point in the history
  • Loading branch information
svillar authored and felipeerias committed Jan 16, 2025
1 parent 481a961 commit 4f3333a
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/src/main/cpp/BrowserWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@ BrowserWorld::StartFrame() {
VRBrowser::ChangeWindowDistance(delta);
}
}
m.device->Reorient(reorientTransform);
m.device->Reorient(reorientTransform, m.lockMode == LockMode::HEAD ? DeviceDelegate::ReorientMode::SIX_DOF : DeviceDelegate::ReorientMode::NO_ROLL);
}
if (m.reorientRequested)
relayoutWidgets = std::exchange(m.reorientRequested, false);
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/cpp/DeviceDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ class DeviceDelegate {
virtual const vrb::Matrix& GetHeadTransform() const = 0;
virtual const vrb::Matrix& GetReorientTransform() const = 0;
virtual void SetReorientTransform(const vrb::Matrix& aMatrix) = 0;
virtual void Reorient(vrb::Matrix&) = 0;
enum class ReorientMode { SIX_DOF, NO_ROLL };
virtual void Reorient(vrb::Matrix &, ReorientMode) = 0;
virtual void SetClearColor(const vrb::Color& aColor) = 0;
virtual void SetClipPlanes(const float aNear, const float aFar) = 0;
virtual void SetControllerDelegate(ControllerDelegatePtr& aController) = 0;
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/cpp/DeviceUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ DeviceUtils::CalculateReorientationMatrix(const vrb::Matrix& aHeadTransform, con
return CalculateReorientationMatrixWithThreshold(aHeadTransform, aHeightPosition, 0.2f, 0.5f, 0.35f);
}

vrb::Matrix
DeviceUtils::CalculateReorientationMatrixOnHeadLock(const vrb::Matrix& aHeadTransform, const vrb::Vector& aHeightPosition) {
return CalculateReorientationMatrixWithThreshold(aHeadTransform, aHeightPosition, 0.0f, 0.0f, 0.0f);
}

// CAUTION: using Euler angles is dangerous because they could cause gimbal lock issues.
vrb::Matrix
DeviceUtils::CalculateReorientationMatrixWithThreshold(const vrb::Matrix& aHeadTransform, const vrb::Vector& aHeightPosition, const float kPitchUpThreshold, const float kPitchDownThreshold, const float kRollThreshold) {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/cpp/DeviceUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace crow {
class DeviceUtils {
public:
static vrb::Matrix CalculateReorientationMatrix(const vrb::Matrix& aHeadTransform, const vrb::Vector& aHeightPosition);
static vrb::Matrix CalculateReorientationMatrixOnHeadLock(const vrb::Matrix& aHeadTransform, const vrb::Vector& aHeightPosition);
static vrb::Matrix CalculateReorientationMatrixWithoutRoll(const vrb::Matrix& aHeadTransform, const vrb::Vector& aHeightPosition);
static void GetTargetImmersiveSize(const uint32_t aRequestedWidth, const uint32_t aRequestedHeight,
const uint32_t aRecommendedWidth, const uint32_t aRecommendedHeight,
Expand Down
2 changes: 1 addition & 1 deletion app/src/noapi/cpp/DeviceDelegateNoAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ DeviceDelegateNoAPI::SetReorientTransform(const vrb::Matrix& aMatrix) {
}

void
DeviceDelegateNoAPI::Reorient(vrb::Matrix&) {
DeviceDelegateNoAPI::Reorient(vrb::Matrix&, ReorientMode) {
// Ignore reorient
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/noapi/cpp/DeviceDelegateNoAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class DeviceDelegateNoAPI : public DeviceDelegate {
const vrb::Matrix& GetHeadTransform() const override;
const vrb::Matrix& GetReorientTransform() const override;
void SetReorientTransform(const vrb::Matrix& aMatrix) override;
void Reorient(vrb::Matrix&) override;
void Reorient(vrb::Matrix&, ReorientMode) override;
void SetClearColor(const vrb::Color& aColor) override;
void SetClipPlanes(const float aNear, const float aFar) override;
void SetControllerDelegate(ControllerDelegatePtr& aController) override;
Expand Down
13 changes: 11 additions & 2 deletions app/src/openxr/cpp/DeviceDelegateOpenXR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -930,8 +930,17 @@ DeviceDelegateOpenXR::SetReorientTransform(const vrb::Matrix& aMatrix) {
}

void
DeviceDelegateOpenXR::Reorient(vrb::Matrix& transform) {
m.reorientMatrix = DeviceUtils::CalculateReorientationMatrixWithoutRoll(transform, GetHeadTransform().GetTranslation());
DeviceDelegateOpenXR::Reorient(vrb::Matrix &transform, ReorientMode mode) {
switch (mode) {
case ReorientMode::SIX_DOF:
m.reorientMatrix = DeviceUtils::CalculateReorientationMatrixOnHeadLock(transform, GetHeadTransform().GetTranslation());
break;
case ReorientMode::NO_ROLL:
m.reorientMatrix = DeviceUtils::CalculateReorientationMatrixWithoutRoll(transform, GetHeadTransform().GetTranslation());
break;
default:
VRB_ERROR("Unsupported reorient mode %d", mode);
}
}

void
Expand Down
2 changes: 1 addition & 1 deletion app/src/openxr/cpp/DeviceDelegateOpenXR.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class DeviceDelegateOpenXR : public DeviceDelegate {
const vrb::Matrix& GetHeadTransform() const override;
const vrb::Matrix& GetReorientTransform() const override;
void SetReorientTransform(const vrb::Matrix& aMatrix) override;
void Reorient(vrb::Matrix&) override;
void Reorient(vrb::Matrix&, ReorientMode) override;
void SetClearColor(const vrb::Color& aColor) override;
void SetClipPlanes(const float aNear, const float aFar) override;
void SetControllerDelegate(ControllerDelegatePtr& aController) override;
Expand Down
13 changes: 11 additions & 2 deletions app/src/visionglass/cpp/DeviceDelegateVisionGlass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,17 @@ DeviceDelegateVisionGlass::SetReorientTransform(const vrb::Matrix& aMatrix) {
}

void
DeviceDelegateVisionGlass::Reorient(vrb::Matrix& transform) {
m.reorientMatrix = DeviceUtils::CalculateReorientationMatrixWithoutRoll(transform, GetHeadTransform().GetTranslation());
DeviceDelegateVisionGlass::Reorient(vrb::Matrix& transform, ReorientMode mode) {
switch (mode) {
case ReorientMode::SIX_DOF:
m.reorientMatrix = DeviceUtils::CalculateReorientationMatrixOnHeadLock(transform, GetHeadTransform().GetTranslation());
break;
case ReorientMode::NO_ROLL:
m.reorientMatrix = DeviceUtils::CalculateReorientationMatrixWithoutRoll(transform, GetHeadTransform().GetTranslation());
break;
default:
VRB_ERROR("Unsupported reorient mode %d", mode);
}
}

void
Expand Down
2 changes: 1 addition & 1 deletion app/src/visionglass/cpp/DeviceDelegateVisionGlass.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class DeviceDelegateVisionGlass : public DeviceDelegate {
const vrb::Matrix& GetHeadTransform() const override;
const vrb::Matrix& GetReorientTransform() const override;
void SetReorientTransform(const vrb::Matrix& aMatrix) override;
void Reorient(vrb::Matrix&) override;
void Reorient(vrb::Matrix&, ReorientMode) override;
void SetClearColor(const vrb::Color& aColor) override;
void SetClipPlanes(const float aNear, const float aFar) override;
void SetControllerDelegate(ControllerDelegatePtr& aController) override;
Expand Down
13 changes: 11 additions & 2 deletions app/src/wavevr/cpp/DeviceDelegateWaveVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -657,8 +657,17 @@ DeviceDelegateWaveVR::SetReorientTransform(const vrb::Matrix& aMatrix) {
}

void
DeviceDelegateWaveVR::Reorient(vrb::Matrix& transform) {
m.reorientMatrix = DeviceUtils::CalculateReorientationMatrixWithoutRoll(transform, GetHeadTransform().GetTranslation());
DeviceDelegateWaveVR::Reorient(vrb::Matrix& transform, ReorientMode mode) {
switch (mode) {
case ReorientMode::SIX_DOF:
m.reorientMatrix = DeviceUtils::CalculateReorientationMatrixOnHeadLock(transform, GetHeadTransform().GetTranslation());
break;
case ReorientMode::NO_ROLL:
m.reorientMatrix = DeviceUtils::CalculateReorientationMatrixWithoutRoll(transform, GetHeadTransform().GetTranslation());
break;
default:
VRB_ERROR("Unsupported reorient mode %d", mode);
}
}

void
Expand Down
2 changes: 1 addition & 1 deletion app/src/wavevr/cpp/DeviceDelegateWaveVR.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class DeviceDelegateWaveVR : public DeviceDelegate {
const vrb::Matrix& GetHeadTransform() const override;
const vrb::Matrix& GetReorientTransform() const override;
void SetReorientTransform(const vrb::Matrix& aMatrix) override;
void Reorient(vrb::Matrix&) override;
void Reorient(vrb::Matrix&, ReorientMode) override;
void SetClearColor(const vrb::Color& aColor) override;
void SetClipPlanes(const float aNear, const float aFar) override;
void SetControllerDelegate(ControllerDelegatePtr& aController) override;
Expand Down

0 comments on commit 4f3333a

Please sign in to comment.