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