Bug 1215143 - FF Android VR returns orientation that is 90deg off on x-axis. r=vlad
authorDaosheng Mu <daoshengmu@gmail.com>
Wed, 28 Oct 2015 09:18:00 +0100
changeset 270409 dad7e0ee9905
parent 270408 cd4361e0be3a
child 270410 fc898522b3fb
push id86
push usercbook@mozilla.com
push date2015-11-04 14:00 +0000
reviewersvlad
bugs1215143
milestone45.0a1
Bug 1215143 - FF Android VR returns orientation that is 90deg off on x-axis. r=vlad
gfx/vr/gfxVRCardboard.cpp
--- a/gfx/vr/gfxVRCardboard.cpp
+++ b/gfx/vr/gfxVRCardboard.cpp
@@ -53,19 +53,19 @@ RemapMatrixForOrientation(ScreenOrientat
     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_LandscapeSecondary) {
     // remap X,Y -> -Y,X
     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];
     o[8] = in[8]; o[9] = in[10]; o[10] = -in[9];
   } else {
     MOZ_ASSERT(0, "gfxVRCardboard::RemapMatrixForOrientation invalid screenConfig");
   }
 
@@ -126,29 +126,33 @@ HMDInfoCardboard::StartSensorTracking()
 
     mLastSensorState.Clear();
   }
 
   mStartCount++;
   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);
   }
 }
 
 void
 HMDInfoCardboard::Notify(const mozilla::hal::SensorData& data)
 {
   if (data.sensor() != mozilla::hal::SENSOR_GAME_ROTATION_VECTOR)
     return;