Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4509)

Unified Diff: chrome/browser/android/vr_shell/vr_controller.h

Issue 2350253004: Controller support for VrShell (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/android/vr_shell/vr_controller.h
diff --git a/chrome/browser/android/vr_shell/vr_controller.h b/chrome/browser/android/vr_shell/vr_controller.h
new file mode 100644
index 0000000000000000000000000000000000000000..f51e472f6fb454a37ce654fb434266872fd6757d
--- /dev/null
+++ b/chrome/browser/android/vr_shell/vr_controller.h
@@ -0,0 +1,165 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_ANDROID_VR_SHELL_VR_CONTROLLER_H_
+#define CHROME_BROWSER_ANDROID_VR_SHELL_VR_CONTROLLER_H_
+
+#include "base/memory/ref_counted.h"
+#include "base/task_runner_util.h"
+#include "content/public/browser/android/content_view_core.h"
+#include "content/public/browser/android/vr_gesture.h"
+#include "third_party/gvr-android-sdk/src/ndk-beta/include/vr/gvr/capi/include/gvr.h"
+#include "third_party/gvr-android-sdk/src/ndk-beta/include/vr/gvr/capi/include/gvr_controller.h"
+#include "third_party/gvr-android-sdk/src/ndk-beta/include/vr/gvr/capi/include/gvr_types.h"
+
+namespace vr_shell {
+
+namespace {
bshe 2016/09/21 15:18:41 nit: move this to .cc
asimjour 2016/09/22 14:48:36 Done.
+constexpr float kNanoSecondsPerSecond = 1.0e9f;
+constexpr float kDisplacementScaleFactor = 800.0f;
+// 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.
+// a gesture.
+// If the user does not move outside of the slop, no gesture is detected.
+// Gestures start to be detected when the user moves outside of the slop.
+// Vertical distance from the border to the center of slop.
+constexpr float kSlopVertical = 0.165f;
+// Horizontal distance from the border to the center of slop.
+constexpr float kSlopHorizontal = 0.125f;
+constexpr float kDelta = 1.0e-7f;
+constexpr float kCutoffHz = 10.0f;
+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.
+
+} // namespace
+
+class VrController {
+ public:
+ // Controller API entry point.
+ explicit VrController(gvr_context_* gvr_context);
+ ~VrController();
+
+ // 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.
+ void OnResume();
+
+ // Must be called when the Activity gets onPause().
+ void OnPause();
+
+ // Must be called when the GL renderer gets onSurfaceCreated().
+ void Initialize(gvr_context_* gvr_context);
+
+ // Must be called when the GL renderer gets onDrawFrame().
+ void UpdateState();
+ VrGesture DetectGesture();
+
+ bool IsTouching();
+
+ float TouchPosX();
+
+ float TouchPosY();
+
+ const quatf Orientation();
+
+ bool IsTouchDown();
+
+ bool IsTouchUp();
+
+ bool ButtonUp(const int32_t button);
+ bool ButtonDown(const int32_t button);
+
+ bool IsConnected();
+
+ private:
+ enum gesture_detector_state {
+ 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.
+ TOUCHING, // touching the touch pad but not scrolling
+ SCROLLING // scrolling on the touch pad
+ };
+
+ struct TouchPoint {
+ vec2f position;
+ int64_t timestamp;
+ };
+
+ struct TouchInfo {
+ TouchPoint touch_point;
+ bool touch_up;
+ bool touch_down;
+ bool is_touching;
+ };
+
+ struct ButtonInfo {
+ gvr_controller_button button;
+ bool button_up;
+ bool button_down;
+ bool button_state;
+ int64_t timestamp;
+ };
+
+ // State of gesture detector.
+ gesture_detector_state state_;
+
+ std::unique_ptr<gvr::ControllerApi> controller_api_;
+ // The last controller state (updated once per frame).
+ gvr::ControllerState controller_state_;
+
+ float last_qx;
mthiesse 2016/09/21 16:13:44 nit: trailing underscore Also below.
asimjour 2016/09/22 14:48:35 Done.
+ float last_qz;
+ bool pinch_started;
+ bool zoom_in_progress;
+
+ std::vector<VrGesture> gesture_list_;
+ std::unique_ptr<TouchInfo> touch_info_;
+
+ // A pointer storing the touch point from previous frame.
+ std::unique_ptr<TouchPoint> prev_touch_point_;
+
+ // A pointer storing the touch point from current frame.
+ std::unique_ptr<TouchPoint> cur_touch_point_;
+
+ // Initial touch point.
+ std::unique_ptr<TouchPoint> init_touch_point_;
+ // Overall velocity
+ vec2f overall_velocity_;
+
+ void UpdateGestureFromTouchInfo();
mthiesse 2016/09/21 16:13:44 nit: Functions before member variables.
asimjour 2016/09/22 14:48:36 Done.
+
+ bool GetButtonLongPressFromButtonInfo();
+
+ // Handle the waiting state.
+ void HandleWaitingState();
+
+ // Handle the detecting state.
+ void HandleDetectingState();
+
+ // Handle the scrolling state.
+ void HandleScrollingState();
+ void Update(const gvr_controller_state* controller_state);
+ void Update(bool touch_up,
+ bool touch_down,
+ bool is_touching,
+ const vec2f position,
+ int64_t timestamp);
+ // Returns true if the touch position is with in the slop of the initial touch
+ // point,
+ // false otherwise.
+ bool InSlop(const vec2f touch_position);
+
+ void Reset();
+
+ int GetGestureListSize() { return static_cast<int>(gesture_list_.size()); }
+
+ const VrGesture* GetGesturePtr(const int index);
+
+ // Update gesture parameters,
+ void UpdateGesture(VrGesture* gesture);
+
+ // If the user is touching the touch pad and the touch point is different from
+ // before,
mthiesse 2016/09/21 16:13:44 nit: no line break
asimjour 2016/09/22 14:48:36 Done.
+ // update the touch point and return true.
+ // Otherwise, return false.
+ bool UpdateCurrentTouchpoint();
+};
+
+} // namespace vr_shell
+
+#endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_CONTROLLER_H_

Powered by Google App Engine
This is Rietveld 408576698