From 18fc47373599c23b3d455778bab07a5342db7606 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Sun, 10 Sep 2023 14:29:42 +0100 Subject: [PATCH] st/oxr: Add special xdev pose space --- src/xrt/state_trackers/oxr/oxr_conversions.h | 3 +- src/xrt/state_trackers/oxr/oxr_defines.h | 1 + src/xrt/state_trackers/oxr/oxr_objects.h | 20 ++++++++++- src/xrt/state_trackers/oxr/oxr_space.c | 37 +++++++++++++++++++- 4 files changed, 58 insertions(+), 3 deletions(-) diff --git a/src/xrt/state_trackers/oxr/oxr_conversions.h b/src/xrt/state_trackers/oxr/oxr_conversions.h index 992d9c9d7..8112590eb 100644 --- a/src/xrt/state_trackers/oxr/oxr_conversions.h +++ b/src/xrt/state_trackers/oxr/oxr_conversions.h @@ -1,4 +1,4 @@ -// Copyright 2018-2023, Collabora, Ltd. +// Copyright 2018-2024, Collabora, Ltd. // SPDX-License-Identifier: BSL-1.0 /*! * @file @@ -71,6 +71,7 @@ oxr_ref_space_to_xr(enum oxr_space_type space_type) case OXR_SPACE_TYPE_REFERENCE_LOCALIZATION_MAP_ML: return XR_REFERENCE_SPACE_TYPE_LOCALIZATION_MAP_ML; case OXR_SPACE_TYPE_ACTION: return XR_REFERENCE_SPACE_TYPE_MAX_ENUM; + case OXR_SPACE_TYPE_XDEV_POSE: return XR_REFERENCE_SPACE_TYPE_MAX_ENUM; } return XR_REFERENCE_SPACE_TYPE_MAX_ENUM; diff --git a/src/xrt/state_trackers/oxr/oxr_defines.h b/src/xrt/state_trackers/oxr/oxr_defines.h index 9a4a349ac..53c77a66a 100644 --- a/src/xrt/state_trackers/oxr/oxr_defines.h +++ b/src/xrt/state_trackers/oxr/oxr_defines.h @@ -108,6 +108,7 @@ enum oxr_space_type OXR_SPACE_TYPE_REFERENCE_LOCALIZATION_MAP_ML, OXR_SPACE_TYPE_ACTION, + OXR_SPACE_TYPE_XDEV_POSE, }; /*! diff --git a/src/xrt/state_trackers/oxr/oxr_objects.h b/src/xrt/state_trackers/oxr/oxr_objects.h index edef080e7..41a655f57 100644 --- a/src/xrt/state_trackers/oxr/oxr_objects.h +++ b/src/xrt/state_trackers/oxr/oxr_objects.h @@ -867,6 +867,18 @@ oxr_space_reference_create(struct oxr_logger *log, const XrReferenceSpaceCreateInfo *createInfo, struct oxr_space **out_space); +/*! + * Monado special space that always points to a specific @ref xrt_device and + * pose, useful when you want to bypass the action binding system for instance. + */ +XrResult +oxr_space_xdev_pose_create(struct oxr_logger *log, + struct oxr_session *sess, + struct xrt_device *xdev, + enum xrt_input_name name, + const struct xrt_pose *pose, + struct oxr_space **out_space); + XrResult oxr_space_locate( struct oxr_logger *log, struct oxr_space *spc, struct oxr_space *baseSpc, XrTime time, XrSpaceLocation *location); @@ -2197,7 +2209,8 @@ oxr_space_type_is_reference(enum oxr_space_type space_type) return true; case OXR_SPACE_TYPE_ACTION: - // Not a reference space. + case OXR_SPACE_TYPE_XDEV_POSE: + // These are not reference spaces. return false; } @@ -2241,6 +2254,11 @@ struct oxr_space struct xrt_device *xdev; enum xrt_input_name name; } action; + + struct + { + struct xrt_space *xs; + } xdev_pose; }; /*! diff --git a/src/xrt/state_trackers/oxr/oxr_space.c b/src/xrt/state_trackers/oxr/oxr_space.c index 4bb3a9dcc..595293261 100644 --- a/src/xrt/state_trackers/oxr/oxr_space.c +++ b/src/xrt/state_trackers/oxr/oxr_space.c @@ -1,4 +1,4 @@ -// Copyright 2019-2023, Collabora, Ltd. +// Copyright 2019-2024, Collabora, Ltd. // SPDX-License-Identifier: BSL-1.0 /*! * @file @@ -91,6 +91,7 @@ get_xrt_space(struct oxr_logger *log, struct oxr_space *spc, struct xrt_space ** struct xrt_space *xspace = NULL; switch (spc->space_type) { case OXR_SPACE_TYPE_ACTION: return get_xrt_space_action(log, spc, out_xspace); + case OXR_SPACE_TYPE_XDEV_POSE: xspace = spc->xdev_pose.xs; break; case OXR_SPACE_TYPE_REFERENCE_VIEW: xspace = spc->sess->sys->xso->semantic.view; break; case OXR_SPACE_TYPE_REFERENCE_LOCAL: xspace = spc->sess->sys->xso->semantic.local; break; case OXR_SPACE_TYPE_REFERENCE_LOCAL_FLOOR: xspace = spc->sess->sys->xso->semantic.local_floor; break; @@ -127,6 +128,7 @@ oxr_space_destroy(struct oxr_logger *log, struct oxr_handle_base *hb) xrt_space_overseer_ref_space_dec(spc->sess->sys->xso, xtype); } + xrt_space_reference(&spc->xdev_pose.xs, NULL); xrt_space_reference(&spc->action.xs, NULL); spc->action.xdev = NULL; spc->action.name = 0; @@ -211,6 +213,39 @@ oxr_space_reference_create(struct oxr_logger *log, return XR_SUCCESS; } +XrResult +oxr_space_xdev_pose_create(struct oxr_logger *log, + struct oxr_session *sess, + struct xrt_device *xdev, + enum xrt_input_name name, + const struct xrt_pose *pose, + struct oxr_space **out_space) +{ + if (!math_pose_validate(pose)) { + return oxr_error(log, XR_ERROR_POSE_INVALID, "(createInfo->offset)"); + } + + struct xrt_space *xspace = NULL; + xrt_result_t xret = xrt_space_overseer_create_pose_space( // + sess->sys->xso, // + xdev, // + name, // + &xspace); // + OXR_CHECK_XRET(log, sess, xret, xrt_space_overseer_create_pose_space); + + struct oxr_space *spc = NULL; + OXR_ALLOCATE_HANDLE_OR_RETURN(log, spc, OXR_XR_DEBUG_SPACE, oxr_space_destroy, &sess->handle); + spc->sess = sess; + spc->pose = *pose; + spc->space_type = OXR_SPACE_TYPE_XDEV_POSE; + xrt_space_reference(&spc->xdev_pose.xs, xspace); + xrt_space_reference(&xspace, NULL); + + *out_space = spc; + + return XR_SUCCESS; +} + /* *