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

Side by Side Diff: chrome/browser/android/vr_shell/vr_controller.cc

Issue 2775283004: Rendering Daydream controller in a fixed position. (Closed)
Patch Set: Moving code to more appropriate locations. Created 3 years, 8 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 unified diff | Download patch
OLDNEW
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 "chrome/browser/android/vr_shell/vr_controller.h" 5 #include "chrome/browser/android/vr_shell/vr_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "chrome/browser/android/vr_shell/vr_math.h"
13 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/ gvr.h" 14 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/ gvr.h"
14 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/ gvr_controller.h" 15 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/ gvr_controller.h"
15 16
16 namespace vr_shell { 17 namespace vr_shell {
17 18
18 namespace { 19 namespace {
19 20
20 constexpr float kDisplacementScaleFactor = 300.0f; 21 constexpr float kDisplacementScaleFactor = 300.0f;
21 22
22 // A slop represents a small rectangular region around the first touch point of 23 // A slop represents a small rectangular region around the first touch point of
(...skipping 10 matching lines...) Expand all
33 // not equal. Also, minimum time distance needed to call two timestamps 34 // not equal. Also, minimum time distance needed to call two timestamps
34 // not equal. 35 // not equal.
35 constexpr float kDelta = 1.0e-7f; 36 constexpr float kDelta = 1.0e-7f;
36 37
37 constexpr float kCutoffHz = 10.0f; 38 constexpr float kCutoffHz = 10.0f;
38 constexpr float kRC = static_cast<float>(1.0 / (2.0 * M_PI * kCutoffHz)); 39 constexpr float kRC = static_cast<float>(1.0 / (2.0 * M_PI * kCutoffHz));
39 constexpr float kNanoSecondsPerSecond = 1.0e9f; 40 constexpr float kNanoSecondsPerSecond = 1.0e9f;
40 41
41 constexpr int kMaxNumOfExtrapolations = 2; 42 constexpr int kMaxNumOfExtrapolations = 2;
42 43
44 static constexpr gvr::Vec3f kControllerPosition = {0.2f, -0.5f, -0.15f};
45
43 class Vector { 46 class Vector {
44 public: 47 public:
45 static inline void ClampTouchpadPosition(gvr::Vec2f* position) { 48 static inline void ClampTouchpadPosition(gvr::Vec2f* position) {
46 position->x = std::min(std::max(0.0f, position->x), 1.0f); 49 position->x = std::min(std::max(0.0f, position->x), 1.0f);
47 position->y = std::min(std::max(0.0f, position->y), 1.0f); 50 position->y = std::min(std::max(0.0f, position->y), 1.0f);
48 } 51 }
49 52
50 static inline void SetZero(gvr::Vec2f* v) { 53 static inline void SetZero(gvr::Vec2f* v) {
51 v->x = 0; 54 v->x = 0;
52 v->y = 0; 55 v->y = 0;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 } 125 }
123 126
124 float VrController::TouchPosX() { 127 float VrController::TouchPosX() {
125 return controller_state_->GetTouchPos().x; 128 return controller_state_->GetTouchPos().x;
126 } 129 }
127 130
128 float VrController::TouchPosY() { 131 float VrController::TouchPosY() {
129 return controller_state_->GetTouchPos().y; 132 return controller_state_->GetTouchPos().y;
130 } 133 }
131 134
132 const gvr::Quatf VrController::Orientation() { 135 gvr::Quatf VrController::Orientation() const {
133 return controller_state_->GetOrientation(); 136 return controller_state_->GetOrientation();
134 } 137 }
135 138
139 gvr::Mat4f VrController::GetTransform() const {
140 // TODO(acondor): Position and orientation needs to be obtained
141 // from an elbow model.
142 // Placing the controller in a fixed position for now.
143 gvr::Mat4f mat;
144 SetIdentityM(mat);
145 // Changing rotation point.
146 TranslateM(mat, mat, 0, 0, 0.05);
147 mat = MatrixMul(QuatToMatrix(Orientation()), mat);
148 TranslateM(mat, mat, kControllerPosition.x, kControllerPosition.y,
149 kControllerPosition.z - 0.05);
150 return mat;
151 }
152
153 VrControllerModel::State VrController::GetModelState() const {
154 if (ButtonState(gvr::ControllerButton::GVR_CONTROLLER_BUTTON_CLICK))
155 return VrControllerModel::TOUCHPAD;
156 if (ButtonState(gvr::ControllerButton::GVR_CONTROLLER_BUTTON_APP))
157 return VrControllerModel::APP;
158 if (ButtonState(gvr::ControllerButton::GVR_CONTROLLER_BUTTON_HOME))
159 return VrControllerModel::SYSTEM;
160 return VrControllerModel::IDLE;
161 }
162
136 bool VrController::TouchDownHappened() { 163 bool VrController::TouchDownHappened() {
137 return controller_state_->GetTouchDown(); 164 return controller_state_->GetTouchDown();
138 } 165 }
139 166
140 bool VrController::TouchUpHappened() { 167 bool VrController::TouchUpHappened() {
141 return controller_state_->GetTouchUp(); 168 return controller_state_->GetTouchUp();
142 } 169 }
143 170
144 bool VrController::ButtonDownHappened(gvr::ControllerButton button) { 171 bool VrController::ButtonDownHappened(gvr::ControllerButton button) {
145 return controller_state_->GetButtonDown(button); 172 return controller_state_->GetButtonDown(button);
146 } 173 }
147 174
148 bool VrController::ButtonUpHappened(gvr::ControllerButton button) { 175 bool VrController::ButtonUpHappened(gvr::ControllerButton button) {
149 return controller_state_->GetButtonUp(button); 176 return controller_state_->GetButtonUp(button);
150 } 177 }
151 178
179 bool VrController::ButtonState(gvr::ControllerButton button) const {
180 return controller_state_->GetButtonState(button);
181 }
182
152 bool VrController::IsConnected() { 183 bool VrController::IsConnected() {
153 return controller_state_->GetConnectionState() == gvr::kControllerConnected; 184 return controller_state_->GetConnectionState() == gvr::kControllerConnected;
154 } 185 }
155 186
156 void VrController::UpdateState() { 187 void VrController::UpdateState() {
157 const int32_t old_status = controller_state_->GetApiStatus(); 188 const int32_t old_status = controller_state_->GetApiStatus();
158 const int32_t old_connection_state = controller_state_->GetConnectionState(); 189 const int32_t old_connection_state = controller_state_->GetConnectionState();
159 // Read current controller state. 190 // Read current controller state.
160 controller_state_->Update(*controller_api_); 191 controller_state_->Update(*controller_api_);
161 // Print new API status and connection state, if they changed. 192 // Print new API status and connection state, if they changed.
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 gvr::Vec2f velocity = Vector::ScalarMult(displacement, 1 / duration); 455 gvr::Vec2f velocity = Vector::ScalarMult(displacement, 1 / duration);
425 456
426 float weight = duration / (kRC + duration); 457 float weight = duration / (kRC + duration);
427 458
428 overall_velocity_ = 459 overall_velocity_ =
429 Vector::Add(Vector::ScalarMult(overall_velocity_, 1 - weight), 460 Vector::Add(Vector::ScalarMult(overall_velocity_, 1 - weight),
430 Vector::ScalarMult(velocity, weight)); 461 Vector::ScalarMult(velocity, weight));
431 } 462 }
432 463
433 } // namespace vr_shell 464 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/vr_controller.h ('k') | chrome/browser/android/vr_shell/vr_controller_model.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698