The open source OpenXR runtime
0
fork

Configure Feed

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

st/oxr: Refactor pose and fov copies into helpers

authored by

Jakob Bornecrantz and committed by
Jakob Bornecrantz
85a2abae 1fb56568

+36 -33
+31
src/xrt/state_trackers/oxr/oxr_objects.h
··· 175 175 176 176 /* 177 177 * 178 + * Helpers 179 + * 180 + */ 181 + 182 + /*! 183 + * Safely copy a xrt_pose to a XrPosef. 184 + */ 185 + #define OXR_XRT_POSE_TO_XRPOSEF(FROM, TO) \ 186 + do { \ 187 + union { \ 188 + struct xrt_pose xrt; \ 189 + XrPosef oxr; \ 190 + } safe_copy = {FROM}; \ 191 + TO = safe_copy.oxr; \ 192 + } while (false) 193 + 194 + /*! 195 + * Safely copy a xrt_fov to a XrFovf. 196 + */ 197 + #define OXR_XRT_FOV_TO_XRFOVF(FROM, TO) \ 198 + do { \ 199 + union { \ 200 + struct xrt_fov xrt; \ 201 + XrFovf oxr; \ 202 + } safe_copy = {FROM}; \ 203 + TO = safe_copy.oxr; \ 204 + } while (false) 205 + 206 + 207 + /* 208 + * 178 209 * oxr_handle_base.c 179 210 * 180 211 */
+3 -19
src/xrt/state_trackers/oxr/oxr_session.c
··· 382 382 if (!oxr_space_pure_relation_in_space(log, viewLocateInfo->displayTime, &pure_head_relation, baseSpc, true, 383 383 &head_relation_in_base_space)) { 384 384 for (uint32_t i = 0; i < view_count; i++) { 385 - union { 386 - struct xrt_pose xrt; 387 - struct XrPosef oxr; 388 - } safe_copy_pose = {0}; 389 - safe_copy_pose.xrt = (struct xrt_pose)XRT_POSE_IDENTITY; 390 - views[i].pose = safe_copy_pose.oxr; 385 + OXR_XRT_POSE_TO_XRPOSEF(XRT_POSE_IDENTITY, views[i].pose); 391 386 } 392 387 return XR_SUCCESS; 393 388 } ··· 405 400 m_relation_chain_push_pose_if_not_identity(&xrc, &view_pose); 406 401 m_relation_chain_push_relation(&xrc, &head_relation_in_base_space); 407 402 m_relation_chain_resolve(&xrc, &result); 408 - union { 409 - struct xrt_pose xrt; 410 - struct XrPosef oxr; 411 - } safe_copy_pose = {0}; 412 - safe_copy_pose.xrt = result.pose; 413 - views[i].pose = safe_copy_pose.oxr; 403 + OXR_XRT_POSE_TO_XRPOSEF(result.pose, views[i].pose); 414 404 415 405 416 406 /* ··· 418 408 */ 419 409 420 410 const struct xrt_fov fov = fovs[i]; 421 - 422 - union { 423 - struct xrt_fov xrt; 424 - XrFovf oxr; 425 - } safe_copy_fov = {0}; 426 - safe_copy_fov.xrt = fov; 427 - views[i].fov = safe_copy_fov.oxr; 411 + OXR_XRT_FOV_TO_XRFOVF(fov, views[i].fov); 428 412 429 413 430 414 /*
+2 -14
src/xrt/state_trackers/oxr/oxr_space.c
··· 443 443 if (!has_pure_relation) { 444 444 location->locationFlags = 0; 445 445 446 - // Copy 447 - union { 448 - struct xrt_pose xrt; 449 - XrPosef oxr; 450 - } safe_copy = {XRT_POSE_IDENTITY}; 451 - location->pose = safe_copy.oxr; 446 + OXR_XRT_POSE_TO_XRPOSEF(XRT_POSE_IDENTITY, location->pose); 452 447 453 448 XrSpaceVelocity *vel = (XrSpaceVelocity *)location->next; 454 449 if (vel) { ··· 476 471 m_relation_chain_push_inverted_pose_if_not_identity(&xrc, &baseSpc->pose); 477 472 m_relation_chain_resolve(&xrc, &result); 478 473 479 - // Copy 480 - union { 481 - struct xrt_pose xrt; 482 - XrPosef oxr; 483 - } safe_copy = {0}; 484 - safe_copy.xrt = result.pose; 485 - 486 - location->pose = safe_copy.oxr; 474 + OXR_XRT_POSE_TO_XRPOSEF(result.pose, location->pose); 487 475 location->locationFlags = xrt_to_xr_space_location_flags(result.relation_flags); 488 476 489 477 XrSpaceVelocity *vel = (XrSpaceVelocity *)location->next;