| 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 <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 // Print new API status and connection state, if they changed. | 138 // Print new API status and connection state, if they changed. |
| 139 if (controller_state_->GetApiStatus() != old_status || | 139 if (controller_state_->GetApiStatus() != old_status || |
| 140 controller_state_->GetConnectionState() != old_connection_state) { | 140 controller_state_->GetConnectionState() != old_connection_state) { |
| 141 VLOG(1) << "Controller Connection status: " | 141 VLOG(1) << "Controller Connection status: " |
| 142 << gvr_controller_connection_state_to_string( | 142 << gvr_controller_connection_state_to_string( |
| 143 controller_state_->GetConnectionState()); | 143 controller_state_->GetConnectionState()); |
| 144 } | 144 } |
| 145 } | 145 } |
| 146 | 146 |
| 147 void VrController::UpdateTouchInfo() { | 147 void VrController::UpdateTouchInfo() { |
| 148 CHECK(touch_info_ != nullptr) << "touch_info_ not initialized properly."; | 148 // touch_info_ not initialized properly. |
| 149 CHECK(touch_info_ != nullptr); |
| 149 gvr::Vec2f position; | 150 gvr::Vec2f position; |
| 150 position.x = TouchPosX(); | 151 position.x = TouchPosX(); |
| 151 position.y = TouchPosY(); | 152 position.y = TouchPosY(); |
| 152 touch_info_->touch_up = TouchUpHappened(); | 153 touch_info_->touch_up = TouchUpHappened(); |
| 153 touch_info_->touch_down = TouchDownHappened(); | 154 touch_info_->touch_down = TouchDownHappened(); |
| 154 touch_info_->is_touching = IsTouching(); | 155 touch_info_->is_touching = IsTouching(); |
| 155 touch_info_->touch_point.position = position; | 156 touch_info_->touch_point.position = position; |
| 156 Vector::ClampTouchpadPosition(&touch_info_->touch_point.position); | 157 Vector::ClampTouchpadPosition(&touch_info_->touch_point.position); |
| 157 touch_info_->touch_point.timestamp = | 158 touch_info_->touch_point.timestamp = |
| 158 gvr::GvrApi::GetTimePointNow().monotonic_system_time_nanos; | 159 gvr::GvrApi::GetTimePointNow().monotonic_system_time_nanos; |
| 159 if (controller_state_->GetLastTouchTimestamp() == last_touch_timestamp_) { | 160 if (controller_state_->GetLastTouchTimestamp() == last_touch_timestamp_) { |
| 160 // Fill the touch_info | 161 // Fill the touch_info |
| 161 float duration = | 162 float duration = |
| 162 (gvr::GvrApi::GetTimePointNow().monotonic_system_time_nanos - | 163 (gvr::GvrApi::GetTimePointNow().monotonic_system_time_nanos - |
| 163 last_timestamp_nanos_) / | 164 last_timestamp_nanos_) / |
| 164 kNanoSecondsPerSecond; | 165 kNanoSecondsPerSecond; |
| 165 | 166 |
| 166 position.x += overall_velocity_.x * duration; | 167 position.x += overall_velocity_.x * duration; |
| 167 position.y += overall_velocity_.y * duration; | 168 position.y += overall_velocity_.y * duration; |
| 168 touch_info_->touch_point.position.x = position.x; | 169 touch_info_->touch_point.position.x = position.x; |
| 169 touch_info_->touch_point.position.y = position.y; | 170 touch_info_->touch_point.position.y = position.y; |
| 170 } | 171 } |
| 171 last_touch_timestamp_ = controller_state_->GetLastTouchTimestamp(); | 172 last_touch_timestamp_ = controller_state_->GetLastTouchTimestamp(); |
| 172 last_timestamp_nanos_ = | 173 last_timestamp_nanos_ = |
| 173 gvr::GvrApi::GetTimePointNow().monotonic_system_time_nanos; | 174 gvr::GvrApi::GetTimePointNow().monotonic_system_time_nanos; |
| 174 } | 175 } |
| 175 | 176 |
| 176 void VrController::Initialize(gvr_context* gvr_context) { | 177 void VrController::Initialize(gvr_context* gvr_context) { |
| 177 CHECK(gvr_context != nullptr) << "invalid gvr_context"; | 178 // invalid gvr_context |
| 179 CHECK(gvr_context != nullptr); |
| 178 controller_api_.reset(new gvr::ControllerApi); | 180 controller_api_.reset(new gvr::ControllerApi); |
| 179 controller_state_.reset(new gvr::ControllerState); | 181 controller_state_.reset(new gvr::ControllerState); |
| 180 int32_t options = gvr::ControllerApi::DefaultOptions(); | 182 int32_t options = gvr::ControllerApi::DefaultOptions(); |
| 181 | 183 |
| 182 // Enable non-default options, if you need them: | 184 // Enable non-default options, if you need them: |
| 183 // options |= GVR_CONTROLLER_ENABLE_GYRO; | 185 // options |= GVR_CONTROLLER_ENABLE_GYRO; |
| 184 CHECK(controller_api_->Init(options, gvr_context)); | 186 CHECK(controller_api_->Init(options, gvr_context)); |
| 185 controller_api_->Resume(); | 187 controller_api_->Resume(); |
| 186 } | 188 } |
| 187 | 189 |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 gvr::Vec2f velocity = Vector::ScalarMult(displacement, 1 / duration); | 368 gvr::Vec2f velocity = Vector::ScalarMult(displacement, 1 / duration); |
| 367 | 369 |
| 368 float weight = duration / (kRC + duration); | 370 float weight = duration / (kRC + duration); |
| 369 | 371 |
| 370 overall_velocity_ = | 372 overall_velocity_ = |
| 371 Vector::Add(Vector::ScalarMult(overall_velocity_, 1 - weight), | 373 Vector::Add(Vector::ScalarMult(overall_velocity_, 1 - weight), |
| 372 Vector::ScalarMult(velocity, weight)); | 374 Vector::ScalarMult(velocity, weight)); |
| 373 } | 375 } |
| 374 | 376 |
| 375 } // namespace vr_shell | 377 } // namespace vr_shell |
| OLD | NEW |