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 #ifndef CHROME_BROWSER_ANDROID_VR_SHELL_VR_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_VR_SHELL_VR_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_ANDROID_VR_SHELL_VR_CONTROLLER_H_ | 6 #define CHROME_BROWSER_ANDROID_VR_SHELL_VR_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "chrome/browser/android/vr_shell/vr_controller_model.h" | 12 #include "chrome/browser/android/vr_shell/vr_controller_model.h" |
| 13 #include "device/vr/android/gvr/gvr_gamepad_data_provider.h" | 13 #include "device/vr/android/gvr/gvr_gamepad_data_provider.h" |
| 14 #include "device/vr/vr_types.h" | |
| 14 #include "third_party/WebKit/public/platform/WebGestureEvent.h" | 15 #include "third_party/WebKit/public/platform/WebGestureEvent.h" |
| 15 #include "third_party/WebKit/public/platform/WebInputEvent.h" | 16 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
| 16 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/ gvr_types.h" | 17 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/ gvr_types.h" |
| 17 | 18 |
| 18 using blink::WebGestureEvent; | 19 using blink::WebGestureEvent; |
| 19 using blink::WebInputEvent; | 20 using blink::WebInputEvent; |
| 20 | 21 |
| 21 namespace gvr { | 22 namespace gvr { |
| 22 class ControllerState; | 23 class ControllerState; |
| 23 } | 24 } |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 45 void UpdateState(); | 46 void UpdateState(); |
| 46 | 47 |
| 47 std::vector<std::unique_ptr<WebGestureEvent>> DetectGestures(); | 48 std::vector<std::unique_ptr<WebGestureEvent>> DetectGestures(); |
| 48 | 49 |
| 49 bool IsTouching(); | 50 bool IsTouching(); |
| 50 | 51 |
| 51 float TouchPosX(); | 52 float TouchPosX(); |
| 52 | 53 |
| 53 float TouchPosY(); | 54 float TouchPosY(); |
| 54 | 55 |
| 55 gvr::Quatf Orientation() const; | 56 vr::Quatf Orientation() const; |
| 56 | 57 |
| 57 gvr::Mat4f GetTransform() const; | 58 void GetTransform(vr::Matf* out) const; |
|
cjgrant
2017/04/11 13:44:40
Why not continue to return?
mthiesse
2017/04/11 14:46:43
As discussed offline, for consistency we're always
| |
| 58 | 59 |
| 59 VrControllerModel::State GetModelState() const; | 60 VrControllerModel::State GetModelState() const; |
| 60 | 61 |
| 61 bool TouchDownHappened(); | 62 bool TouchDownHappened(); |
| 62 | 63 |
| 63 bool TouchUpHappened(); | 64 bool TouchUpHappened(); |
| 64 | 65 |
| 65 bool ButtonUpHappened(gvr::ControllerButton button); | 66 bool ButtonUpHappened(gvr::ControllerButton button); |
| 66 bool ButtonDownHappened(gvr::ControllerButton button); | 67 bool ButtonDownHappened(gvr::ControllerButton button); |
| 67 bool ButtonState(gvr::ControllerButton button) const; | 68 bool ButtonState(gvr::ControllerButton button) const; |
| 68 | 69 |
| 69 bool IsConnected(); | 70 bool IsConnected(); |
| 70 | 71 |
| 71 private: | 72 private: |
| 72 enum GestureDetectorState { | 73 enum GestureDetectorState { |
| 73 WAITING, // waiting for user to touch down | 74 WAITING, // waiting for user to touch down |
| 74 TOUCHING, // touching the touch pad but not scrolling | 75 TOUCHING, // touching the touch pad but not scrolling |
| 75 SCROLLING // scrolling on the touch pad | 76 SCROLLING // scrolling on the touch pad |
| 76 }; | 77 }; |
| 77 | 78 |
| 78 struct TouchPoint { | 79 struct TouchPoint { |
| 79 gvr::Vec2f position; | 80 gfx::Vector2dF position; |
| 80 int64_t timestamp; | 81 int64_t timestamp; |
| 81 }; | 82 }; |
| 82 | 83 |
| 83 struct TouchInfo { | 84 struct TouchInfo { |
| 84 TouchPoint touch_point; | 85 TouchPoint touch_point; |
| 85 bool touch_up; | 86 bool touch_up; |
| 86 bool touch_down; | 87 bool touch_down; |
| 87 bool is_touching; | 88 bool is_touching; |
| 88 }; | 89 }; |
| 89 | 90 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 104 | 105 |
| 105 // Handle the detecting state. | 106 // Handle the detecting state. |
| 106 void HandleDetectingState(WebGestureEvent* gesture); | 107 void HandleDetectingState(WebGestureEvent* gesture); |
| 107 | 108 |
| 108 // Handle the scrolling state. | 109 // Handle the scrolling state. |
| 109 void HandleScrollingState(WebGestureEvent* gesture); | 110 void HandleScrollingState(WebGestureEvent* gesture); |
| 110 void UpdateTouchInfo(); | 111 void UpdateTouchInfo(); |
| 111 | 112 |
| 112 // Returns true if the touch position is within the slop of the initial touch | 113 // Returns true if the touch position is within the slop of the initial touch |
| 113 // point, false otherwise. | 114 // point, false otherwise. |
| 114 bool InSlop(const gvr::Vec2f touch_position); | 115 bool InSlop(const gfx::Vector2dF touch_position); |
| 115 | 116 |
| 116 // Returns true if the gesture is in horizontal direction. | 117 // Returns true if the gesture is in horizontal direction. |
| 117 bool IsHorizontalGesture(); | 118 bool IsHorizontalGesture(); |
| 118 | 119 |
| 119 void Reset(); | 120 void Reset(); |
| 120 | 121 |
| 121 void UpdateGestureParameters(); | 122 void UpdateGestureParameters(); |
| 122 | 123 |
| 123 // If the user is touching the touch pad and the touch point is different from | 124 // If the user is touching the touch pad and the touch point is different from |
| 124 // before, update the touch point and return true. Otherwise, return false. | 125 // before, update the touch point and return true. Otherwise, return false. |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 148 // A pointer storing the touch point from previous frame. | 149 // A pointer storing the touch point from previous frame. |
| 149 std::unique_ptr<TouchPoint> prev_touch_point_; | 150 std::unique_ptr<TouchPoint> prev_touch_point_; |
| 150 | 151 |
| 151 // A pointer storing the touch point from current frame. | 152 // A pointer storing the touch point from current frame. |
| 152 std::unique_ptr<TouchPoint> cur_touch_point_; | 153 std::unique_ptr<TouchPoint> cur_touch_point_; |
| 153 | 154 |
| 154 // Initial touch point. | 155 // Initial touch point. |
| 155 std::unique_ptr<TouchPoint> init_touch_point_; | 156 std::unique_ptr<TouchPoint> init_touch_point_; |
| 156 | 157 |
| 157 // Overall velocity | 158 // Overall velocity |
| 158 gvr::Vec2f overall_velocity_; | 159 gfx::Vector2dF overall_velocity_; |
| 159 | 160 |
| 160 // Last velocity that is used for fling and direction detection | 161 // Last velocity that is used for fling and direction detection |
| 161 gvr::Vec2f last_velocity_; | 162 gfx::Vector2dF last_velocity_; |
| 162 | 163 |
| 163 // Displacement of the touch point from the previews to the current touch | 164 // Displacement of the touch point from the previews to the current touch |
| 164 gvr::Vec2f displacement_; | 165 gfx::Vector2dF displacement_; |
| 165 | 166 |
| 166 int64_t last_touch_timestamp_ = 0; | 167 int64_t last_touch_timestamp_ = 0; |
| 167 int64_t last_timestamp_nanos_ = 0; | 168 int64_t last_timestamp_nanos_ = 0; |
| 168 | 169 |
| 169 // Number of consecutively extrapolated touch points | 170 // Number of consecutively extrapolated touch points |
| 170 int extrapolated_touch_ = 0; | 171 int extrapolated_touch_ = 0; |
| 171 | 172 |
| 172 DISALLOW_COPY_AND_ASSIGN(VrController); | 173 DISALLOW_COPY_AND_ASSIGN(VrController); |
| 173 }; | 174 }; |
| 174 | 175 |
| 175 } // namespace vr_shell | 176 } // namespace vr_shell |
| 176 | 177 |
| 177 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_CONTROLLER_H_ | 178 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_CONTROLLER_H_ |
| OLD | NEW |