Chromium Code Reviews| Index: chrome/browser/android/vr_shell/vr_shell.cc |
| diff --git a/chrome/browser/android/vr_shell/vr_shell.cc b/chrome/browser/android/vr_shell/vr_shell.cc |
| index edcbb68f0fe05e2c0f75e96229e281b9e33a5b32..13d13bd866330577a634307b87fe44d62d23d57c 100644 |
| --- a/chrome/browser/android/vr_shell/vr_shell.cc |
| +++ b/chrome/browser/android/vr_shell/vr_shell.cc |
| @@ -655,7 +655,9 @@ void VrShell::RegisterGamepadDataFetcher( |
| } |
| /* static */ |
| -device::mojom::VRPosePtr VrShell::VRPosePtrFromGvrPose(gvr::Mat4f head_mat) { |
| +device::mojom::VRPosePtr VrShell::VRPosePtrFromGvrPose(gvr::Mat4f head_mat, |
| + gvr::Mat4f head_mat_2, |
| + int64_t epsilon_nanos) { |
| device::mojom::VRPosePtr pose = device::mojom::VRPose::New(); |
| pose->orientation.emplace(4); |
| @@ -682,6 +684,36 @@ device::mojom::VRPosePtr VrShell::VRPosePtrFromGvrPose(gvr::Mat4f head_mat) { |
| pose->position.value()[2] = decomposed_transform.translate[2]; |
| } |
| + // The angular velocity is a 3-element vector pointing along the |
| + // rotation axis with magnitude equal to rotation speed in |
| + // radians/second. |
| + // |
| + // The spec isn't very clear on details, clarification requested in |
| + // https://github.com/w3c/webvr/issues/212 . |
| + // |
| + // Assume we're using right-hand rule for direction and a |
| + // headset-attached frame of reference with +X to the right, +Y up, |
| + // and +Z backwards (towards back of head). |
| + // |
| + // Examples: |
| + // - "look up" motion: (positive, 0, 0) |
| + // - "turn left" motion: (0, positive, 0) |
| + // - "lean head left" motion: (0, 0, positive) |
| + // |
| + // Assuming that pose prediction is simply based on adding a time * |
| + // angular velocity rotation to the pose, we can approximate the |
| + // angular velocity from the difference between two successive |
| + // poses. This is a first order estimate that assumes small enough |
| + // rotations so that we can do linear approximation. |
| + pose->angularVelocity.emplace(3); |
| + double epsilon_seconds = epsilon_nanos * 1e-9; |
|
cjgrant
2017/03/24 21:15:40
Should protect against epsilon_nanos being 0 to av
klausw
2017/03/24 22:13:29
That can't happen accidentally since it's a compil
|
| + pose->angularVelocity.value()[0] = |
| + (head_mat_2.m[1][2] - head_mat.m[1][2]) / epsilon_seconds; |
| + pose->angularVelocity.value()[1] = |
| + -(head_mat_2.m[0][2] - head_mat.m[0][2]) / epsilon_seconds; |
| + pose->angularVelocity.value()[2] = |
| + (head_mat_2.m[0][1] - head_mat.m[0][1]) / epsilon_seconds; |
| + |
| return pose; |
| } |