Bug 1305891 - Part 1: Support Oculus Touch orientation and position tracking; r?kip draft
authorDaosheng Mu <daoshengmu@gmail.com>
Thu, 02 Feb 2017 17:57:39 +0800
changeset 482673 2d64912f0d40746b2cdab2dcc2010a3413564868
parent 482503 00d16f03506b7f9f754b01a0a458c05445ac6dba
child 482674 3d9e727475ec19720456e665fbab4555f0abba69
push id45124
push userbmo:dmu@mozilla.com
push dateMon, 13 Feb 2017 07:55:08 +0000
reviewerskip
bugs1305891
milestone54.0a1
Bug 1305891 - Part 1: Support Oculus Touch orientation and position tracking; r?kip MozReview-Commit-ID: JQr6gzF06k7
gfx/vr/gfxVROculus.cpp
--- a/gfx/vr/gfxVROculus.cpp
+++ b/gfx/vr/gfxVROculus.cpp
@@ -987,16 +987,52 @@ VRSystemManagerOculus::HandleInput()
     axis = static_cast<uint32_t>(OculusControllerAxisType::HandTrigger);
     HandleAxisMove(controller->GetIndex(), axis, inputState.HandTrigger[i]);
 
     axis = static_cast<uint32_t>(OculusControllerAxisType::ThumbstickXAxis);
     HandleAxisMove(controller->GetIndex(), axis, inputState.Thumbstick[i].x);
 
     axis = static_cast<uint32_t>(OculusControllerAxisType::ThumbstickYAxis);
     HandleAxisMove(controller->GetIndex(), axis, -inputState.Thumbstick[i].y);
+
+    // Start to process pose
+    ovrTrackingState state = ovr_GetTrackingState(mSession, 0.0, false);
+    ovrPoseStatef& pose(state.HandPoses[i]);
+    GamepadPoseState poseState;
+
+    if (state.HandStatusFlags[i] & ovrStatus_OrientationTracked) {
+      poseState.flags |= GamepadCapabilityFlags::Cap_Orientation;
+      poseState.orientation[0] = pose.ThePose.Orientation.x;
+      poseState.orientation[1] = pose.ThePose.Orientation.y;
+      poseState.orientation[2] = pose.ThePose.Orientation.z;
+      poseState.orientation[3] = pose.ThePose.Orientation.w;
+      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;
+    }
+    if (state.HandStatusFlags[i] & 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;
+      poseState.linearVelocity[2] = pose.LinearVelocity.z;
+
+      poseState.flags |= GamepadCapabilityFlags::Cap_LinearAcceleration;
+      poseState.linearAcceleration[0] = pose.LinearAcceleration.x;
+      poseState.linearAcceleration[1] = pose.LinearAcceleration.y;
+      poseState.linearAcceleration[2] = pose.LinearAcceleration.z;
+    }
+    HandlePoseTracking(controller->GetIndex(), poseState, controller);
   }
 }
 
 void
 VRSystemManagerOculus::HandleButtonPress(uint32_t aControllerIdx,
                                          uint64_t aButtonPressed)
 {
   MOZ_ASSERT(sizeof(kOculusTouchLButton) / sizeof(ovrButton) ==
@@ -1046,17 +1082,20 @@ VRSystemManagerOculus::HandleAxisMove(ui
   }
 }
 
 void
 VRSystemManagerOculus::HandlePoseTracking(uint32_t aControllerIdx,
                                           const GamepadPoseState& aPose,
                                           VRControllerHost* aController)
 {
-  // TODO: Bug 1305891
+  if (aPose != aController->GetPose()) {
+    aController->SetPose(aPose);
+    NewPoseState(aControllerIdx, aPose);
+  }
 }
 
 void
 VRSystemManagerOculus::GetControllers(nsTArray<RefPtr<VRControllerHost>>&
                                       aControllerResult)
 {
   if (!mOculusInitialized) {
     return;