From 1b554b8c726f62da4d205f7456f0c88a59cc6b96 Mon Sep 17 00:00:00 2001 From: Daosheng Mu Date: Wed, 28 Oct 2015 09:18:00 +0100 Subject: [PATCH] Bug 1215143 - FF Android VR returns orientation that is 90deg off on x-axis. r=vlad --- gfx/vr/gfxVRCardboard.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/gfx/vr/gfxVRCardboard.cpp b/gfx/vr/gfxVRCardboard.cpp index 614beac51c7..ab295ec4ef8 100644 --- a/gfx/vr/gfxVRCardboard.cpp +++ b/gfx/vr/gfxVRCardboard.cpp @@ -58,9 +58,9 @@ RemapMatrixForOrientation(ScreenOrientationInternal screenConfig, const Matrix4x o[0] = in[1]; o[1] = -in[0]; o[2] = in[2]; o[4] = in[5]; o[5] = -in[4]; o[6] = in[6]; o[8] = in[9]; o[9] = -in[8]; o[10] = in[10]; - } else if (screenConfig == eScreenOrientation_PortraitPrimary || - screenConfig == eScreenOrientation_PortraitSecondary) - { + } else if (screenConfig == eScreenOrientation_PortraitPrimary) { + out = aMatrix; + } else if (screenConfig == eScreenOrientation_PortraitSecondary) { // remap X,Y -> X,-Z o[0] = in[0]; o[1] = in[2]; o[2] = -in[1]; o[4] = in[4]; o[5] = in[6]; o[6] = -in[5]; @@ -131,19 +131,23 @@ HMDInfoCardboard::StartSensorTracking() return true; } +// Android sends us events that have a 90-degree rotation about +// the x axis compared to what we want (phone flat vs. phone held in front of the eyes). +// Correct for this by applying a transform to undo this rotation. void HMDInfoCardboard::Notify(const mozilla::hal::ScreenConfiguration& config) { mOrient = config.orientation(); if (mOrient == eScreenOrientation_LandscapePrimary) { - mScreenTransform = Quaternion(0.f, 0.f, (float) M_SQRT1_2, (float) M_SQRT1_2); + mScreenTransform = Quaternion(-0.5f, 0.5f, 0.5f, 0.5f); } else if (mOrient == eScreenOrientation_LandscapeSecondary) { - mScreenTransform = Quaternion(0.f, 0.f, (float) -M_SQRT1_2, (float) M_SQRT1_2); + mScreenTransform = Quaternion(-0.5f, -0.5f, -0.5f, 0.5f); } else if (mOrient == eScreenOrientation_PortraitPrimary) { - mScreenTransform = Quaternion(); + mScreenTransform = Quaternion((float) -M_SQRT1_2, 0.f, 0.f, (float) M_SQRT1_2); } else if (mOrient == eScreenOrientation_PortraitSecondary) { - mScreenTransform = Quaternion(0.f, 0.f, 1.f, 0.f); + // Currently, PortraitSecondary event doesn't be triggered. + mScreenTransform = Quaternion((float) M_SQRT1_2, 0.f, 0.f, (float) M_SQRT1_2); } }