| 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 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 if (controller_api_) | 103 if (controller_api_) |
| 104 controller_api_->Pause(); | 104 controller_api_->Pause(); |
| 105 } | 105 } |
| 106 | 106 |
| 107 device::GvrGamepadData VrController::GetGamepadData() { | 107 device::GvrGamepadData VrController::GetGamepadData() { |
| 108 device::GvrGamepadData pad; | 108 device::GvrGamepadData pad; |
| 109 | 109 |
| 110 pad.timestamp = controller_state_->GetLastOrientationTimestamp(); | 110 pad.timestamp = controller_state_->GetLastOrientationTimestamp(); |
| 111 pad.touch_pos = controller_state_->GetTouchPos(); | 111 pad.touch_pos = controller_state_->GetTouchPos(); |
| 112 pad.orientation = controller_state_->GetOrientation(); | 112 pad.orientation = controller_state_->GetOrientation(); |
| 113 pad.accel = controller_state_->GetAccel(); | 113 |
| 114 pad.gyro = controller_state_->GetGyro(); | 114 // Use orientation to rotate acceleration/gyro into seated space. |
| 115 gvr::Mat4f pose_mat = QuatToMatrix(pad.orientation); |
| 116 pad.accel = MatrixVectorMul(pose_mat, controller_state_->GetAccel()); |
| 117 pad.gyro = MatrixVectorMul(pose_mat, controller_state_->GetGyro()); |
| 118 |
| 115 pad.is_touching = controller_state_->IsTouching(); | 119 pad.is_touching = controller_state_->IsTouching(); |
| 116 pad.controller_button_pressed = | 120 pad.controller_button_pressed = |
| 117 controller_state_->GetButtonState(GVR_CONTROLLER_BUTTON_CLICK); | 121 controller_state_->GetButtonState(GVR_CONTROLLER_BUTTON_CLICK); |
| 118 pad.right_handed = handedness_ == GVR_CONTROLLER_RIGHT_HANDED; | 122 pad.right_handed = handedness_ == GVR_CONTROLLER_RIGHT_HANDED; |
| 119 | 123 |
| 120 return pad; | 124 return pad; |
| 121 } | 125 } |
| 122 | 126 |
| 123 bool VrController::IsTouching() { | 127 bool VrController::IsTouching() { |
| 124 return controller_state_->IsTouching(); | 128 return controller_state_->IsTouching(); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 gvr::GvrApi::GetTimePointNow().monotonic_system_time_nanos; | 231 gvr::GvrApi::GetTimePointNow().monotonic_system_time_nanos; |
| 228 } | 232 } |
| 229 | 233 |
| 230 void VrController::Initialize(gvr_context* gvr_context) { | 234 void VrController::Initialize(gvr_context* gvr_context) { |
| 231 CHECK(gvr_context != nullptr) << "invalid gvr_context"; | 235 CHECK(gvr_context != nullptr) << "invalid gvr_context"; |
| 232 controller_api_.reset(new gvr::ControllerApi); | 236 controller_api_.reset(new gvr::ControllerApi); |
| 233 controller_state_.reset(new gvr::ControllerState); | 237 controller_state_.reset(new gvr::ControllerState); |
| 234 | 238 |
| 235 int32_t options = gvr::ControllerApi::DefaultOptions(); | 239 int32_t options = gvr::ControllerApi::DefaultOptions(); |
| 236 | 240 |
| 237 // Enable non-default options - WebVR needs gyro, and since VrShell | 241 // Enable non-default options - WebVR needs gyro and linear acceleration, and |
| 238 // implements GvrGamepadDataProvider we need this always. | 242 // since VrShell implements GvrGamepadDataProvider we need this always. |
| 239 options |= GVR_CONTROLLER_ENABLE_GYRO; | 243 options |= GVR_CONTROLLER_ENABLE_GYRO; |
| 244 options |= GVR_CONTROLLER_ENABLE_ACCEL; |
| 240 | 245 |
| 241 CHECK(controller_api_->Init(options, gvr_context)); | 246 CHECK(controller_api_->Init(options, gvr_context)); |
| 242 | 247 |
| 243 std::unique_ptr<gvr::GvrApi> gvr = gvr::GvrApi::WrapNonOwned(gvr_context); | 248 std::unique_ptr<gvr::GvrApi> gvr = gvr::GvrApi::WrapNonOwned(gvr_context); |
| 244 // TODO(bajones): Monitor changes to the controller handedness. | 249 // TODO(bajones): Monitor changes to the controller handedness. |
| 245 handedness_ = gvr->GetUserPrefs().GetControllerHandedness(); | 250 handedness_ = gvr->GetUserPrefs().GetControllerHandedness(); |
| 246 | 251 |
| 247 controller_api_->Resume(); | 252 controller_api_->Resume(); |
| 248 } | 253 } |
| 249 | 254 |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 gvr::Vec2f velocity = Vector::ScalarMult(displacement, 1 / duration); | 449 gvr::Vec2f velocity = Vector::ScalarMult(displacement, 1 / duration); |
| 445 | 450 |
| 446 float weight = duration / (kRC + duration); | 451 float weight = duration / (kRC + duration); |
| 447 | 452 |
| 448 overall_velocity_ = | 453 overall_velocity_ = |
| 449 Vector::Add(Vector::ScalarMult(overall_velocity_, 1 - weight), | 454 Vector::Add(Vector::ScalarMult(overall_velocity_, 1 - weight), |
| 450 Vector::ScalarMult(velocity, weight)); | 455 Vector::ScalarMult(velocity, weight)); |
| 451 } | 456 } |
| 452 | 457 |
| 453 } // namespace vr_shell | 458 } // namespace vr_shell |
| OLD | NEW |