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

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

Issue 2770353002: WebVR: add angular velocity estimate to pose (Closed)
Patch Set: Created 3 years, 9 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
688 // rotation axis with magnitude equal to rotation speed in
689 // radians/second.
690 //
691 // The spec isn't very clear on details, clarification requested in
692 // https://github.com/w3c/webvr/issues/212 .
693 //
694 // Assume we're using right-hand rule for direction and a
695 // headset-attached frame of reference with +X to the right, +Y up,
696 // and +Z backwards (towards back of head).
697 //
698 // Examples:
699 // - "look up" motion: (positive, 0, 0)
700 // - "turn left" motion: (0, positive, 0)
701 // - "lean head left" motion: (0, 0, positive)
702 //
703 // Assuming that pose prediction is simply based on adding a time *
704 // angular velocity rotation to the pose, we can approximate the
705 // angular velocity from the difference between two successive
706 // poses. This is a first order estimate that assumes small enough
707 // rotations so that we can do linear approximation.
708 pose->angularVelocity.emplace(3);
709 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
710 pose->angularVelocity.value()[0] =
711 (head_mat_2.m[1][2] - head_mat.m[1][2]) / epsilon_seconds;
712 pose->angularVelocity.value()[1] =
713 -(head_mat_2.m[0][2] - head_mat.m[0][2]) / epsilon_seconds;
714 pose->angularVelocity.value()[2] =
715 (head_mat_2.m[0][1] - head_mat.m[0][1]) / epsilon_seconds;
716
685 return pose; 717 return pose;
686 } 718 }
687 719
688 /* static */ 720 /* static */
689 gvr::Sizei VrShell::GetRecommendedWebVrSize(gvr::GvrApi* gvr_api) { 721 gvr::Sizei VrShell::GetRecommendedWebVrSize(gvr::GvrApi* gvr_api) {
690 // Pick a reasonable default size for the WebVR transfer surface 722 // Pick a reasonable default size for the WebVR transfer surface
691 // based on a downscaled 1:1 render resolution. This size will also 723 // based on a downscaled 1:1 render resolution. This size will also
692 // be reported to the client via CreateVRDisplayInfo as the 724 // be reported to the client via CreateVRDisplayInfo as the
693 // client-recommended renderWidth/renderHeight and for the GVR 725 // client-recommended renderWidth/renderHeight and for the GVR
694 // framebuffer. If the client chooses a different size or resizes it 726 // 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) { 811 jboolean reprojected_rendering) {
780 return reinterpret_cast<intptr_t>(new VrShell( 812 return reinterpret_cast<intptr_t>(new VrShell(
781 env, obj, reinterpret_cast<ui::WindowAndroid*>(content_window_android), 813 env, obj, reinterpret_cast<ui::WindowAndroid*>(content_window_android),
782 content::WebContents::FromJavaWebContents(ui_web_contents), 814 content::WebContents::FromJavaWebContents(ui_web_contents),
783 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), for_web_vr, 815 reinterpret_cast<ui::WindowAndroid*>(ui_window_android), for_web_vr,
784 VrShellDelegate::GetNativeVrShellDelegate(env, delegate), 816 VrShellDelegate::GetNativeVrShellDelegate(env, delegate),
785 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering)); 817 reinterpret_cast<gvr_context*>(gvr_api), reprojected_rendering));
786 } 818 }
787 819
788 } // namespace vr_shell 820 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698