| 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_device.h" | 5 #include "device/vr/android/gvr/gvr_device.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 | 9 |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 right_eye->offset[2] = -right_eye_mat.m[2][3]; | 143 right_eye->offset[2] = -right_eye_mat.m[2][3]; |
| 144 | 144 |
| 145 if (delegate_) { | 145 if (delegate_) { |
| 146 delegate_->SetWebVRRenderSurfaceSize(2 * left_eye->renderWidth, | 146 delegate_->SetWebVRRenderSurfaceSize(2 * left_eye->renderWidth, |
| 147 left_eye->renderHeight); | 147 left_eye->renderHeight); |
| 148 } | 148 } |
| 149 | 149 |
| 150 return device; | 150 return device; |
| 151 } | 151 } |
| 152 | 152 |
| 153 mojom::VRPosePtr GvrDevice::GetPose() { | |
| 154 TRACE_EVENT0("input", "GvrDevice::GetSensorState"); | |
| 155 | |
| 156 mojom::VRPosePtr pose = mojom::VRPose::New(); | |
| 157 | |
| 158 pose->timestamp = base::Time::Now().ToJsTime(); | |
| 159 | |
| 160 // Increment pose frame counter always, even if it's a faked pose. | |
| 161 pose->poseIndex = ++pose_index_; | |
| 162 | |
| 163 pose->orientation.emplace(4); | |
| 164 | |
| 165 gvr::GvrApi* gvr_api = GetGvrApi(); | |
| 166 if (!gvr_api) { | |
| 167 // If we don't have a GvrApi instance return a static forward orientation. | |
| 168 pose->orientation.value()[0] = 0.0; | |
| 169 pose->orientation.value()[1] = 0.0; | |
| 170 pose->orientation.value()[2] = 0.0; | |
| 171 pose->orientation.value()[3] = 1.0; | |
| 172 | |
| 173 return pose; | |
| 174 } | |
| 175 | |
| 176 if (!delegate_) | |
| 177 return nullptr; | |
| 178 | |
| 179 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); | |
| 180 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos; | |
| 181 | |
| 182 gvr::Mat4f head_mat = | |
| 183 gvr_api->GetHeadSpaceFromStartSpaceRotation(target_time); | |
| 184 head_mat = gvr_api->ApplyNeckModel(head_mat, 1.0f); | |
| 185 | |
| 186 gfx::Transform inv_transform( | |
| 187 head_mat.m[0][0], head_mat.m[0][1], head_mat.m[0][2], head_mat.m[0][3], | |
| 188 head_mat.m[1][0], head_mat.m[1][1], head_mat.m[1][2], head_mat.m[1][3], | |
| 189 head_mat.m[2][0], head_mat.m[2][1], head_mat.m[2][2], head_mat.m[2][3], | |
| 190 head_mat.m[3][0], head_mat.m[3][1], head_mat.m[3][2], head_mat.m[3][3]); | |
| 191 | |
| 192 gfx::Transform transform; | |
| 193 if (inv_transform.GetInverse(&transform)) { | |
| 194 gfx::DecomposedTransform decomposed_transform; | |
| 195 gfx::DecomposeTransform(&decomposed_transform, transform); | |
| 196 | |
| 197 pose->orientation.value()[0] = decomposed_transform.quaternion[0]; | |
| 198 pose->orientation.value()[1] = decomposed_transform.quaternion[1]; | |
| 199 pose->orientation.value()[2] = decomposed_transform.quaternion[2]; | |
| 200 pose->orientation.value()[3] = decomposed_transform.quaternion[3]; | |
| 201 | |
| 202 pose->position.emplace(3); | |
| 203 pose->position.value()[0] = decomposed_transform.translate[0]; | |
| 204 pose->position.value()[1] = decomposed_transform.translate[1]; | |
| 205 pose->position.value()[2] = decomposed_transform.translate[2]; | |
| 206 } | |
| 207 | |
| 208 // Save the underlying GVR pose for use by rendering. It can't use a | |
| 209 // VRPosePtr since that's a different data type. | |
| 210 delegate_->SetGvrPoseForWebVr(head_mat, pose_index_); | |
| 211 | |
| 212 return pose; | |
| 213 } | |
| 214 | |
| 215 void GvrDevice::ResetPose() { | 153 void GvrDevice::ResetPose() { |
| 216 gvr::GvrApi* gvr_api = GetGvrApi(); | 154 gvr::GvrApi* gvr_api = GetGvrApi(); |
| 217 | 155 |
| 218 // Should never call RecenterTracking when using with Daydream viewers. On | 156 // Should never call RecenterTracking when using with Daydream viewers. On |
| 219 // those devices recentering should only be done via the controller. | 157 // those devices recentering should only be done via the controller. |
| 220 if (gvr_api && gvr_api->GetViewerType() == GVR_VIEWER_TYPE_CARDBOARD) | 158 if (gvr_api && gvr_api->GetViewerType() == GVR_VIEWER_TYPE_CARDBOARD) |
| 221 gvr_api->RecenterTracking(); | 159 gvr_api->RecenterTracking(); |
| 222 } | 160 } |
| 223 | 161 |
| 224 void GvrDevice::RequestPresent(const base::Callback<void(bool)>& callback) { | 162 void GvrDevice::RequestPresent(const base::Callback<void(bool)>& callback) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 } | 210 } |
| 273 | 211 |
| 274 gvr::GvrApi* GvrDevice::GetGvrApi() { | 212 gvr::GvrApi* GvrDevice::GetGvrApi() { |
| 275 if (!delegate_) | 213 if (!delegate_) |
| 276 return nullptr; | 214 return nullptr; |
| 277 | 215 |
| 278 return delegate_->gvr_api(); | 216 return delegate_->gvr_api(); |
| 279 } | 217 } |
| 280 | 218 |
| 281 } // namespace device | 219 } // namespace device |
| OLD | NEW |