From a980392b9e96a35ff78aa0be786c8220fbed14b6 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Thu, 2 Mar 2023 14:27:01 +0000 Subject: [PATCH] st/oxr: Refactor out conversion helper to own header --- src/xrt/state_trackers/oxr/oxr_conversions.h | 52 ++++++++++++++++++++ src/xrt/state_trackers/oxr/oxr_objects.h | 4 +- src/xrt/state_trackers/oxr/oxr_session.c | 1 + src/xrt/state_trackers/oxr/oxr_space.c | 36 +------------- 4 files changed, 55 insertions(+), 38 deletions(-) create mode 100644 src/xrt/state_trackers/oxr/oxr_conversions.h diff --git a/src/xrt/state_trackers/oxr/oxr_conversions.h b/src/xrt/state_trackers/oxr/oxr_conversions.h new file mode 100644 index 000000000..8eb47084b --- /dev/null +++ b/src/xrt/state_trackers/oxr/oxr_conversions.h @@ -0,0 +1,52 @@ +// Copyright 2018-2023, Collabora, Ltd. +// SPDX-License-Identifier: BSL-1.0 +/*! + * @file + * @brief Smaller helper functions to convert between xrt and OpenXR things. + * @author Christoph Haag + * @author Jakob Bornecrantz + * @ingroup oxr_main + */ + +#pragma once + +#include "xrt/xrt_defines.h" +#include "xrt/xrt_vulkan_includes.h" +#include "xrt/xrt_openxr_includes.h" + + +static inline XrSpaceLocationFlags +xrt_to_xr_space_location_flags(enum xrt_space_relation_flags relation_flags) +{ + // clang-format off + bool valid_ori = (relation_flags & XRT_SPACE_RELATION_ORIENTATION_VALID_BIT) != 0; + bool tracked_ori = (relation_flags & XRT_SPACE_RELATION_ORIENTATION_TRACKED_BIT) != 0; + bool valid_pos = (relation_flags & XRT_SPACE_RELATION_POSITION_VALID_BIT) != 0; + bool tracked_pos = (relation_flags & XRT_SPACE_RELATION_POSITION_TRACKED_BIT) != 0; + + bool linear_vel = (relation_flags & XRT_SPACE_RELATION_LINEAR_VELOCITY_VALID_BIT) != 0; + bool angular_vel = (relation_flags & XRT_SPACE_RELATION_ANGULAR_VELOCITY_VALID_BIT) != 0; + // clang-format on + + XrSpaceLocationFlags location_flags = (XrSpaceLocationFlags)0; + if (valid_ori) { + location_flags |= XR_SPACE_LOCATION_ORIENTATION_VALID_BIT; + } + if (tracked_ori) { + location_flags |= XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT; + } + if (valid_pos) { + location_flags |= XR_SPACE_LOCATION_POSITION_VALID_BIT; + } + if (tracked_pos) { + location_flags |= XR_SPACE_LOCATION_POSITION_TRACKED_BIT; + } + if (linear_vel) { + location_flags |= XR_SPACE_VELOCITY_LINEAR_VALID_BIT; + } + if (angular_vel) { + location_flags |= XR_SPACE_VELOCITY_ANGULAR_VALID_BIT; + } + + return location_flags; +} diff --git a/src/xrt/state_trackers/oxr/oxr_objects.h b/src/xrt/state_trackers/oxr/oxr_objects.h index 8628c244d..d7000752f 100644 --- a/src/xrt/state_trackers/oxr/oxr_objects.h +++ b/src/xrt/state_trackers/oxr/oxr_objects.h @@ -828,12 +828,10 @@ oxr_space_locate( XRT_CHECK_RESULT bool is_local_space_set_up(struct oxr_session *sess); -XrSpaceLocationFlags -xrt_to_xr_space_location_flags(enum xrt_space_relation_flags relation_flags); - XRT_CHECK_RESULT bool global_to_local_space(struct oxr_logger *log, struct oxr_session *sess, XrTime time, struct xrt_space_relation *rel); + /* * * oxr_swapchain.c diff --git a/src/xrt/state_trackers/oxr/oxr_session.c b/src/xrt/state_trackers/oxr/oxr_session.c index a9356a3cc..9491d09de 100644 --- a/src/xrt/state_trackers/oxr/oxr_session.c +++ b/src/xrt/state_trackers/oxr/oxr_session.c @@ -39,6 +39,7 @@ #include "oxr_api_verify.h" #include "oxr_chain.h" #include "oxr_pretty_print.h" +#include "oxr_conversions.h" #include #include diff --git a/src/xrt/state_trackers/oxr/oxr_space.c b/src/xrt/state_trackers/oxr/oxr_space.c index ce7d0cf35..272bdbd18 100644 --- a/src/xrt/state_trackers/oxr/oxr_space.c +++ b/src/xrt/state_trackers/oxr/oxr_space.c @@ -23,6 +23,7 @@ #include "oxr_input_transform.h" #include "oxr_chain.h" #include "oxr_pretty_print.h" +#include "oxr_conversions.h" const struct xrt_pose origin = XRT_POSE_IDENTITY; @@ -350,41 +351,6 @@ print_pose(struct oxr_session *sess, const char *prefix, struct xrt_pose *pose) U_LOG_D("%s (%f, %f, %f) (%f, %f, %f, %f)", prefix, p->x, p->y, p->z, q->x, q->y, q->z, q->w); } -XrSpaceLocationFlags -xrt_to_xr_space_location_flags(enum xrt_space_relation_flags relation_flags) -{ - // clang-format off - bool valid_ori = (relation_flags & XRT_SPACE_RELATION_ORIENTATION_VALID_BIT) != 0; - bool tracked_ori = (relation_flags & XRT_SPACE_RELATION_ORIENTATION_TRACKED_BIT) != 0; - bool valid_pos = (relation_flags & XRT_SPACE_RELATION_POSITION_VALID_BIT) != 0; - bool tracked_pos = (relation_flags & XRT_SPACE_RELATION_POSITION_TRACKED_BIT) != 0; - - bool linear_vel = (relation_flags & XRT_SPACE_RELATION_LINEAR_VELOCITY_VALID_BIT) != 0; - bool angular_vel = (relation_flags & XRT_SPACE_RELATION_ANGULAR_VELOCITY_VALID_BIT) != 0; - // clang-format on - - XrSpaceLocationFlags location_flags = (XrSpaceLocationFlags)0; - if (valid_ori) { - location_flags |= XR_SPACE_LOCATION_ORIENTATION_VALID_BIT; - } - if (tracked_ori) { - location_flags |= XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT; - } - if (valid_pos) { - location_flags |= XR_SPACE_LOCATION_POSITION_VALID_BIT; - } - if (tracked_pos) { - location_flags |= XR_SPACE_LOCATION_POSITION_TRACKED_BIT; - } - if (linear_vel) { - location_flags |= XR_SPACE_VELOCITY_LINEAR_VALID_BIT; - } - if (angular_vel) { - location_flags |= XR_SPACE_VELOCITY_ANGULAR_VALID_BIT; - } - return location_flags; -} - XrResult oxr_space_locate( struct oxr_logger *log, struct oxr_space *spc, struct oxr_space *baseSpc, XrTime time, XrSpaceLocation *location)