OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_ANDROID_VR_SHELL_VR_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_ANDROID_VR_SHELL_VR_CONTROLLER_H_ |
| 7 |
| 8 #include "base/memory/ref_counted.h" |
| 9 #include "chrome/browser/android/vr_shell/vr_gesture.h" |
| 10 #include "third_party/gvr-android-sdk/src/ndk-beta/include/vr/gvr/capi/include/g
vr.h" |
| 11 #include "third_party/gvr-android-sdk/src/ndk-beta/include/vr/gvr/capi/include/g
vr_controller.h" |
| 12 #include "third_party/gvr-android-sdk/src/ndk-beta/include/vr/gvr/capi/include/g
vr_types.h" |
| 13 |
| 14 namespace vr_shell { |
| 15 |
| 16 class VrController { |
| 17 public: |
| 18 // Controller API entry point. |
| 19 explicit VrController(gvr_context* gvr_context); |
| 20 ~VrController(); |
| 21 |
| 22 // Must be called when the Activity gets OnResume(). |
| 23 void OnResume(); |
| 24 |
| 25 // Must be called when the Activity gets OnPause(). |
| 26 void OnPause(); |
| 27 |
| 28 // Must be called when the GL renderer gets OnSurfaceCreated(). |
| 29 void Initialize(gvr_context* gvr_context); |
| 30 |
| 31 // Must be called when the GL renderer gets OnDrawFrame(). |
| 32 void UpdateState(); |
| 33 VrGesture DetectGesture(); |
| 34 |
| 35 bool IsTouching(); |
| 36 |
| 37 float TouchPosX(); |
| 38 |
| 39 float TouchPosY(); |
| 40 |
| 41 const gvr::Quatf Orientation(); |
| 42 |
| 43 bool IsTouchDown(); |
| 44 |
| 45 bool IsTouchUp(); |
| 46 |
| 47 bool IsButtonUp(const int32_t button); |
| 48 bool IsButtonDown(const int32_t button); |
| 49 |
| 50 bool IsConnected(); |
| 51 |
| 52 private: |
| 53 enum GestureDetectorState { |
| 54 WAITING, // waiting for user to touch down |
| 55 TOUCHING, // touching the touch pad but not scrolling |
| 56 SCROLLING // scrolling on the touch pad |
| 57 }; |
| 58 |
| 59 struct TouchPoint { |
| 60 gvr::Vec2f position; |
| 61 int64_t timestamp; |
| 62 }; |
| 63 |
| 64 struct TouchInfo { |
| 65 TouchPoint touch_point; |
| 66 bool touch_up; |
| 67 bool touch_down; |
| 68 bool is_touching; |
| 69 }; |
| 70 |
| 71 struct ButtonInfo { |
| 72 gvr::ControllerButton button; |
| 73 bool button_up; |
| 74 bool button_down; |
| 75 bool button_state; |
| 76 int64_t timestamp; |
| 77 }; |
| 78 |
| 79 void UpdateGestureFromTouchInfo(); |
| 80 |
| 81 bool GetButtonLongPressFromButtonInfo(); |
| 82 |
| 83 // Handle the waiting state. |
| 84 void HandleWaitingState(); |
| 85 |
| 86 // Handle the detecting state. |
| 87 void HandleDetectingState(); |
| 88 |
| 89 // Handle the scrolling state. |
| 90 void HandleScrollingState(); |
| 91 void Update(const gvr_controller_state* controller_state); |
| 92 void Update(bool touch_up, |
| 93 bool touch_down, |
| 94 bool is_touching, |
| 95 const gvr::Vec2f position, |
| 96 int64_t timestamp); |
| 97 |
| 98 // Returns true if the touch position is within the slop of the initial touch |
| 99 // point, false otherwise. |
| 100 bool InSlop(const gvr::Vec2f touch_position); |
| 101 |
| 102 void Reset(); |
| 103 |
| 104 size_t GetGestureListSize() { return gesture_list_.size(); } |
| 105 |
| 106 const VrGesture* GetGesturePtr(const size_t index); |
| 107 |
| 108 // Update gesture parameters, |
| 109 void UpdateGesture(VrGesture* gesture); |
| 110 |
| 111 // If the user is touching the touch pad and the touch point is different from |
| 112 // before, update the touch point and return true. Otherwise, return false. |
| 113 bool UpdateCurrentTouchpoint(); |
| 114 |
| 115 // State of gesture detector. |
| 116 GestureDetectorState state_; |
| 117 |
| 118 std::unique_ptr<gvr::ControllerApi> controller_api_; |
| 119 |
| 120 // The last controller state (updated once per frame). |
| 121 gvr::ControllerState controller_state_; |
| 122 |
| 123 float last_qx_; |
| 124 bool pinch_started_; |
| 125 bool zoom_in_progress_ = false; |
| 126 |
| 127 std::vector<VrGesture> gesture_list_; |
| 128 std::unique_ptr<TouchInfo> touch_info_; |
| 129 |
| 130 // A pointer storing the touch point from previous frame. |
| 131 std::unique_ptr<TouchPoint> prev_touch_point_; |
| 132 |
| 133 // A pointer storing the touch point from current frame. |
| 134 std::unique_ptr<TouchPoint> cur_touch_point_; |
| 135 |
| 136 // Initial touch point. |
| 137 std::unique_ptr<TouchPoint> init_touch_point_; |
| 138 |
| 139 // Overall velocity |
| 140 gvr::Vec2f overall_velocity_; |
| 141 |
| 142 DISALLOW_COPY_AND_ASSIGN(VrController); |
| 143 }; |
| 144 |
| 145 } // namespace vr_shell |
| 146 |
| 147 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_CONTROLLER_H_ |
OLD | NEW |