Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Side by Side Diff: chrome/browser/android/vr_shell/vr_shell.cc

Issue 2770353002: WebVR: add angular velocity estimate to pose (Closed)
Patch Set: Comment changes and reformatting as suggested Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/android/vr_shell/vr_shell.h" 5 #include "chrome/browser/android/vr_shell/vr_shell.h"
6 6
7 #include <android/native_window_jni.h> 7 #include <android/native_window_jni.h>
8 8
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 } 648 }
649 } 649 }
650 650
651 void VrShell::RegisterGamepadDataFetcher( 651 void VrShell::RegisterGamepadDataFetcher(
652 device::GvrGamepadDataFetcher* fetcher) { 652 device::GvrGamepadDataFetcher* fetcher) {
653 DVLOG(1) << __FUNCTION__ << "(" << fetcher << ")"; 653 DVLOG(1) << __FUNCTION__ << "(" << fetcher << ")";
654 gamepad_data_fetcher_ = fetcher; 654 gamepad_data_fetcher_ = fetcher;
655 } 655 }
656 656
657 /* static */ 657 /* static */
658 device::mojom::VRPosePtr VrShell::VRPosePtrFromGvrPose(gvr::Mat4f head_mat) { 658 device::mojom::VRPosePtr VrShell::VRPosePtrFromGvrPose(gvr::Mat4f head_mat,
659 gvr::Mat4f head_mat_2,
660 int64_t epsilon_nanos) {
659 device::mojom::VRPosePtr pose = device::mojom::VRPose::New(); 661 device::mojom::VRPosePtr pose = device::mojom::VRPose::New();
660 662
661 pose->orientation.emplace(4); 663 pose->orientation.emplace(4);
662 664
663 gfx::Transform inv_transform( 665 gfx::Transform inv_transform(
664 head_mat.m[0][0], head_mat.m[0][1], head_mat.m[0][2], head_mat.m[0][3], 666 head_mat.m[0][0], head_mat.m[0][1], head_mat.m[0][2], head_mat.m[0][3],
665 head_mat.m[1][0], head_mat.m[1][1], head_mat.m[1][2], head_mat.m[1][3], 667 head_mat.m[1][0], head_mat.m[1][1], head_mat.m[1][2], head_mat.m[1][3],
666 head_mat.m[2][0], head_mat.m[2][1], head_mat.m[2][2], head_mat.m[2][3], 668 head_mat.m[2][0], head_mat.m[2][1], head_mat.m[2][2], head_mat.m[2][3],
667 head_mat.m[3][0], head_mat.m[3][1], head_mat.m[3][2], head_mat.m[3][3]); 669 head_mat.m[3][0], head_mat.m[3][1], head_mat.m[3][2], head_mat.m[3][3]);
668 670
669 gfx::Transform transform; 671 gfx::Transform transform;
670 if (inv_transform.GetInverse(&transform)) { 672 if (inv_transform.GetInverse(&transform)) {
671 gfx::DecomposedTransform decomposed_transform; 673 gfx::DecomposedTransform decomposed_transform;
672 gfx::DecomposeTransform(&decomposed_transform, transform); 674 gfx::DecomposeTransform(&decomposed_transform, transform);
673 675
674 pose->orientation.value()[0] = decomposed_transform.quaternion[0]; 676 pose->orientation.value()[0] = decomposed_transform.quaternion[0];
675 pose->orientation.value()[1] = decomposed_transform.quaternion[1]; 677 pose->orientation.value()[1] = decomposed_transform.quaternion[1];
676 pose->orientation.value()[2] = decomposed_transform.quaternion[2]; 678 pose->orientation.value()[2] = decomposed_transform.quaternion[2];
677 pose->orientation.value()[3] = decomposed_transform.quaternion[3]; 679 pose->orientation.value()[3] = decomposed_transform.quaternion[3];
678 680
679 pose->position.emplace(3); 681 pose->position.emplace(3);
680 pose->position.value()[0] = decomposed_transform.translate[0]; 682 pose->position.value()[0] = decomposed_transform.translate[0];
681 pose->position.value()[1] = decomposed_transform.translate[1]; 683 pose->position.value()[1] = decomposed_transform.translate[1];
682 pose->position.value()[2] = decomposed_transform.translate[2]; 684 pose->position.value()[2] = decomposed_transform.translate[2];
683 } 685 }
684 686
687 // The angular velocity is a 3-element vector pointing along the rotation
688 // axis with magnitude equal to rotation speed in radians/second.
689 //
690 // The spec isn't very clear on details, clarification requested in
691 // https://github.com/w3c/webvr/issues/212 .
692 //
693 // Assume we're using right-hand rule for direction and a headset-attached
694 // frame of reference with +X to the right, +Y up, and +Z backwards (towards
695 // back of head).
696 //
697 // Examples:
698 // - "look up" motion: (positive, 0, 0)
699 // - "turn left" motion: (0, positive, 0)
700 // - "lean head left" motion: (0, 0, positive)
701 //
702 // Assuming that pose prediction is simply based on adding a time * angular
703 // velocity rotation to the pose, we can approximate the angular velocity
704 // from the difference between two successive poses. This is a first order
705 // estimate that assumes small enough rotations so that we can do linear
706 // approximation.
707 pose->angularVelocity.emplace(3);
708 // Assume that epsilon is nonzero since it's a compile-time constant
709 // provided by the caller.
710 double epsilon_seconds = epsilon_nanos * 1e-9;
711 pose->angularVelocity.value()[0] =
billorr 2017/03/24 22:52:51 can you explain the math here in a comment? Looki
klausw 2017/03/27 02:25:52 I'm using https://en.wikipedia.org/wiki/Angular_ve
712 (head_mat_2.m[1][2] - head_mat.m[1][2]) / epsilon_seconds;
713 pose->angularVelocity.value()[1] =
714 -(head_mat_2.m[0][2] - head_mat.m[0][2]) / epsilon_seconds;
715 pose->angularVelocity.value()[2] =
716 (head_mat_2.m[0][1] - head_mat.m[0][1]) / epsilon_seconds;
717
685 return pose; 718 return pose;
686 } 719 }
687 720
688 /* static */ 721 /* static */
689 gvr::Sizei VrShell::GetRecommendedWebVrSize(gvr::GvrApi* gvr_api) { 722 gvr::Sizei VrShell::GetRecommendedWebVrSize(gvr::GvrApi* gvr_api) {
690 // Pick a reasonable default size for the WebVR transfer surface 723 // Pick a reasonable default size for the WebVR transfer surface
691 // based on a downscaled 1:1 render resolution. This size will also 724 // based on a downscaled 1:1 render resolution. This size will also
692 // be reported to the client via CreateVRDisplayInfo as the 725 // be reported to the client via CreateVRDisplayInfo as the
693 // client-recommended renderWidth/renderHeight and for the GVR 726 // client-recommended renderWidth/renderHeight and for the GVR
694 // framebuffer. If the client chooses a different size or resizes it 727 // framebuffer. If the client chooses a different size or resizes it
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 jboolean reprojected_rendering) { 812 jboolean reprojected_rendering) {
780 return reinterpret_cast<intptr_t>(new VrShell( 813 return reinterpret_cast<intptr_t>(new VrShell(
781 env, obj, reinterpret_cast<ui::WindowAndroid*>(content_window_android), 814 env, obj, reinterpret_cast<ui::WindowAndroid*>(content_window_android),
782 content::WebContents::FromJavaWebContents(ui_web_contents), 815 content::WebContents::FromJavaWebContents(ui_web_contents),
783 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), for_web_vr, 816 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), for_web_vr,
784 VrShellDelegate::GetNativeVrShellDelegate(env, delegate), 817 VrShellDelegate::GetNativeVrShellDelegate(env, delegate),
785 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); 818 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering));
786 } 819 }
787 820
788 } // namespace vr_shell 821 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/vr_shell.h ('k') | chrome/browser/android/vr_shell/vr_shell_gl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698