Commit e7f760bc authored by Brandon Jones's avatar Brandon Jones Committed by Commit Bot

Fix the controller being locked in place with 6DoF systems

gvr's Arm model apparently does not take into account the user's head position
on 6DoF systems, leaving the arm model "locked" in place near the origin. This
change manually offsets the controller model by the head's position so that the
arm model for the controller stays at a constant relative position to the head.
This yields behavior that matches Google's other first-party VR applications.

Bug: 831610
Change-Id: Id5cf7013c5b671e320304cd78bc80abd11580300
Reviewed-on: https://chromium-review.googlesource.com/1058558
Commit-Queue: Brandon Jones <bajones@chromium.org>
Reviewed-by: default avatarAmirhossein Simjour <asimjour@chromium.org>
Cr-Commit-Position: refs/heads/master@{#558833}
parent 453d85b0
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include "third_party/blink/public/platform/web_input_event.h" #include "third_party/blink/public/platform/web_input_event.h"
#include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/gvr.h" #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/gvr.h"
#include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/gvr_controller.h" #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/gvr_controller.h"
#include "ui/gfx/transform.h"
namespace vr { namespace vr {
...@@ -247,14 +246,16 @@ gfx::Quaternion VrController::Orientation() const { ...@@ -247,14 +246,16 @@ gfx::Quaternion VrController::Orientation() const {
} }
gfx::Point3F VrController::Position() const { gfx::Point3F VrController::Position() const {
gvr::Vec3f position = controller_state_->GetPosition(); const gvr::Vec3f& position = controller_state_->GetPosition();
return gfx::Point3F(position.x, position.y, position.z); return gfx::Point3F(position.x + head_offset_.x(),
position.y + head_offset_.y(),
position.z + head_offset_.z());
} }
void VrController::GetTransform(gfx::Transform* out) const { void VrController::GetTransform(gfx::Transform* out) const {
*out = gfx::Transform(Orientation()); *out = gfx::Transform(Orientation());
gvr::Vec3f position = controller_state_->GetPosition(); const gfx::Point3F& position = Position();
out->matrix().postTranslate(position.x, position.y, position.z); out->matrix().postTranslate(position.x(), position.y(), position.z());
} }
void VrController::GetRelativePointerTransform(gfx::Transform* out) const { void VrController::GetRelativePointerTransform(gfx::Transform* out) const {
...@@ -314,9 +315,17 @@ bool VrController::IsConnected() { ...@@ -314,9 +315,17 @@ bool VrController::IsConnected() {
return controller_state_->GetConnectionState() == gvr::kControllerConnected; return controller_state_->GetConnectionState() == gvr::kControllerConnected;
} }
void VrController::UpdateState(const gvr::Mat4f& head_direction) { void VrController::UpdateState(const gfx::Transform& head_pose) {
gfx::Transform inv_pose;
if (head_pose.GetInverse(&inv_pose)) {
head_offset_.SetPoint(0, 0, 0);
inv_pose.TransformPoint(&head_offset_);
}
gvr::Mat4f gvr_head_pose;
TransformToGvrMat(head_pose, &gvr_head_pose);
controller_api_->ApplyArmModel(handedness_, gvr::kArmModelBehaviorFollowGaze, controller_api_->ApplyArmModel(handedness_, gvr::kArmModelBehaviorFollowGaze,
head_direction); gvr_head_pose);
const int32_t old_status = controller_state_->GetApiStatus(); const int32_t old_status = controller_state_->GetApiStatus();
const int32_t old_connection_state = controller_state_->GetConnectionState(); const int32_t old_connection_state = controller_state_->GetConnectionState();
for (int button = 0; button < GVR_CONTROLLER_BUTTON_COUNT; ++button) { for (int button = 0; button < GVR_CONTROLLER_BUTTON_COUNT; ++button) {
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/android/vr/gvr_util.h"
#include "chrome/browser/vr/platform_controller.h" #include "chrome/browser/vr/platform_controller.h"
#include "device/vr/android/gvr/gvr_gamepad_data_provider.h" #include "device/vr/android/gvr/gvr_gamepad_data_provider.h"
#include "device/vr/public/mojom/vr_service.mojom.h" #include "device/vr/public/mojom/vr_service.mojom.h"
...@@ -18,6 +19,7 @@ ...@@ -18,6 +19,7 @@
#include "ui/gfx/geometry/quaternion.h" #include "ui/gfx/geometry/quaternion.h"
#include "ui/gfx/geometry/vector2d_f.h" #include "ui/gfx/geometry/vector2d_f.h"
#include "ui/gfx/geometry/vector3d_f.h" #include "ui/gfx/geometry/vector3d_f.h"
#include "ui/gfx/transform.h"
namespace blink { namespace blink {
class WebGestureEvent; class WebGestureEvent;
...@@ -54,7 +56,7 @@ class VrController : public PlatformController { ...@@ -54,7 +56,7 @@ class VrController : public PlatformController {
device::mojom::XRInputSourceStatePtr GetInputSourceState(); device::mojom::XRInputSourceStatePtr GetInputSourceState();
// Called once per frame to update controller state. // Called once per frame to update controller state.
void UpdateState(const gvr::Mat4f& head_direction); void UpdateState(const gfx::Transform& head_pose);
std::unique_ptr<GestureList> DetectGestures(); std::unique_ptr<GestureList> DetectGestures();
...@@ -192,6 +194,9 @@ class VrController : public PlatformController { ...@@ -192,6 +194,9 @@ class VrController : public PlatformController {
// Displacement of the touch point from the previews to the current touch // Displacement of the touch point from the previews to the current touch
gfx::Vector2dF displacement_; gfx::Vector2dF displacement_;
// Head offset. Keeps the controller at the user's side with 6DoF headsets.
gfx::Point3F head_offset_;
int64_t last_touch_timestamp_ = 0; int64_t last_touch_timestamp_ = 0;
int64_t last_timestamp_nanos_ = 0; int64_t last_timestamp_nanos_ = 0;
......
...@@ -1183,9 +1183,7 @@ void VrShellGl::UpdateViewports() { ...@@ -1183,9 +1183,7 @@ void VrShellGl::UpdateViewports() {
void VrShellGl::UpdateController(const RenderInfo& render_info, void VrShellGl::UpdateController(const RenderInfo& render_info,
base::TimeTicks current_time) { base::TimeTicks current_time) {
TRACE_EVENT0("gpu", "VrShellGl::UpdateController"); TRACE_EVENT0("gpu", "VrShellGl::UpdateController");
gvr::Mat4f gvr_head_pose; controller_->UpdateState(render_info.head_pose);
TransformToGvrMat(render_info.head_pose, &gvr_head_pose);
controller_->UpdateState(gvr_head_pose);
gfx::Point3F laser_origin = controller_->GetPointerStart(); gfx::Point3F laser_origin = controller_->GetPointerStart();
device::GvrGamepadData controller_data = controller_->GetGamepadData(); device::GvrGamepadData controller_data = controller_->GetGamepadData();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment