The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

st/oxr: Rework composition of head relation for xrLocateViews

authored by

Christoph Haag and committed by
Jakob Bornecrantz
9cd3b47f 9b656cde

+137 -92
+13 -3
src/xrt/state_trackers/oxr/oxr_objects.h
··· 649 649 oxr_session_get_view_relation_at(struct oxr_logger *, 650 650 struct oxr_session *sess, 651 651 XrTime at_time, 652 - struct xrt_space_relation *out_relation); 652 + struct xrt_space_relation *out_relation, 653 + struct xrt_device **out_xdev); 653 654 654 655 XrResult 655 656 oxr_session_locate_views(struct oxr_logger *log, ··· 710 711 XrResult 711 712 oxr_space_ref_relation(struct oxr_logger *log, 712 713 struct oxr_session *sess, 713 - XrReferenceSpaceType space, 714 - XrReferenceSpaceType baseSpc, 714 + struct oxr_space *space, 715 + struct oxr_space *baseSpc, 715 716 XrTime time, 716 717 struct xrt_space_relation *out_relation); 718 + 719 + XrResult 720 + oxr_view_relation_ref_relation(struct oxr_logger *log, 721 + struct oxr_session *sess, 722 + struct xrt_space_relation *view_relation, 723 + struct xrt_device *view_xdev, 724 + struct oxr_space *baseSpc, 725 + XrTime time, 726 + struct xrt_space_relation *out_relation); 717 727 718 728 bool 719 729 initial_head_relation_valid(struct oxr_session *sess);
+23 -26
src/xrt/state_trackers/oxr/oxr_session.c
··· 262 262 } 263 263 } 264 264 265 + /** 266 + * Gets the view relation in global space. Even though @out_xdev is returned, the tracking origin offset is already 267 + * applied. 268 + */ 265 269 XrResult 266 270 oxr_session_get_view_relation_at(struct oxr_logger *log, 267 271 struct oxr_session *sess, 268 272 XrTime at_time, 269 - struct xrt_space_relation *out_relation) 273 + struct xrt_space_relation *out_relation, 274 + struct xrt_device **out_xdev) 270 275 { 271 276 // @todo This function needs to be massively expanded to support all 272 277 // use cases this drive. The main use of this function is to get ··· 284 289 struct xrt_relation_chain xrc = {0}; 285 290 oxr_xdev_get_relation_chain(log, sess->sys->inst, xdev, XRT_INPUT_GENERIC_HEAD_POSE, at_time, &xrc); 286 291 m_relation_chain_resolve(&xrc, out_relation); 292 + 293 + *out_xdev = xdev; 287 294 288 295 return oxr_session_success_result(sess); 289 296 } ··· 378 385 379 386 const uint64_t xdisplay_time = 380 387 time_state_ts_to_monotonic_ns(sess->sys->inst->timekeeping, viewLocateInfo->displayTime); 381 - //! @todo Head relation currently not used. 388 + 382 389 struct xrt_space_relation head_relation = XRT_SPACE_RELATION_ZERO; 383 390 struct xrt_fov fovs[2] = {0}; 384 391 struct xrt_pose poses[2] = {0}; ··· 392 399 fovs, // 393 400 poses); 394 401 402 + // head_relation is in xdev space. Bring it into global space by applying tracking origin offset. 403 + struct xrt_relation_chain xrc = {0}; 404 + m_relation_chain_push_relation(&xrc, &head_relation); 405 + m_relation_chain_push_pose_if_not_identity(&xrc, &xdev->tracking_origin->offset); 406 + m_relation_chain_resolve(&xrc, &head_relation); 395 407 396 - /* 397 - * Get the pure_relation if needed. 398 - */ 399 - 400 - // Get the viewLocateInfo->space to view space relation. 401 - struct xrt_space_relation pure_relation; 402 - 403 - /*! 404 - * @todo Introduce oxr_space_ref_relation_with_relation that takes 405 - * relation and transforms it into the correct relationship. 406 - */ 407 - // If we are going from stage space use the head pose. 408 - oxr_space_ref_relation( // 409 - log, // 410 - sess, // 411 - XR_REFERENCE_SPACE_TYPE_VIEW, // 412 - baseSpc->type, // 413 - viewLocateInfo->displayTime, // 414 - &pure_relation); // 408 + // transform head_relation into base_space 409 + struct xrt_space_relation base_spc_head_relation; 410 + oxr_view_relation_ref_relation(log, sess, &head_relation, xdev, baseSpc, viewLocateInfo->displayTime, 411 + &base_spc_head_relation); 415 412 416 413 // @todo the fov information that we get from xdev->hmd->views[i].fov is 417 414 // not properly filled out in oh_device.c, fix before wasting time ··· 432 429 struct xrt_space_relation result = {0}; 433 430 struct xrt_relation_chain xrc = {0}; 434 431 m_relation_chain_push_pose_if_not_identity(&xrc, &view_pose); 435 - m_relation_chain_push_relation(&xrc, &pure_relation); 436 - m_relation_chain_push_pose_if_not_identity(&xrc, &baseSpc->pose); 432 + m_relation_chain_push_relation(&xrc, &base_spc_head_relation); 433 + m_relation_chain_push_inverted_pose_if_not_identity(&xrc, &baseSpc->pose); 437 434 m_relation_chain_resolve(&xrc, &result); 438 435 union { 439 436 struct xrt_pose xrt; ··· 908 905 /*! @todo: testing, relating to view space unsupported 909 906 * in other parts of monado */ 910 907 911 - struct xrt_device *head_xdev = GET_XDEV_BY_ROLE(sess->sys, head); 908 + struct xrt_device *view_xdev = NULL; 912 909 913 910 struct xrt_space_relation view_relation; 914 - oxr_session_get_view_relation_at(log, sess, at_time, &view_relation); 911 + oxr_session_get_view_relation_at(log, sess, at_time, &view_relation, &view_xdev); 915 912 916 913 m_relation_chain_push_relation(&chain, &value.hand_pose); 917 914 m_relation_chain_push_pose_if_not_identity(&chain, tracking_origin_offset); 918 915 919 916 m_relation_chain_push_inverted_relation(&chain, &view_relation); 920 917 m_relation_chain_push_inverted_pose_if_not_identity(&chain, 921 - &head_xdev->tracking_origin->offset); 918 + &view_xdev->tracking_origin->offset); 922 919 923 920 } else if (!baseSpc->is_reference) { 924 921 // action space
+101 -63
src/xrt/state_trackers/oxr/oxr_space.c
··· 166 166 } 167 167 168 168 /*! 169 + * Transform @view_relation given in global space into baseSpc without the app given offset pose for baseSpc 170 + * applied. 171 + */ 172 + XrResult 173 + oxr_view_relation_ref_relation(struct oxr_logger *log, 174 + struct oxr_session *sess, 175 + struct xrt_space_relation *view_relation, 176 + struct xrt_device *view_xdev, 177 + struct oxr_space *baseSpc, 178 + XrTime time, 179 + struct xrt_space_relation *out_relation) 180 + { 181 + *out_relation = *view_relation; 182 + 183 + //! @todo: find a central place to set up local space 184 + if (!ensure_initial_head_relation(log, sess, out_relation)) { 185 + out_relation->relation_flags = XRT_SPACE_RELATION_BITMASK_NONE; 186 + return XR_SUCCESS; 187 + } 188 + 189 + if (baseSpc->type == XR_REFERENCE_SPACE_TYPE_STAGE) { 190 + // device poses are already in stage = "global" space 191 + } else if (baseSpc->type == XR_REFERENCE_SPACE_TYPE_LOCAL) { 192 + global_to_local_space(sess, out_relation); 193 + } else if (baseSpc->type == XR_REFERENCE_SPACE_TYPE_VIEW) { 194 + // view relation in view space should be identity 195 + m_space_relation_ident(out_relation); 196 + } else { 197 + OXR_WARN_ONCE(log, "unsupported base reference space in space_ref_relation"); 198 + out_relation->relation_flags = XRT_SPACE_RELATION_BITMASK_NONE; 199 + return XR_SUCCESS; 200 + } 201 + 202 + return XR_SUCCESS; 203 + } 204 + 205 + static XrResult 206 + oxr_view_ref_relation(struct oxr_logger *log, 207 + struct oxr_session *sess, 208 + struct oxr_space *baseSpc, 209 + XrTime time, 210 + struct xrt_space_relation *out_relation) 211 + { 212 + struct xrt_device *view_xdev = NULL; 213 + struct xrt_space_relation view_relation; 214 + oxr_session_get_view_relation_at(log, sess, time, &view_relation, &view_xdev); 215 + return oxr_view_relation_ref_relation(log, sess, &view_relation, view_xdev, baseSpc, time, out_relation); 216 + } 217 + 218 + static XrResult 219 + oxr_stage_ref_relation(struct oxr_logger *log, 220 + struct oxr_session *sess, 221 + struct oxr_space *baseSpc, 222 + XrTime time, 223 + struct xrt_space_relation *out_relation) 224 + { 225 + if (baseSpc->type == XR_REFERENCE_SPACE_TYPE_LOCAL) { 226 + math_pose_invert(&sess->initial_head_relation.pose, &out_relation->pose); 227 + } else { 228 + OXR_WARN_ONCE(log, "unsupported base space in space_ref_relation"); 229 + out_relation->relation_flags = XRT_SPACE_RELATION_BITMASK_NONE; 230 + return XR_SUCCESS; 231 + } 232 + return XR_SUCCESS; 233 + } 234 + 235 + static XrResult 236 + oxr_locale_ref_relation(struct oxr_logger *log, 237 + struct oxr_session *sess, 238 + struct oxr_space *baseSpc, 239 + XrTime time, 240 + struct xrt_space_relation *out_relation) 241 + { 242 + if (baseSpc->type == XR_REFERENCE_SPACE_TYPE_STAGE) { 243 + out_relation->pose = sess->initial_head_relation.pose; 244 + } else { 245 + OXR_WARN_ONCE(log, "unsupported base space in space_ref_relation"); 246 + out_relation->relation_flags = XRT_SPACE_RELATION_BITMASK_NONE; 247 + return XR_SUCCESS; 248 + } 249 + return XR_SUCCESS; 250 + } 251 + 252 + /*! 169 253 * This returns only the relation between two spaces without any of the app 170 254 * given relations applied, assumes that both spaces are reference spaces. 171 255 */ 172 256 XrResult 173 257 oxr_space_ref_relation(struct oxr_logger *log, 174 258 struct oxr_session *sess, 175 - XrReferenceSpaceType space, 176 - XrReferenceSpaceType baseSpc, 259 + struct oxr_space *space, 260 + struct oxr_space *baseSpc, 177 261 XrTime time, 178 262 struct xrt_space_relation *out_relation) 179 263 { 180 264 m_space_relation_ident(out_relation); 181 265 182 - 183 - if (space == baseSpc) { 184 - // m_space_relation_ident() sets to identity. 185 - } else if (space == XR_REFERENCE_SPACE_TYPE_VIEW) { 186 - oxr_session_get_view_relation_at(log, sess, time, out_relation); 187 - 188 - if (!ensure_initial_head_relation(log, sess, out_relation)) { 189 - out_relation->relation_flags = XRT_SPACE_RELATION_BITMASK_NONE; 190 - return XR_SUCCESS; 191 - } 192 - 193 - if (baseSpc == XR_REFERENCE_SPACE_TYPE_STAGE) { 194 - // device poses are already in stage = "global" space 195 - } else if (baseSpc == XR_REFERENCE_SPACE_TYPE_LOCAL) { 196 - global_to_local_space(sess, out_relation); 197 - } else if (baseSpc == XR_REFERENCE_SPACE_TYPE_VIEW) { 198 - 199 - } else { 200 - OXR_WARN_ONCE(log, "unsupported base space in space_ref_relation"); 201 - out_relation->relation_flags = XRT_SPACE_RELATION_BITMASK_NONE; 202 - return XR_SUCCESS; 203 - } 204 - } else if (baseSpc == XR_REFERENCE_SPACE_TYPE_VIEW) { 205 - oxr_session_get_view_relation_at(log, sess, time, out_relation); 206 - 207 - if (!ensure_initial_head_relation(log, sess, out_relation)) { 208 - out_relation->relation_flags = XRT_SPACE_RELATION_BITMASK_NONE; 209 - return XR_SUCCESS; 210 - } 211 - if (space == XR_REFERENCE_SPACE_TYPE_STAGE) { 212 - // device poses are already in stage = "global" space 213 - } else if (space == XR_REFERENCE_SPACE_TYPE_LOCAL) { 214 - global_to_local_space(sess, out_relation); 215 - } else if (space == XR_REFERENCE_SPACE_TYPE_VIEW) { 216 - 217 - } else { 218 - OXR_WARN_ONCE(log, "unsupported base space in space_ref_relation"); 219 - out_relation->relation_flags = XRT_SPACE_RELATION_BITMASK_NONE; 220 - return XR_SUCCESS; 221 - } 266 + if (space->type == baseSpc->type) { 267 + // m_space_relation_ident() already set this to identity. 268 + } else if (space->type == XR_REFERENCE_SPACE_TYPE_VIEW) { 269 + oxr_view_ref_relation(log, sess, baseSpc, time, out_relation); 270 + } else if (baseSpc->type == XR_REFERENCE_SPACE_TYPE_VIEW) { 271 + oxr_view_ref_relation(log, sess, space, time, out_relation); 272 + //! @todo invert complete relation 222 273 math_pose_invert(&out_relation->pose, &out_relation->pose); 223 - 224 - } else if (space == XR_REFERENCE_SPACE_TYPE_STAGE) { 225 - if (baseSpc == XR_REFERENCE_SPACE_TYPE_LOCAL) { 226 - math_pose_invert(&sess->initial_head_relation.pose, &out_relation->pose); 227 - } else { 228 - OXR_WARN_ONCE(log, "unsupported base space in space_ref_relation"); 229 - out_relation->relation_flags = XRT_SPACE_RELATION_BITMASK_NONE; 230 - return XR_SUCCESS; 231 - } 232 - } else if (space == XR_REFERENCE_SPACE_TYPE_LOCAL) { 233 - if (baseSpc == XR_REFERENCE_SPACE_TYPE_STAGE) { 234 - out_relation->pose = sess->initial_head_relation.pose; 235 - } else { 236 - OXR_WARN_ONCE(log, "unsupported base space in space_ref_relation"); 237 - out_relation->relation_flags = XRT_SPACE_RELATION_BITMASK_NONE; 238 - return XR_SUCCESS; 239 - } 274 + } else if (space->type == XR_REFERENCE_SPACE_TYPE_STAGE) { 275 + oxr_stage_ref_relation(log, sess, baseSpc, time, out_relation); 276 + } else if (space->type == XR_REFERENCE_SPACE_TYPE_LOCAL) { 277 + oxr_locale_ref_relation(log, sess, baseSpc, time, out_relation); 240 278 } else { 241 279 out_relation->relation_flags = XRT_SPACE_RELATION_BITMASK_NONE; 242 280 return XR_SUCCESS; ··· 257 295 } 258 296 259 297 /*! 260 - * This returns only the relation between two spaces without any of the app 261 - * given relations applied, assumes that only one is a action space. 298 + * This returns only the relation between two space without the app given offset pose for baseSpc applied, 299 + * assumes that only one is a action space. 262 300 */ 263 301 static XrResult 264 302 oxr_space_action_relation(struct oxr_logger *log, ··· 327 365 328 366 /*! 329 367 * This returns only the relation between two directly-associated spaces without 330 - * any of the app given relations applied. 368 + * the app given offset pose for baseSpc applied. 331 369 */ 332 370 static XrResult 333 371 get_pure_space_relation(struct oxr_logger *log, ··· 339 377 struct oxr_session *sess = spc->sess; 340 378 341 379 if (spc->is_reference && baseSpc->is_reference) { 342 - return oxr_space_ref_relation(log, sess, spc->type, baseSpc->type, time, out_relation); 380 + return oxr_space_ref_relation(log, sess, spc, baseSpc, time, out_relation); 343 381 } 344 382 /// @todo Deal with action to action by keeping a true_space that we can always go via. (poor mans space graph) 345 383 if (!spc->is_reference && !baseSpc->is_reference) {