Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_controller.h" | 5 #include "chrome/browser/android/vr_shell/vr_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "chrome/browser/android/vr_shell/vr_math.h" | |
| 13 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/ gvr.h" | 14 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/ gvr.h" |
| 14 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/ gvr_controller.h" | 15 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/ gvr_controller.h" |
| 15 | 16 |
| 16 namespace vr_shell { | 17 namespace vr_shell { |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 constexpr float kDisplacementScaleFactor = 300.0f; | 21 constexpr float kDisplacementScaleFactor = 300.0f; |
| 21 | 22 |
| 22 // A slop represents a small rectangular region around the first touch point of | 23 // A slop represents a small rectangular region around the first touch point of |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 if (controller_api_) | 101 if (controller_api_) |
| 101 controller_api_->Pause(); | 102 controller_api_->Pause(); |
| 102 } | 103 } |
| 103 | 104 |
| 104 device::GvrGamepadData VrController::GetGamepadData() { | 105 device::GvrGamepadData VrController::GetGamepadData() { |
| 105 device::GvrGamepadData pad; | 106 device::GvrGamepadData pad; |
| 106 | 107 |
| 107 pad.timestamp = controller_state_->GetLastOrientationTimestamp(); | 108 pad.timestamp = controller_state_->GetLastOrientationTimestamp(); |
| 108 pad.touch_pos = controller_state_->GetTouchPos(); | 109 pad.touch_pos = controller_state_->GetTouchPos(); |
| 109 pad.orientation = controller_state_->GetOrientation(); | 110 pad.orientation = controller_state_->GetOrientation(); |
| 110 pad.accel = controller_state_->GetAccel(); | 111 |
| 111 pad.gyro = controller_state_->GetGyro(); | 112 // Use orientation to rotate acceleration/gyro into seated space. |
|
billorr
2017/03/27 17:33:53
nit: Accelerometer measurement or acceleration? I
klausw
2017/03/27 17:55:42
Acceleration and gravity are the same thing (blame
| |
| 113 gvr::Mat4f pose_mat = QuatToMatrix(pad.orientation); | |
| 114 pad.accel = MatrixVectorMul(pose_mat, controller_state_->GetAccel()); | |
| 115 pad.gyro = MatrixVectorMul(pose_mat, controller_state_->GetGyro()); | |
| 116 | |
| 112 pad.is_touching = controller_state_->IsTouching(); | 117 pad.is_touching = controller_state_->IsTouching(); |
| 113 pad.controller_button_pressed = | 118 pad.controller_button_pressed = |
| 114 controller_state_->GetButtonState(GVR_CONTROLLER_BUTTON_CLICK); | 119 controller_state_->GetButtonState(GVR_CONTROLLER_BUTTON_CLICK); |
| 115 pad.right_handed = handedness_ == GVR_CONTROLLER_RIGHT_HANDED; | 120 pad.right_handed = handedness_ == GVR_CONTROLLER_RIGHT_HANDED; |
| 116 | 121 |
| 117 return pad; | 122 return pad; |
| 118 } | 123 } |
| 119 | 124 |
| 120 bool VrController::IsTouching() { | 125 bool VrController::IsTouching() { |
| 121 return controller_state_->IsTouching(); | 126 return controller_state_->IsTouching(); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 196 gvr::GvrApi::GetTimePointNow().monotonic_system_time_nanos; | 201 gvr::GvrApi::GetTimePointNow().monotonic_system_time_nanos; |
| 197 } | 202 } |
| 198 | 203 |
| 199 void VrController::Initialize(gvr_context* gvr_context) { | 204 void VrController::Initialize(gvr_context* gvr_context) { |
| 200 CHECK(gvr_context != nullptr) << "invalid gvr_context"; | 205 CHECK(gvr_context != nullptr) << "invalid gvr_context"; |
| 201 controller_api_.reset(new gvr::ControllerApi); | 206 controller_api_.reset(new gvr::ControllerApi); |
| 202 controller_state_.reset(new gvr::ControllerState); | 207 controller_state_.reset(new gvr::ControllerState); |
| 203 | 208 |
| 204 int32_t options = gvr::ControllerApi::DefaultOptions(); | 209 int32_t options = gvr::ControllerApi::DefaultOptions(); |
| 205 | 210 |
| 206 // Enable non-default options - WebVR needs gyro, and since VrShell | 211 // Enable non-default options - WebVR needs gyro and linear acceleration, and |
| 207 // implements GvrGamepadDataProvider we need this always. | 212 // since VrShell implements GvrGamepadDataProvider we need this always. |
| 208 options |= GVR_CONTROLLER_ENABLE_GYRO; | 213 options |= GVR_CONTROLLER_ENABLE_GYRO; |
| 214 options |= GVR_CONTROLLER_ENABLE_ACCEL; | |
| 209 | 215 |
| 210 CHECK(controller_api_->Init(options, gvr_context)); | 216 CHECK(controller_api_->Init(options, gvr_context)); |
| 211 | 217 |
| 212 std::unique_ptr<gvr::GvrApi> gvr = gvr::GvrApi::WrapNonOwned(gvr_context); | 218 std::unique_ptr<gvr::GvrApi> gvr = gvr::GvrApi::WrapNonOwned(gvr_context); |
| 213 // TODO(bajones): Monitor changes to the controller handedness. | 219 // TODO(bajones): Monitor changes to the controller handedness. |
| 214 handedness_ = gvr->GetUserPrefs().GetControllerHandedness(); | 220 handedness_ = gvr->GetUserPrefs().GetControllerHandedness(); |
| 215 | 221 |
| 216 // Work around an obscure link error in component build. | 222 // Work around an obscure link error in component build. |
| 217 // third_party/gvr-android-sdk/libgvr_shim_static_arm.a needs | 223 // third_party/gvr-android-sdk/libgvr_shim_static_arm.a needs |
| 218 // __aeabi_f2lz (float to int64_t static cast implementation) for | 224 // __aeabi_f2lz (float to int64_t static cast implementation) for |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 424 gvr::Vec2f velocity = Vector::ScalarMult(displacement, 1 / duration); | 430 gvr::Vec2f velocity = Vector::ScalarMult(displacement, 1 / duration); |
| 425 | 431 |
| 426 float weight = duration / (kRC + duration); | 432 float weight = duration / (kRC + duration); |
| 427 | 433 |
| 428 overall_velocity_ = | 434 overall_velocity_ = |
| 429 Vector::Add(Vector::ScalarMult(overall_velocity_, 1 - weight), | 435 Vector::Add(Vector::ScalarMult(overall_velocity_, 1 - weight), |
| 430 Vector::ScalarMult(velocity, weight)); | 436 Vector::ScalarMult(velocity, weight)); |
| 431 } | 437 } |
| 432 | 438 |
| 433 } // namespace vr_shell | 439 } // namespace vr_shell |
| OLD | NEW |