Skip to content

Commit

Permalink
Bug 1650714 - Part 2: Correct XRRigidTransform inverse math r=daoshen…
Browse files Browse the repository at this point in the history
…gmu,kip,lsalzman

Differential Revision: https://phabricator.services.mozilla.com/D82433
  • Loading branch information
MortimerGoro committed Jul 10, 2020
1 parent 088f996 commit a0b1223
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
5 changes: 3 additions & 2 deletions dom/vr/XRFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ already_AddRefed<XRViewerPose> XRFrame::GetViewerPose(

gfx::Matrix4x4Double originTransform;
originTransform.SetRotationFromQuaternion(
aReferenceSpace.GetEffectiveOriginOrientation());
aReferenceSpace.GetEffectiveOriginOrientation().Inverse());
originTransform.PreTranslate(-aReferenceSpace.GetEffectiveOriginPosition());

headTransform *= originTransform;
Expand Down Expand Up @@ -155,7 +155,8 @@ already_AddRefed<XRPose> XRFrame::GetPose(const XRSpace& aSpace,

const bool emulatedPosition = aSpace.IsPositionEmulated();
gfx::Matrix4x4Double base;
base.SetRotationFromQuaternion(aBaseSpace.GetEffectiveOriginOrientation());
base.SetRotationFromQuaternion(
aBaseSpace.GetEffectiveOriginOrientation().Inverse());
base.PreTranslate(-aBaseSpace.GetEffectiveOriginPosition());

gfx::Matrix4x4Double matrix = aSpace.GetEffectiveOriginTransform() * base;
Expand Down
16 changes: 6 additions & 10 deletions dom/vr/XRRigidTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,9 @@ void XRRigidTransform::UpdateInternal() {
mOrientation->SetW(mRawOrientation.w);
}
if (mInverse) {
gfx::QuaternionDouble q(mRawOrientation);
gfx::PointDouble3D p = -mRawPosition;
p = q.RotatePoint(p);
q.Invert();
mInverse->Update(p, q);
gfx::Matrix4x4Double inverseMatrix = mRawTransformMatrix;
Unused << inverseMatrix.Invert();
mInverse->Update(inverseMatrix);
}
}

Expand Down Expand Up @@ -175,11 +173,9 @@ void XRRigidTransform::GetMatrix(JSContext* aCx,

already_AddRefed<XRRigidTransform> XRRigidTransform::Inverse() {
if (!mInverse) {
gfx::QuaternionDouble q(mRawOrientation);
gfx::PointDouble3D p = -mRawPosition;
p = q.RotatePoint(p);
q.Invert();
mInverse = new XRRigidTransform(mParent, p, q);
gfx::Matrix4x4Double inverseMatrix = mRawTransformMatrix;
Unused << inverseMatrix.Invert();
mInverse = new XRRigidTransform(mParent, inverseMatrix);
}

RefPtr<XRRigidTransform> inverse = mInverse;
Expand Down
6 changes: 6 additions & 0 deletions gfx/2d/Quaternion.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ class BaseQuaternion {

BaseQuaternion& Invert() { return Conjugate().Normalize(); }

BaseQuaternion Inverse() const {
BaseQuaternion q = *this;
q.Invert();
return q;
}

Point3DTyped<UnknownUnits, T> RotatePoint(
const Point3DTyped<UnknownUnits, T>& aPoint) const {
T uvx = T(2.0) * (y * aPoint.z - z * aPoint.y);
Expand Down

0 comments on commit a0b1223

Please sign in to comment.