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_delegate.h" | 5 #include "device/vr/android/gvr/gvr_delegate.h" |
6 | 6 |
7 #include "base/trace_event/trace_event.h" | 7 #include "base/trace_event/trace_event.h" |
8 #include "device/vr/vr_math.h" | 8 #include "device/vr/vr_math.h" |
9 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/
gvr.h" | 9 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/
gvr.h" |
10 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/
gvr_types.h" | 10 #include "third_party/gvr-android-sdk/src/libraries/headers/vr/gvr/capi/include/
gvr_types.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 pose->position.value()[0] = decomposed_transform.translate[0]; | 111 pose->position.value()[0] = decomposed_transform.translate[0]; |
112 pose->position.value()[1] = decomposed_transform.translate[1]; | 112 pose->position.value()[1] = decomposed_transform.translate[1]; |
113 pose->position.value()[2] = decomposed_transform.translate[2]; | 113 pose->position.value()[2] = decomposed_transform.translate[2]; |
114 } | 114 } |
115 | 115 |
116 return pose; | 116 return pose; |
117 } | 117 } |
118 | 118 |
119 /* static */ | 119 /* static */ |
120 void GvrDelegate::GetGvrPoseWithNeckModel(gvr::GvrApi* gvr_api, | 120 void GvrDelegate::GetGvrPoseWithNeckModel(gvr::GvrApi* gvr_api, |
121 vr::Mat4f* out) { | 121 vr::Mat4f* out, |
| 122 int64_t prediction_time) { |
122 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); | 123 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); |
123 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos; | 124 target_time.monotonic_system_time_nanos += prediction_time; |
124 | 125 |
125 gvr::Mat4f head_mat = gvr_api->ApplyNeckModel( | 126 gvr::Mat4f head_mat = gvr_api->ApplyNeckModel( |
126 gvr_api->GetHeadSpaceFromStartSpaceRotation(target_time), 1.0f); | 127 gvr_api->GetHeadSpaceFromStartSpaceRotation(target_time), 1.0f); |
127 | 128 |
128 GvrMatToMatf(head_mat, out); | 129 GvrMatToMatf(head_mat, out); |
129 } | 130 } |
130 | 131 |
131 /* static */ | 132 /* static */ |
| 133 void GvrDelegate::GetGvrPoseWithNeckModel(gvr::GvrApi* gvr_api, |
| 134 vr::Mat4f* out) { |
| 135 GetGvrPoseWithNeckModel(gvr_api, out, kPredictionTimeWithoutVsyncNanos); |
| 136 } |
| 137 |
| 138 /* static */ |
132 mojom::VRPosePtr GvrDelegate::GetVRPosePtrWithNeckModel( | 139 mojom::VRPosePtr GvrDelegate::GetVRPosePtrWithNeckModel( |
133 gvr::GvrApi* gvr_api, | 140 gvr::GvrApi* gvr_api, |
134 vr::Mat4f* head_mat_out) { | 141 vr::Mat4f* head_mat_out, |
| 142 int64_t prediction_time) { |
135 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); | 143 gvr::ClockTimePoint target_time = gvr::GvrApi::GetTimePointNow(); |
136 target_time.monotonic_system_time_nanos += kPredictionTimeWithoutVsyncNanos; | 144 target_time.monotonic_system_time_nanos += prediction_time; |
137 | 145 |
138 gvr::Mat4f gvr_head_mat = gvr_api->ApplyNeckModel( | 146 gvr::Mat4f gvr_head_mat = gvr_api->ApplyNeckModel( |
139 gvr_api->GetHeadSpaceFromStartSpaceRotation(target_time), 1.0f); | 147 gvr_api->GetHeadSpaceFromStartSpaceRotation(target_time), 1.0f); |
140 | 148 |
141 vr::Mat4f* head_mat_ptr = head_mat_out; | 149 vr::Mat4f* head_mat_ptr = head_mat_out; |
142 vr::Mat4f head_mat; | 150 vr::Mat4f head_mat; |
143 if (!head_mat_ptr) | 151 if (!head_mat_ptr) |
144 head_mat_ptr = &head_mat; | 152 head_mat_ptr = &head_mat; |
145 GvrMatToMatf(gvr_head_mat, head_mat_ptr); | 153 GvrMatToMatf(gvr_head_mat, head_mat_ptr); |
146 | 154 |
(...skipping 12 matching lines...) Expand all Loading... |
159 gfx::Vector3dF angular_velocity = | 167 gfx::Vector3dF angular_velocity = |
160 GetAngularVelocityFromPoses(*head_mat_ptr, head_mat_2, epsilon_seconds); | 168 GetAngularVelocityFromPoses(*head_mat_ptr, head_mat_2, epsilon_seconds); |
161 pose->angularVelocity.value()[0] = angular_velocity.x(); | 169 pose->angularVelocity.value()[0] = angular_velocity.x(); |
162 pose->angularVelocity.value()[1] = angular_velocity.y(); | 170 pose->angularVelocity.value()[1] = angular_velocity.y(); |
163 pose->angularVelocity.value()[2] = angular_velocity.z(); | 171 pose->angularVelocity.value()[2] = angular_velocity.z(); |
164 | 172 |
165 return pose; | 173 return pose; |
166 } | 174 } |
167 | 175 |
168 /* static */ | 176 /* static */ |
| 177 mojom::VRPosePtr GvrDelegate::GetVRPosePtrWithNeckModel( |
| 178 gvr::GvrApi* gvr_api, |
| 179 vr::Mat4f* head_mat_out) { |
| 180 return GetVRPosePtrWithNeckModel(gvr_api, head_mat_out, |
| 181 kPredictionTimeWithoutVsyncNanos); |
| 182 } |
| 183 |
| 184 /* static */ |
169 gfx::Size GvrDelegate::GetRecommendedWebVrSize(gvr::GvrApi* gvr_api) { | 185 gfx::Size GvrDelegate::GetRecommendedWebVrSize(gvr::GvrApi* gvr_api) { |
170 // Pick a reasonable default size for the WebVR transfer surface | 186 // Pick a reasonable default size for the WebVR transfer surface |
171 // based on a downscaled 1:1 render resolution. This size will also | 187 // based on a downscaled 1:1 render resolution. This size will also |
172 // be reported to the client via CreateVRDisplayInfo as the | 188 // be reported to the client via CreateVRDisplayInfo as the |
173 // client-recommended renderWidth/renderHeight and for the GVR | 189 // client-recommended renderWidth/renderHeight and for the GVR |
174 // framebuffer. If the client chooses a different size or resizes it | 190 // framebuffer. If the client chooses a different size or resizes it |
175 // while presenting, we'll resize the transfer surface and GVR | 191 // while presenting, we'll resize the transfer surface and GVR |
176 // framebuffer to match. | 192 // framebuffer to match. |
177 gvr::Sizei render_target_size = | 193 gvr::Sizei render_target_size = |
178 gvr_api->GetMaximumEffectiveRenderTargetSize(); | 194 gvr_api->GetMaximumEffectiveRenderTargetSize(); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 gvr::Mat4f eye_mat = gvr_api->GetEyeFromHeadMatrix(eye); | 253 gvr::Mat4f eye_mat = gvr_api->GetEyeFromHeadMatrix(eye); |
238 eye_params->offset[0] = -eye_mat.m[0][3]; | 254 eye_params->offset[0] = -eye_mat.m[0][3]; |
239 eye_params->offset[1] = -eye_mat.m[1][3]; | 255 eye_params->offset[1] = -eye_mat.m[1][3]; |
240 eye_params->offset[2] = -eye_mat.m[2][3]; | 256 eye_params->offset[2] = -eye_mat.m[2][3]; |
241 } | 257 } |
242 | 258 |
243 return device; | 259 return device; |
244 } | 260 } |
245 | 261 |
246 } // namespace device | 262 } // namespace device |
OLD | NEW |