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/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/time/time.h" | |
| 14 #include "cc/base/math_util.h" | 13 #include "cc/base/math_util.h" |
| 15 #include "chrome/browser/android/vr_shell/elbow_model.h" | 14 #include "chrome/browser/android/vr_shell/elbow_model.h" |
| 16 #include "third_party/WebKit/public/platform/WebGestureEvent.h" | 15 #include "third_party/WebKit/public/platform/WebGestureEvent.h" |
| 17 #include "third_party/WebKit/public/platform/WebInputEvent.h" | 16 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
| 18 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/ gvr.h" | 17 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/ gvr.h" |
| 19 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/ gvr_controller.h" | 18 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/ gvr_controller.h" |
| 20 #include "ui/gfx/transform.h" | 19 #include "ui/gfx/transform.h" |
| 21 | 20 |
| 22 namespace vr_shell { | 21 namespace vr_shell { |
| 23 | 22 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 42 | 41 |
| 43 constexpr float kCutoffHz = 10.0f; | 42 constexpr float kCutoffHz = 10.0f; |
| 44 constexpr float kRC = static_cast<float>(1.0 / (2.0 * M_PI * kCutoffHz)); | 43 constexpr float kRC = static_cast<float>(1.0 / (2.0 * M_PI * kCutoffHz)); |
| 45 constexpr float kNanoSecondsPerSecond = 1.0e9f; | 44 constexpr float kNanoSecondsPerSecond = 1.0e9f; |
| 46 | 45 |
| 47 constexpr int kMaxNumOfExtrapolations = 2; | 46 constexpr int kMaxNumOfExtrapolations = 2; |
| 48 | 47 |
| 49 // Distance from the center of the controller to start rendering the laser. | 48 // Distance from the center of the controller to start rendering the laser. |
| 50 constexpr float kLaserStartDisplacement = 0.045; | 49 constexpr float kLaserStartDisplacement = 0.045; |
| 51 | 50 |
| 51 constexpr float microsPerNano = 1000.0; | |
|
cjgrant
2017/06/16 16:19:00
Why use a float? The types used with this are int
mthiesse
2017/06/16 17:24:11
Done.
| |
| 52 | |
| 52 void ClampTouchpadPosition(gfx::Vector2dF* position) { | 53 void ClampTouchpadPosition(gfx::Vector2dF* position) { |
| 53 position->set_x(cc::MathUtil::ClampToRange(position->x(), 0.0f, 1.0f)); | 54 position->set_x(cc::MathUtil::ClampToRange(position->x(), 0.0f, 1.0f)); |
| 54 position->set_y(cc::MathUtil::ClampToRange(position->y(), 0.0f, 1.0f)); | 55 position->set_y(cc::MathUtil::ClampToRange(position->y(), 0.0f, 1.0f)); |
| 55 } | 56 } |
| 56 | 57 |
| 57 float DeltaTimeSeconds(int64_t last_timestamp_nanos) { | 58 float DeltaTimeSeconds(int64_t last_timestamp_nanos) { |
| 58 return (gvr::GvrApi::GetTimePointNow().monotonic_system_time_nanos - | 59 return (gvr::GvrApi::GetTimePointNow().monotonic_system_time_nanos - |
| 59 last_timestamp_nanos) / | 60 last_timestamp_nanos) / |
| 60 kNanoSecondsPerSecond; | 61 kNanoSecondsPerSecond; |
| 61 } | 62 } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 } | 135 } |
| 135 | 136 |
| 136 float VrController::TouchPosX() { | 137 float VrController::TouchPosX() { |
| 137 return controller_state_->GetTouchPos().x; | 138 return controller_state_->GetTouchPos().x; |
| 138 } | 139 } |
| 139 | 140 |
| 140 float VrController::TouchPosY() { | 141 float VrController::TouchPosY() { |
| 141 return controller_state_->GetTouchPos().y; | 142 return controller_state_->GetTouchPos().y; |
| 142 } | 143 } |
| 143 | 144 |
| 145 base::TimeTicks VrController::GetLastOrientationTimestamp() const { | |
| 146 return base::TimeTicks::FromInternalValue( | |
| 147 controller_state_->GetLastOrientationTimestamp() / microsPerNano); | |
| 148 } | |
| 149 | |
| 150 base::TimeTicks VrController::GetLastTouchTimestamp() const { | |
| 151 return base::TimeTicks::FromInternalValue( | |
| 152 controller_state_->GetLastTouchTimestamp() / microsPerNano); | |
| 153 } | |
| 154 | |
| 155 base::TimeTicks VrController::GetLastButtonTimestamp() const { | |
| 156 return base::TimeTicks::FromInternalValue( | |
| 157 controller_state_->GetLastButtonTimestamp() / microsPerNano); | |
| 158 } | |
| 159 | |
| 144 gfx::Quaternion VrController::Orientation() const { | 160 gfx::Quaternion VrController::Orientation() const { |
| 145 const gvr::Quatf& orientation = controller_state_->GetOrientation(); | 161 const gvr::Quatf& orientation = controller_state_->GetOrientation(); |
| 146 return gfx::Quaternion(orientation.qx, orientation.qy, orientation.qz, | 162 return gfx::Quaternion(orientation.qx, orientation.qy, orientation.qz, |
| 147 orientation.qw); | 163 orientation.qw); |
| 148 } | 164 } |
| 149 | 165 |
| 150 void VrController::GetTransform(gfx::Transform* out) const { | 166 void VrController::GetTransform(gfx::Transform* out) const { |
| 151 *out = gfx::Transform(elbow_model_->GetControllerRotation()); | 167 *out = gfx::Transform(elbow_model_->GetControllerRotation()); |
| 152 gfx::Point3F p = elbow_model_->GetControllerPosition(); | 168 gfx::Point3F p = elbow_model_->GetControllerPosition(); |
| 153 out->matrix().postTranslate(p.x(), p.y(), p.z()); | 169 out->matrix().postTranslate(p.x(), p.y(), p.z()); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 gesture_list->push_back(std::move(fling)); | 299 gesture_list->push_back(std::move(fling)); |
| 284 } | 300 } |
| 285 Reset(); | 301 Reset(); |
| 286 } | 302 } |
| 287 | 303 |
| 288 return gesture_list; | 304 return gesture_list; |
| 289 } | 305 } |
| 290 | 306 |
| 291 void VrController::UpdateGestureFromTouchInfo(blink::WebGestureEvent* gesture) { | 307 void VrController::UpdateGestureFromTouchInfo(blink::WebGestureEvent* gesture) { |
| 292 gesture->SetTimeStampSeconds( | 308 gesture->SetTimeStampSeconds( |
| 293 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF()); | 309 (GetLastTouchTimestamp() - base::TimeTicks()).InSecondsF()); |
| 294 switch (state_) { | 310 switch (state_) { |
| 295 // User has not put finger on touch pad. | 311 // User has not put finger on touch pad. |
| 296 case WAITING: | 312 case WAITING: |
| 297 HandleWaitingState(gesture); | 313 HandleWaitingState(gesture); |
| 298 break; | 314 break; |
| 299 // User has not started a gesture (by moving out of slop). | 315 // User has not started a gesture (by moving out of slop). |
| 300 case TOUCHING: | 316 case TOUCHING: |
| 301 HandleDetectingState(gesture); | 317 HandleDetectingState(gesture); |
| 302 break; | 318 break; |
| 303 // User is scrolling on touchpad | 319 // User is scrolling on touchpad |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 436 | 452 |
| 437 const gfx::Vector2dF& velocity = ScaleVector2d(displacement, (1 / duration)); | 453 const gfx::Vector2dF& velocity = ScaleVector2d(displacement, (1 / duration)); |
| 438 | 454 |
| 439 float weight = duration / (kRC + duration); | 455 float weight = duration / (kRC + duration); |
| 440 | 456 |
| 441 overall_velocity_ = ScaleVector2d(overall_velocity_, (1 - weight)) + | 457 overall_velocity_ = ScaleVector2d(overall_velocity_, (1 - weight)) + |
| 442 ScaleVector2d(velocity, weight); | 458 ScaleVector2d(velocity, weight); |
| 443 } | 459 } |
| 444 | 460 |
| 445 } // namespace vr_shell | 461 } // namespace vr_shell |
| OLD | NEW |