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 #include "device/vr/android/gvr/gvr_gamepad_data_fetcher.h" | 5 #include "device/vr/android/gvr/gvr_gamepad_data_fetcher.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 | 8 |
9 #include "device/vr/android/gvr/gvr_delegate.h" | 9 #include "device/vr/android/gvr/gvr_delegate.h" |
10 #include "third_party/WebKit/public/platform/WebGamepads.h" | 10 #include "third_party/WebKit/public/platform/WebGamepads.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
47 GvrGamepadDataFetcher::GvrGamepadDataFetcher(GvrDelegate* delegate, | 47 GvrGamepadDataFetcher::GvrGamepadDataFetcher(GvrDelegate* delegate, |
48 unsigned int display_id) | 48 unsigned int display_id) |
49 : display_id_(display_id) { | 49 : display_id_(display_id) { |
50 gvr::GvrApi* gvr_api = delegate->gvr_api(); | 50 gvr::GvrApi* gvr_api = delegate->gvr_api(); |
51 controller_api_.reset(new gvr::ControllerApi()); | 51 controller_api_.reset(new gvr::ControllerApi()); |
52 int32_t options = gvr::ControllerApi::DefaultOptions(); | 52 int32_t options = gvr::ControllerApi::DefaultOptions(); |
53 options |= GVR_CONTROLLER_ENABLE_GYRO; | 53 options |= GVR_CONTROLLER_ENABLE_GYRO; |
54 bool success = controller_api_->Init(options, gvr_api->GetContext()); | 54 bool success = controller_api_->Init(options, gvr_api->GetContext()); |
55 if (!success) | 55 if (!success) |
56 controller_api_.reset(nullptr); | 56 controller_api_.reset(nullptr); |
57 | |
58 user_prefs_.reset(new gvr::UserPrefs(gvr_api->GetUserPrefs().cobj())); | |
57 } | 59 } |
58 | 60 |
59 GvrGamepadDataFetcher::~GvrGamepadDataFetcher() {} | 61 GvrGamepadDataFetcher::~GvrGamepadDataFetcher() {} |
60 | 62 |
61 GamepadSource GvrGamepadDataFetcher::source() { | 63 GamepadSource GvrGamepadDataFetcher::source() { |
62 return GAMEPAD_SOURCE_GVR; | 64 return GAMEPAD_SOURCE_GVR; |
63 } | 65 } |
64 | 66 |
65 void GvrGamepadDataFetcher::OnAddedToProvider() { | 67 void GvrGamepadDataFetcher::OnAddedToProvider() { |
66 PauseHint(false); | 68 PauseHint(false); |
(...skipping 19 matching lines...) Expand all Loading... | |
86 pad.buttonsLength = 1; | 88 pad.buttonsLength = 1; |
87 pad.axesLength = 2; | 89 pad.axesLength = 2; |
88 | 90 |
89 pad.displayId = display_id_; | 91 pad.displayId = display_id_; |
90 } | 92 } |
91 | 93 |
92 controller_state_.Update(*controller_api_); | 94 controller_state_.Update(*controller_api_); |
93 | 95 |
94 pad.timestamp = controller_state_.GetLastOrientationTimestamp(); | 96 pad.timestamp = controller_state_.GetLastOrientationTimestamp(); |
95 | 97 |
96 // TODO: Query from API if avaialable. | 98 // TODO: Query from API if avaialable. |
billorr
2016/09/23 17:26:24
todo out of date?
| |
97 pad.hand = GamepadHandRight; | 99 gvr::ControllerHandedness handedness = user_prefs_->GetControllerHandedness(); |
100 pad.hand = (handedness == GVR_CONTROLLER_RIGHT_HANDED) ? GamepadHandRight | |
101 : GamepadHandLeft; | |
98 | 102 |
99 if (controller_state_.IsTouching()) { | 103 if (controller_state_.IsTouching()) { |
100 gvr_vec2f touch_position = controller_state_.GetTouchPos(); | 104 gvr_vec2f touch_position = controller_state_.GetTouchPos(); |
101 pad.axes[0] = (touch_position.x * 2.0f) - 1.0f; | 105 pad.axes[0] = (touch_position.x * 2.0f) - 1.0f; |
102 pad.axes[1] = (touch_position.y * 2.0f) - 1.0f; | 106 pad.axes[1] = (touch_position.y * 2.0f) - 1.0f; |
103 } else { | 107 } else { |
104 pad.axes[0] = 0.0f; | 108 pad.axes[0] = 0.0f; |
105 pad.axes[1] = 0.0f; | 109 pad.axes[1] = 0.0f; |
106 } | 110 } |
107 | 111 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 return; | 143 return; |
140 | 144 |
141 if (paused) { | 145 if (paused) { |
142 controller_api_->Pause(); | 146 controller_api_->Pause(); |
143 } else { | 147 } else { |
144 controller_api_->Resume(); | 148 controller_api_->Resume(); |
145 } | 149 } |
146 } | 150 } |
147 | 151 |
148 } // namespace device | 152 } // namespace device |
OLD | NEW |