| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 vect_prod.x = v.x * scalar; | 75 vect_prod.x = v.x * scalar; |
| 76 vect_prod.y = v.y * scalar; | 76 vect_prod.y = v.y * scalar; |
| 77 return vect_prod; | 77 return vect_prod; |
| 78 } | 78 } |
| 79 | 79 |
| 80 }; // Vector | 80 }; // Vector |
| 81 | 81 |
| 82 } // namespace | 82 } // namespace |
| 83 | 83 |
| 84 VrController::VrController(gvr_context* vr_context) { | 84 VrController::VrController(gvr_context* vr_context) { |
| 85 DVLOG(1) << __FUNCTION__ << "=" << this; |
| 85 Initialize(vr_context); | 86 Initialize(vr_context); |
| 86 Reset(); | 87 Reset(); |
| 87 } | 88 } |
| 88 | 89 |
| 89 VrController::~VrController() {} | 90 VrController::~VrController() { |
| 91 DVLOG(1) << __FUNCTION__ << "=" << this; |
| 92 } |
| 90 | 93 |
| 91 void VrController::OnResume() { | 94 void VrController::OnResume() { |
| 92 if (controller_api_) | 95 if (controller_api_) |
| 93 controller_api_->Resume(); | 96 controller_api_->Resume(); |
| 94 } | 97 } |
| 95 | 98 |
| 96 void VrController::OnPause() { | 99 void VrController::OnPause() { |
| 97 if (controller_api_) | 100 if (controller_api_) |
| 98 controller_api_->Pause(); | 101 controller_api_->Pause(); |
| 99 } | 102 } |
| 100 | 103 |
| 104 device::GvrGamepadData VrController::GetGamepadData() { |
| 105 device::GvrGamepadData pad; |
| 106 |
| 107 pad.timestamp = controller_state_->GetLastOrientationTimestamp(); |
| 108 pad.touch_pos = controller_state_->GetTouchPos(); |
| 109 pad.orientation = controller_state_->GetOrientation(); |
| 110 pad.accel = controller_state_->GetAccel(); |
| 111 pad.gyro = controller_state_->GetGyro(); |
| 112 pad.is_touching = controller_state_->IsTouching(); |
| 113 pad.controller_button_pressed = |
| 114 controller_state_->GetButtonState(GVR_CONTROLLER_BUTTON_CLICK); |
| 115 pad.right_handed = handedness_ == GVR_CONTROLLER_RIGHT_HANDED; |
| 116 |
| 117 return pad; |
| 118 } |
| 119 |
| 101 bool VrController::IsTouching() { | 120 bool VrController::IsTouching() { |
| 102 return controller_state_->IsTouching(); | 121 return controller_state_->IsTouching(); |
| 103 } | 122 } |
| 104 | 123 |
| 105 float VrController::TouchPosX() { | 124 float VrController::TouchPosX() { |
| 106 return controller_state_->GetTouchPos().x; | 125 return controller_state_->GetTouchPos().x; |
| 107 } | 126 } |
| 108 | 127 |
| 109 float VrController::TouchPosY() { | 128 float VrController::TouchPosY() { |
| 110 return controller_state_->GetTouchPos().y; | 129 return controller_state_->GetTouchPos().y; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 } | 193 } |
| 175 last_touch_timestamp_ = controller_state_->GetLastTouchTimestamp(); | 194 last_touch_timestamp_ = controller_state_->GetLastTouchTimestamp(); |
| 176 last_timestamp_nanos_ = | 195 last_timestamp_nanos_ = |
| 177 gvr::GvrApi::GetTimePointNow().monotonic_system_time_nanos; | 196 gvr::GvrApi::GetTimePointNow().monotonic_system_time_nanos; |
| 178 } | 197 } |
| 179 | 198 |
| 180 void VrController::Initialize(gvr_context* gvr_context) { | 199 void VrController::Initialize(gvr_context* gvr_context) { |
| 181 CHECK(gvr_context != nullptr) << "invalid gvr_context"; | 200 CHECK(gvr_context != nullptr) << "invalid gvr_context"; |
| 182 controller_api_.reset(new gvr::ControllerApi); | 201 controller_api_.reset(new gvr::ControllerApi); |
| 183 controller_state_.reset(new gvr::ControllerState); | 202 controller_state_.reset(new gvr::ControllerState); |
| 203 |
| 184 int32_t options = gvr::ControllerApi::DefaultOptions(); | 204 int32_t options = gvr::ControllerApi::DefaultOptions(); |
| 185 | 205 |
| 186 // Enable non-default options, if you need them: | 206 // Enable non-default options - WebVR needs gyro, and since VrShell |
| 187 // options |= GVR_CONTROLLER_ENABLE_GYRO; | 207 // implements GvrGamepadDataProvider we need this always. |
| 208 options |= GVR_CONTROLLER_ENABLE_GYRO; |
| 209 |
| 188 CHECK(controller_api_->Init(options, gvr_context)); | 210 CHECK(controller_api_->Init(options, gvr_context)); |
| 211 |
| 212 std::unique_ptr<gvr::GvrApi> gvr = gvr::GvrApi::WrapNonOwned(gvr_context); |
| 213 // TODO(bajones): Monitor changes to the controller handedness. |
| 214 handedness_ = gvr->GetUserPrefs().GetControllerHandedness(); |
| 215 |
| 216 // Work around an obscure link error in component build. |
| 217 // third_party/gvr-android-sdk/libgvr_shim_static_arm.a needs |
| 218 // __aeabi_f2lz (float to int64_t static cast implementation) for |
| 219 // ION's logging.cc::ThrottledLogger. Somehow this is no longer |
| 220 // being provided, so convince the compiler to emit it here so that |
| 221 // it's resolvable when linking libchrome.so. |
| 222 // TODO(bshe,crbug.com/704305): look into a more elegant fix? |
| 223 volatile float fixme_float = 1.3f; |
| 224 volatile int64_t fixme_int64 = static_cast<int64_t>(fixme_float); |
| 225 (void)fixme_int64; |
| 226 |
| 189 controller_api_->Resume(); | 227 controller_api_->Resume(); |
| 190 } | 228 } |
| 191 | 229 |
| 192 std::vector<std::unique_ptr<WebGestureEvent>> VrController::DetectGestures() { | 230 std::vector<std::unique_ptr<WebGestureEvent>> VrController::DetectGestures() { |
| 193 std::vector<std::unique_ptr<WebGestureEvent>> gesture_list; | 231 std::vector<std::unique_ptr<WebGestureEvent>> gesture_list; |
| 194 std::unique_ptr<WebGestureEvent> gesture(new WebGestureEvent()); | 232 std::unique_ptr<WebGestureEvent> gesture(new WebGestureEvent()); |
| 195 | 233 |
| 196 if (controller_state_->GetConnectionState() != gvr::kControllerConnected) { | 234 if (controller_state_->GetConnectionState() != gvr::kControllerConnected) { |
| 197 gesture_list.push_back(std::move(gesture)); | 235 gesture_list.push_back(std::move(gesture)); |
| 198 return gesture_list; | 236 return gesture_list; |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 gvr::Vec2f velocity = Vector::ScalarMult(displacement, 1 / duration); | 424 gvr::Vec2f velocity = Vector::ScalarMult(displacement, 1 / duration); |
| 387 | 425 |
| 388 float weight = duration / (kRC + duration); | 426 float weight = duration / (kRC + duration); |
| 389 | 427 |
| 390 overall_velocity_ = | 428 overall_velocity_ = |
| 391 Vector::Add(Vector::ScalarMult(overall_velocity_, 1 - weight), | 429 Vector::Add(Vector::ScalarMult(overall_velocity_, 1 - weight), |
| 392 Vector::ScalarMult(velocity, weight)); | 430 Vector::ScalarMult(velocity, weight)); |
| 393 } | 431 } |
| 394 | 432 |
| 395 } // namespace vr_shell | 433 } // namespace vr_shell |
| OLD | NEW |