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 "content/public/browser/android/content_view_core.h" | |
11 #include "content/public/browser/android/vr_gesture.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 namespace { | |
bshe
2016/09/21 15:18:41
nit: move this to .cc
asimjour
2016/09/22 14:48:36
Done.
| |
19 constexpr float kNanoSecondsPerSecond = 1.0e9f; | |
20 constexpr float kDisplacementScaleFactor = 800.0f; | |
21 // A slop represents a small rectangular region around the first touch point of | |
mthiesse
2016/09/21 16:13:44
nit: New line before comment, throughout this CL.
asimjour
2016/09/22 14:48:36
Done.
| |
22 // a gesture. | |
23 // If the user does not move outside of the slop, no gesture is detected. | |
24 // Gestures start to be detected when the user moves outside of the slop. | |
25 // Vertical distance from the border to the center of slop. | |
26 constexpr float kSlopVertical = 0.165f; | |
27 // Horizontal distance from the border to the center of slop. | |
28 constexpr float kSlopHorizontal = 0.125f; | |
29 constexpr float kDelta = 1.0e-7f; | |
30 constexpr float kCutoffHz = 10.0f; | |
31 constexpr float kRc = static_cast<float>(1.0 / (2.0 * M_PI * kCutoffHz)); | |
mthiesse
2016/09/21 16:13:44
nit: kRC
asimjour
2016/09/22 14:48:35
Done.
| |
32 | |
33 } // namespace | |
34 | |
35 class VrController { | |
36 public: | |
37 // Controller API entry point. | |
38 explicit VrController(gvr_context_* gvr_context); | |
39 ~VrController(); | |
40 | |
41 // Must be called when the Activity gets onResume(). | |
mthiesse
2016/09/21 16:13:44
nit: OnResume()
below too.
asimjour
2016/09/22 14:48:35
Done.
| |
42 void OnResume(); | |
43 | |
44 // Must be called when the Activity gets onPause(). | |
45 void OnPause(); | |
46 | |
47 // Must be called when the GL renderer gets onSurfaceCreated(). | |
48 void Initialize(gvr_context_* gvr_context); | |
49 | |
50 // Must be called when the GL renderer gets onDrawFrame(). | |
51 void UpdateState(); | |
52 VrGesture DetectGesture(); | |
53 | |
54 bool IsTouching(); | |
55 | |
56 float TouchPosX(); | |
57 | |
58 float TouchPosY(); | |
59 | |
60 const quatf Orientation(); | |
61 | |
62 bool IsTouchDown(); | |
63 | |
64 bool IsTouchUp(); | |
65 | |
66 bool ButtonUp(const int32_t button); | |
67 bool ButtonDown(const int32_t button); | |
68 | |
69 bool IsConnected(); | |
70 | |
71 private: | |
72 enum gesture_detector_state { | |
73 WAITING, // waiting for user to touch down | |
mthiesse
2016/09/21 16:13:44
nit: extra space
asimjour
2016/09/22 14:48:36
Done.
| |
74 TOUCHING, // touching the touch pad but not scrolling | |
75 SCROLLING // scrolling on the touch pad | |
76 }; | |
77 | |
78 struct TouchPoint { | |
79 vec2f position; | |
80 int64_t timestamp; | |
81 }; | |
82 | |
83 struct TouchInfo { | |
84 TouchPoint touch_point; | |
85 bool touch_up; | |
86 bool touch_down; | |
87 bool is_touching; | |
88 }; | |
89 | |
90 struct ButtonInfo { | |
91 gvr_controller_button button; | |
92 bool button_up; | |
93 bool button_down; | |
94 bool button_state; | |
95 int64_t timestamp; | |
96 }; | |
97 | |
98 // State of gesture detector. | |
99 gesture_detector_state state_; | |
100 | |
101 std::unique_ptr<gvr::ControllerApi> controller_api_; | |
102 // The last controller state (updated once per frame). | |
103 gvr::ControllerState controller_state_; | |
104 | |
105 float last_qx; | |
mthiesse
2016/09/21 16:13:44
nit: trailing underscore
Also below.
asimjour
2016/09/22 14:48:35
Done.
| |
106 float last_qz; | |
107 bool pinch_started; | |
108 bool zoom_in_progress; | |
109 | |
110 std::vector<VrGesture> gesture_list_; | |
111 std::unique_ptr<TouchInfo> touch_info_; | |
112 | |
113 // A pointer storing the touch point from previous frame. | |
114 std::unique_ptr<TouchPoint> prev_touch_point_; | |
115 | |
116 // A pointer storing the touch point from current frame. | |
117 std::unique_ptr<TouchPoint> cur_touch_point_; | |
118 | |
119 // Initial touch point. | |
120 std::unique_ptr<TouchPoint> init_touch_point_; | |
121 // Overall velocity | |
122 vec2f overall_velocity_; | |
123 | |
124 void UpdateGestureFromTouchInfo(); | |
mthiesse
2016/09/21 16:13:44
nit: Functions before member variables.
asimjour
2016/09/22 14:48:36
Done.
| |
125 | |
126 bool GetButtonLongPressFromButtonInfo(); | |
127 | |
128 // Handle the waiting state. | |
129 void HandleWaitingState(); | |
130 | |
131 // Handle the detecting state. | |
132 void HandleDetectingState(); | |
133 | |
134 // Handle the scrolling state. | |
135 void HandleScrollingState(); | |
136 void Update(const gvr_controller_state* controller_state); | |
137 void Update(bool touch_up, | |
138 bool touch_down, | |
139 bool is_touching, | |
140 const vec2f position, | |
141 int64_t timestamp); | |
142 // Returns true if the touch position is with in the slop of the initial touch | |
143 // point, | |
144 // false otherwise. | |
145 bool InSlop(const vec2f touch_position); | |
146 | |
147 void Reset(); | |
148 | |
149 int GetGestureListSize() { return static_cast<int>(gesture_list_.size()); } | |
150 | |
151 const VrGesture* GetGesturePtr(const int index); | |
152 | |
153 // Update gesture parameters, | |
154 void UpdateGesture(VrGesture* gesture); | |
155 | |
156 // If the user is touching the touch pad and the touch point is different from | |
157 // before, | |
mthiesse
2016/09/21 16:13:44
nit: no line break
asimjour
2016/09/22 14:48:36
Done.
| |
158 // update the touch point and return true. | |
159 // Otherwise, return false. | |
160 bool UpdateCurrentTouchpoint(); | |
161 }; | |
162 | |
163 } // namespace vr_shell | |
164 | |
165 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_CONTROLLER_H_ | |
OLD | NEW |