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" | |
mthiesse
2016/09/30 14:09:36
I think you can forward declare
#include "base/ta
asimjour
2016/09/30 15:38:08
Removed extra #include. Only vr_gesture.h is remai
| |
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); | |
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); | |
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 IsButtonUp(const int32_t button); | |
50 bool IsButtonDown(const int32_t button); | |
51 | |
52 bool IsConnected(); | |
53 | |
54 private: | |
55 enum GestureDetectorState { | |
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; | |
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::ControllerButton 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 within the slop of the initial touch | |
101 // point, false otherwise. | |
102 bool InSlop(const gvr::Vec2f touch_position); | |
103 | |
104 void Reset(); | |
105 | |
106 size_t GetGestureListSize() { return gesture_list_.size(); } | |
107 | |
108 const VrGesture* GetGesturePtr(const size_t index); | |
109 | |
110 // Update gesture parameters, | |
111 void UpdateGesture(VrGesture* gesture); | |
112 | |
113 // If the user is touching the touch pad and the touch point is different from | |
114 // before, update the touch point and return true. Otherwise, return false. | |
115 bool UpdateCurrentTouchpoint(); | |
116 | |
117 // State of gesture detector. | |
118 GestureDetectorState state_; | |
119 | |
120 std::unique_ptr<gvr::ControllerApi> controller_api_; | |
121 | |
122 // The last controller state (updated once per frame). | |
123 gvr::ControllerState controller_state_; | |
124 | |
125 float last_qx_; | |
126 bool pinch_started_; | |
127 bool zoom_in_progress_ = false; | |
128 | |
129 std::vector<VrGesture> gesture_list_; | |
130 std::unique_ptr<TouchInfo> touch_info_; | |
131 | |
132 // A pointer storing the touch point from previous frame. | |
133 std::unique_ptr<TouchPoint> prev_touch_point_; | |
134 | |
135 // A pointer storing the touch point from current frame. | |
136 std::unique_ptr<TouchPoint> cur_touch_point_; | |
137 | |
138 // Initial touch point. | |
139 std::unique_ptr<TouchPoint> init_touch_point_; | |
140 | |
141 // Overall velocity | |
142 gvr::Vec2f overall_velocity_; | |
143 | |
144 DISALLOW_COPY_AND_ASSIGN(VrController); | |
145 }; | |
146 | |
147 } // namespace vr_shell | |
148 | |
149 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_CONTROLLER_H_ | |
OLD | NEW |