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 "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "chrome/browser/android/vr_shell/vr_gesture.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" | 10 #include "third_party/gvr-android-sdk/src/ndk-beta/include/vr/gvr/capi/include/g
vr.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 void OnResume(); | 23 void OnResume(); |
24 | 24 |
25 // Must be called when the Activity gets OnPause(). | 25 // Must be called when the Activity gets OnPause(). |
26 void OnPause(); | 26 void OnPause(); |
27 | 27 |
28 // Must be called when the GL renderer gets OnSurfaceCreated(). | 28 // Must be called when the GL renderer gets OnSurfaceCreated(). |
29 void Initialize(gvr_context* gvr_context); | 29 void Initialize(gvr_context* gvr_context); |
30 | 30 |
31 // Must be called when the GL renderer gets OnDrawFrame(). | 31 // Must be called when the GL renderer gets OnDrawFrame(). |
32 void UpdateState(); | 32 void UpdateState(); |
33 VrGesture DetectGesture(); | 33 std::unique_ptr<VrGesture> DetectGesture(); |
34 | 34 |
35 bool IsTouching(); | 35 bool IsTouching(); |
36 | 36 |
37 float TouchPosX(); | 37 float TouchPosX(); |
38 | 38 |
39 float TouchPosY(); | 39 float TouchPosY(); |
40 | 40 |
41 const gvr::Quatf Orientation(); | 41 const gvr::Quatf Orientation(); |
42 | 42 |
43 bool IsTouchDown(); | 43 bool IsTouchDown(); |
(...skipping 25 matching lines...) Expand all Loading... |
69 }; | 69 }; |
70 | 70 |
71 struct ButtonInfo { | 71 struct ButtonInfo { |
72 gvr::ControllerButton button; | 72 gvr::ControllerButton button; |
73 bool button_up; | 73 bool button_up; |
74 bool button_down; | 74 bool button_down; |
75 bool button_state; | 75 bool button_state; |
76 int64_t timestamp; | 76 int64_t timestamp; |
77 }; | 77 }; |
78 | 78 |
79 void UpdateGestureFromTouchInfo(); | 79 void UpdateGestureFromTouchInfo(VrGesture* gesture); |
80 | 80 |
81 bool GetButtonLongPressFromButtonInfo(); | 81 bool GetButtonLongPressFromButtonInfo(); |
82 | 82 |
83 // Handle the waiting state. | 83 // Handle the waiting state. |
84 void HandleWaitingState(); | 84 void HandleWaitingState(); |
85 | 85 |
86 // Handle the detecting state. | 86 // Handle the detecting state. |
87 void HandleDetectingState(); | 87 void HandleDetectingState(VrGesture* gesture); |
88 | 88 |
89 // Handle the scrolling state. | 89 // Handle the scrolling state. |
90 void HandleScrollingState(); | 90 void HandleScrollingState(VrGesture* gesture); |
91 void Update(const gvr_controller_state* controller_state); | 91 void UpdateTouchInfo(); |
92 void Update(bool touch_up, | |
93 bool touch_down, | |
94 bool is_touching, | |
95 const gvr::Vec2f position, | |
96 int64_t timestamp); | |
97 | 92 |
98 // Returns true if the touch position is within the slop of the initial touch | 93 // Returns true if the touch position is within the slop of the initial touch |
99 // point, false otherwise. | 94 // point, false otherwise. |
100 bool InSlop(const gvr::Vec2f touch_position); | 95 bool InSlop(const gvr::Vec2f touch_position); |
101 | 96 |
102 void Reset(); | 97 void Reset(); |
103 | 98 |
104 size_t GetGestureListSize() { return gesture_list_.size(); } | |
105 | |
106 const VrGesture* GetGesturePtr(const size_t index); | |
107 | |
108 // Update gesture parameters, | 99 // Update gesture parameters, |
109 void UpdateGesture(VrGesture* gesture); | 100 void UpdateGesture(VrGesture* gesture); |
110 | 101 |
111 // If the user is touching the touch pad and the touch point is different from | 102 // 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. | 103 // before, update the touch point and return true. Otherwise, return false. |
113 bool UpdateCurrentTouchpoint(); | 104 bool UpdateCurrentTouchpoint(); |
114 | 105 |
115 // State of gesture detector. | 106 // State of gesture detector. |
116 GestureDetectorState state_; | 107 GestureDetectorState state_; |
117 | 108 |
118 std::unique_ptr<gvr::ControllerApi> controller_api_; | 109 std::unique_ptr<gvr::ControllerApi> controller_api_; |
119 | 110 |
120 // The last controller state (updated once per frame). | 111 // The last controller state (updated once per frame). |
121 gvr::ControllerState controller_state_; | 112 gvr::ControllerState controller_state_; |
122 | 113 |
123 float last_qx_; | 114 float last_qx_; |
124 bool pinch_started_; | 115 bool pinch_started_; |
125 bool zoom_in_progress_ = false; | 116 bool zoom_in_progress_ = false; |
126 | 117 |
127 std::vector<VrGesture> gesture_list_; | |
128 std::unique_ptr<TouchInfo> touch_info_; | 118 std::unique_ptr<TouchInfo> touch_info_; |
129 | 119 |
130 // A pointer storing the touch point from previous frame. | 120 // A pointer storing the touch point from previous frame. |
131 std::unique_ptr<TouchPoint> prev_touch_point_; | 121 std::unique_ptr<TouchPoint> prev_touch_point_; |
132 | 122 |
133 // A pointer storing the touch point from current frame. | 123 // A pointer storing the touch point from current frame. |
134 std::unique_ptr<TouchPoint> cur_touch_point_; | 124 std::unique_ptr<TouchPoint> cur_touch_point_; |
135 | 125 |
136 // Initial touch point. | 126 // Initial touch point. |
137 std::unique_ptr<TouchPoint> init_touch_point_; | 127 std::unique_ptr<TouchPoint> init_touch_point_; |
138 | 128 |
139 // Overall velocity | 129 // Overall velocity |
140 gvr::Vec2f overall_velocity_; | 130 gvr::Vec2f overall_velocity_; |
141 | 131 |
142 DISALLOW_COPY_AND_ASSIGN(VrController); | 132 DISALLOW_COPY_AND_ASSIGN(VrController); |
143 }; | 133 }; |
144 | 134 |
145 } // namespace vr_shell | 135 } // namespace vr_shell |
146 | 136 |
147 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_CONTROLLER_H_ | 137 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_CONTROLLER_H_ |
OLD | NEW |