Skip to content

Commit

Permalink
Merge pull request #70 from Igalia/mortimer/eye_transform
Browse files Browse the repository at this point in the history
Use eye transform instead of translation in external_vr
  • Loading branch information
svillar authored Mar 17, 2022
2 parents 96c4456 + bb776dd commit f64d1ac
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
1 change: 1 addition & 0 deletions app/src/main/cpp/DeviceDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class ImmersiveDisplay {
const double aTopDegrees,
const double aBottomDegrees) = 0;
virtual void SetEyeOffset(const device::Eye aEye, const float aX, const float aY, const float aZ) = 0;
virtual void SetEyeTransform(const device::Eye aEye, const vrb::Matrix& aTransform) = 0;
virtual void SetEyeResolution(const int32_t aWidth, const int32_t aHeight) = 0;
virtual void SetNativeFramebufferScaleFactor(const float aScale) = 0;
virtual void SetStageSize(const float aWidth, const float aDepth) = 0;
Expand Down
17 changes: 10 additions & 7 deletions app/src/main/cpp/ExternalVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ struct ExternalVR::State {
mozilla::gfx::VRSystemState system = {};
mozilla::gfx::VRBrowserState browser = {};
// device::CapabilityFlags deviceCapabilities = 0;
vrb::Vector eyeOffsets[device::EyeCount];
vrb::Matrix eyeTransforms[device::EyeCount];
uint64_t lastFrameId = 0;
bool firstPresentingFrame = false;
bool compositorEnabled = true;
Expand Down Expand Up @@ -325,13 +325,16 @@ ExternalVR::SetFieldOfView(const device::Eye aEye, const double aLeftDegrees,

void
ExternalVR::SetEyeOffset(const device::Eye aEye, const float aX, const float aY, const float aZ) {
SetEyeTransform(aEye, vrb::Matrix::Translation(vrb::Vector(aX, aY, aZ)));
}

void
ExternalVR::SetEyeTransform(const device::Eye aEye, const vrb::Matrix& aTransform) {
mozilla::gfx::VRDisplayState::Eye which = (aEye == device::Eye::Right
? mozilla::gfx::VRDisplayState::Eye_Right
: mozilla::gfx::VRDisplayState::Eye_Left);
m.system.displayState.eyeTranslation[which].x = aX;
m.system.displayState.eyeTranslation[which].y = aY;
m.system.displayState.eyeTranslation[which].z = aZ;
m.eyeOffsets[device::EyeIndex(aEye)].Set(aX, aY, aZ);
memcpy(&(m.system.displayState.eyeTransform[which]), aTransform.Data(), sizeof(m.system.displayState.eyeTransform[which]));
m.eyeTransforms[device::EyeIndex(aEye)] = aTransform;
}

void
Expand Down Expand Up @@ -466,8 +469,8 @@ ExternalVR::PushFramePoses(const vrb::Matrix& aHeadTransform, const std::vector<
m.system.sensorState.inputFrameID++;
m.system.displayState.lastSubmittedFrameId = m.lastFrameId;

vrb::Matrix leftView = vrb::Matrix::Position(-m.eyeOffsets[device::EyeIndex(device::Eye::Left)]).PostMultiply(inverseHeadTransform);
vrb::Matrix rightView = vrb::Matrix::Position(-m.eyeOffsets[device::EyeIndex(device::Eye::Right)]).PostMultiply(inverseHeadTransform);
vrb::Matrix leftView = m.eyeTransforms[device::EyeIndex(device::Eye::Left)].Inverse().PostMultiply(inverseHeadTransform);
vrb::Matrix rightView = m.eyeTransforms[device::EyeIndex(device::Eye::Right)].Inverse().PostMultiply(inverseHeadTransform);
memcpy(&(m.system.sensorState.leftViewMatrix), leftView.Data(),
sizeof(m.system.sensorState.leftViewMatrix));
memcpy(&(m.system.sensorState.rightViewMatrix), rightView.Data(),
Expand Down
1 change: 1 addition & 0 deletions app/src/main/cpp/ExternalVR.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class ExternalVR : public ImmersiveDisplay {
const double aBottomDegrees) override;
void SetEyeOffset(const device::Eye aEye, const float aX, const float aY, const float aZ) override;
void SetEyeResolution(const int32_t aX, const int32_t aY) override;
void SetEyeTransform(const device::Eye aEye, const vrb::Matrix& aTransform) override;
void SetNativeFramebufferScaleFactor(const float aScale) override;
void SetStageSize(const float aWidth, const float aDepth) override;
void SetSittingToStandingTransform(const vrb::Matrix& aTransform) override;
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/cpp/moz_external_vr.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace gfx {
// running at the same time? Or...what if we have multiple
// release builds running on same machine? (Bug 1563232)
#define SHMEM_VERSION "0.0.11"
static const int32_t kVRExternalVersion = 18;
static const int32_t kVRExternalVersion = 19;

// We assign VR presentations to groups with a bitmask.
// Currently, we will only display either content or chrome.
Expand Down Expand Up @@ -344,7 +344,7 @@ struct VRDisplayState {
VRDisplayCapabilityFlags capabilityFlags;
VRDisplayBlendMode blendMode;
VRFieldOfView eyeFOV[VRDisplayState::NumEyes];
Point3D_POD eyeTranslation[VRDisplayState::NumEyes];
float eyeTransform[VRDisplayState::NumEyes][16];
IntSize_POD eyeResolution;
float nativeFramebufferScaleFactor;
bool suppressFrames;
Expand Down
7 changes: 4 additions & 3 deletions app/src/openxr/cpp/DeviceDelegateOpenXR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ DeviceDelegateOpenXR::StartFrame(const FramePrediction aPrediction) {
}
}

// Query eyeTransform ans perspective for each view
// Query eyeTransform and perspective for each view
XrViewState viewState{XR_TYPE_VIEW_STATE};
uint32_t viewCapacityInput = (uint32_t) m.views.size();
uint32_t viewCountOutput = 0;
Expand All @@ -744,9 +744,10 @@ DeviceDelegateOpenXR::StartFrame(const FramePrediction aPrediction) {
for (int i = 0; i < m.views.size(); ++i) {
const XrView &view = m.views[i];
const device::Eye eye = i == 0 ? device::Eye::Left : device::Eye::Right;
m.cameras[i]->SetEyeTransform(XrPoseToMatrix(view.pose));
vrb::Matrix eyeTransform = XrPoseToMatrix(view.pose);
m.cameras[i]->SetEyeTransform(eyeTransform);
if (m.immersiveDisplay) {
m.immersiveDisplay->SetEyeOffset(eye, view.pose.position.x, view.pose.position.y, view.pose.position.z);
m.immersiveDisplay->SetEyeTransform(eye, eyeTransform);
}
}
}
Expand Down

0 comments on commit f64d1ac

Please sign in to comment.