Bug 1355648 - Part 1: Check VR controllers if losing tracking; r?kip draft
authorDaosheng Mu <daoshengmu@gmail.com>
Fri, 21 Apr 2017 18:14:42 +0800
changeset 568421 c2457d57f4db025a057aa73eb6160a4f1698ccde
parent 568252 3f0c8da53c5cb015933b10b52ded3f30432b378a
child 568422 9eeb4ec9d265f232e7741f9b63018a2a43e54b92
push id55867
push userbmo:dmu@mozilla.com
push dateWed, 26 Apr 2017 06:11:42 +0000
reviewerskip
bugs1355648
milestone55.0a1
Bug 1355648 - Part 1: Check VR controllers if losing tracking; r?kip MozReview-Commit-ID: B8DaBmz1mJo
gfx/vr/gfxVROculus.cpp
gfx/vr/gfxVROpenVR.cpp
--- a/gfx/vr/gfxVROculus.cpp
+++ b/gfx/vr/gfxVROculus.cpp
@@ -1259,16 +1259,17 @@ VRSystemManagerOculus::HandleInput()
       poseState.angularVelocity[0] = pose.AngularVelocity.x;
       poseState.angularVelocity[1] = pose.AngularVelocity.y;
       poseState.angularVelocity[2] = pose.AngularVelocity.z;
 
       poseState.flags |= GamepadCapabilityFlags::Cap_AngularAcceleration;
       poseState.angularAcceleration[0] = pose.AngularAcceleration.x;
       poseState.angularAcceleration[1] = pose.AngularAcceleration.y;
       poseState.angularAcceleration[2] = pose.AngularAcceleration.z;
+      poseState.isOrientationValid = true;
     }
     if (state.HandStatusFlags[handIdx] & ovrStatus_PositionTracked) {
       poseState.flags |= GamepadCapabilityFlags::Cap_Position;
       poseState.position[0] = pose.ThePose.Position.x;
       poseState.position[1] = pose.ThePose.Position.y;
       poseState.position[2] = pose.ThePose.Position.z;
       poseState.linearVelocity[0] = pose.LinearVelocity.x;
       poseState.linearVelocity[1] = pose.LinearVelocity.y;
@@ -1276,16 +1277,17 @@ VRSystemManagerOculus::HandleInput()
 
       poseState.flags |= GamepadCapabilityFlags::Cap_LinearAcceleration;
       poseState.linearAcceleration[0] = pose.LinearAcceleration.x;
       poseState.linearAcceleration[1] = pose.LinearAcceleration.y;
       poseState.linearAcceleration[2] = pose.LinearAcceleration.z;
 
       float eyeHeight = ovr_GetFloat(mSession, OVR_KEY_EYE_HEIGHT, OVR_DEFAULT_EYE_HEIGHT);
       poseState.position[1] -= eyeHeight;
+      poseState.isPositionValid = true;
     }
     HandlePoseTracking(i, poseState, controller);
   }
 }
 
 void
 VRSystemManagerOculus::HandleButtonPress(uint32_t aControllerIdx,
                                          uint32_t aButton,
--- a/gfx/vr/gfxVROpenVR.cpp
+++ b/gfx/vr/gfxVROpenVR.cpp
@@ -709,51 +709,56 @@ VRSystemManagerOpenVR::HandleInput()
       }
       MOZ_ASSERT(buttonIdx ==
                  controller->GetControllerInfo().GetNumButtons());
       controller->SetButtonPressed(state.ulButtonPressed);
       controller->SetButtonTouched(state.ulButtonTouched);
 
       // Start to process pose
       const ::vr::TrackedDevicePose_t& pose = poses[trackedIndex];
+      GamepadPoseState poseState;
 
-      if (pose.bDeviceIsConnected && pose.bPoseIsValid &&
-        pose.eTrackingResult == ::vr::TrackingResult_Running_OK) {
+      if (pose.bDeviceIsConnected) {
+        poseState.flags |= (GamepadCapabilityFlags::Cap_Orientation |
+                            GamepadCapabilityFlags::Cap_Position);
+      }
+
+      if (pose.bPoseIsValid &&
+          pose.eTrackingResult == ::vr::TrackingResult_Running_OK) {
         gfx::Matrix4x4 m;
 
         // NOTE! mDeviceToAbsoluteTracking is a 3x4 matrix, not 4x4.  But
         // because of its arrangement, we can copy the 12 elements in and
         // then transpose them to the right place.  We do this so we can
         // pull out a Quaternion.
         memcpy(&m.components, &pose.mDeviceToAbsoluteTracking, sizeof(float) * 12);
         m.Transpose();
 
         gfx::Quaternion rot;
         rot.SetFromRotationMatrix(m);
         rot.Invert();
 
-        GamepadPoseState poseState;
-        poseState.flags |= GamepadCapabilityFlags::Cap_Orientation;
         poseState.orientation[0] = rot.x;
         poseState.orientation[1] = rot.y;
         poseState.orientation[2] = rot.z;
         poseState.orientation[3] = rot.w;
         poseState.angularVelocity[0] = pose.vAngularVelocity.v[0];
         poseState.angularVelocity[1] = pose.vAngularVelocity.v[1];
         poseState.angularVelocity[2] = pose.vAngularVelocity.v[2];
+        poseState.isOrientationValid = true;
 
-        poseState.flags |= GamepadCapabilityFlags::Cap_Position;
         poseState.position[0] = m._41;
         poseState.position[1] = m._42;
         poseState.position[2] = m._43;
         poseState.linearVelocity[0] = pose.vVelocity.v[0];
         poseState.linearVelocity[1] = pose.vVelocity.v[1];
         poseState.linearVelocity[2] = pose.vVelocity.v[2];
-        HandlePoseTracking(i, poseState, controller);
+        poseState.isPositionValid = true;
       }
+      HandlePoseTracking(i, poseState, controller);
     }
   }
 }
 
 void
 VRSystemManagerOpenVR::HandleButtonPress(uint32_t aControllerIdx,
                                          uint32_t aButton,
                                          uint64_t aButtonMask,