Monado OpenXR Runtime
Loading...
Searching...
No Matches
g_body_tracker.hpp
Go to the documentation of this file.
1// Copyright 2026, NVIDIA CORPORATION.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Header for glue classes to wrap xrt body tracker interfaces.
6 * @ingroup aux_util
7 */
8
9#pragma once
10
12
13#include "g_catch_guard.hpp"
14#include "g_traits.hpp"
15
16#include <type_traits>
17
18
19namespace xrt::util {
20
21/*!
22 * CRTP glue wrapper for @ref xrt_body_tracker. Relies on standard layout to
23 * recover the derived object from the C struct, and has some requirements and
24 * limitations because of that. See @ref cpp-glue-wrappers for the guide and
25 * conventions for these wrappers.
26 */
27template <class T> class BodyTrackerBase
28{
29public: // Methods
30 BodyTrackerBase() noexcept
31 {
32 static_assert(std::is_standard_layout_v<BodyTrackerBase>,
33 "glue base must be standard layout for pointer recovery");
34 static_assert(is_non_virtual_base_v<BodyTrackerBase, T>,
35 "glue base must be a non-virtual base of T for pointer recovery");
36
37 auto &xbt = *getXBT();
38
39 xbt = {
40 .supported = {/* Filled in by derived class. */},
41 .locate = locateWrap,
42 .get_skeleton = getSkeletonWrap,
43 .reset_calibration_meta = resetCalibrationMetaWrap,
44 .set_calibration_override_meta = setCalibrationOverrideMetaWrap,
45 .set_fidelity_meta = setFidelityMetaWrap,
46 .destroy = destroyBodyTrackerWrap,
47 };
48 }
49
50 ~BodyTrackerBase() noexcept = default;
51
52 const T &
53 derived() const noexcept
54 {
55 return static_cast<const T &>(*this);
56 }
57
58 T &
59 derived() noexcept
60 {
61 return static_cast<T &>(*this);
62 }
63
64 static const T *
65 fromXBT(const xrt_body_tracker *xbt) noexcept
66 {
67 return &(reinterpret_cast<const BodyTrackerBase *>(xbt)->derived());
68 }
69
70 static T *
71 fromXBT(xrt_body_tracker *xbt) noexcept
72 {
73 return &(reinterpret_cast<BodyTrackerBase *>(xbt)->derived());
74 }
75
76 const xrt_body_tracker *
77 getXBT() const noexcept
78 {
79 return &mBodyTracker;
80 }
81
83 getXBT() noexcept
84 {
85 return &mBodyTracker;
86 }
87
88
89private: // Members
90 /*!
91 * Wrapped @ref xrt_body_tracker. Must be the first data member: a pointer to
92 * it is then interconvertible with a pointer to this standard-layout base,
93 * which lets the glue cast a C pointer back to the derived C++ class. See
94 * @ref cpp-glue-wrappers.
95 */
96 xrt_body_tracker mBodyTracker = {};
97
98
99private: // Functions
100#define GET(xbt) (fromXBT(xbt)->derived())
101
102 static xrt_result_t
103 locateWrap(struct xrt_body_tracker *xbt,
104 struct xrt_space_overseer *xso,
105 struct xrt_space *base_space,
106 const struct xrt_pose *base_offset,
107 int64_t at_timestamp_ns,
108 struct xrt_body_tracker_location *out_location) noexcept
109 try {
110 return GET(xbt).locate(xso, base_space, base_offset, at_timestamp_ns, out_location);
111 }
112 G_CATCH_GUARDS
113
114 static xrt_result_t
115 getSkeletonWrap(struct xrt_body_tracker *xbt, struct xrt_body_skeleton *out_skeleton) noexcept
116 try {
117 return GET(xbt).getSkeleton(out_skeleton);
118 }
119 G_CATCH_GUARDS
120
121 static xrt_result_t
122 resetCalibrationMetaWrap(struct xrt_body_tracker *xbt) noexcept
123 try {
124 return GET(xbt).resetCalibrationMeta();
125 }
126 G_CATCH_GUARDS
127
128 static xrt_result_t
129 setCalibrationOverrideMetaWrap(struct xrt_body_tracker *xbt, float body_height) noexcept
130 try {
131 return GET(xbt).setCalibrationOverrideMeta(body_height);
132 }
133 G_CATCH_GUARDS
134
135 static xrt_result_t
136 setFidelityMetaWrap(struct xrt_body_tracker *xbt, enum xrt_body_tracking_fidelity_meta fidelity) noexcept
137 try {
138 return GET(xbt).setFidelityMeta(fidelity);
139 }
140 G_CATCH_GUARDS
141
142 static void
143 destroyBodyTrackerWrap(struct xrt_body_tracker *xbt) noexcept
144 try {
145 T::destroyBodyTracker(xbt);
146 }
147 G_CATCH_GUARDS_VOID
148
149#undef GET
150};
151
152} // namespace xrt::util
CRTP glue wrapper for xrt_body_tracker.
Definition g_body_tracker.hpp:28
Catch guards for glue classes.
Shared type traits for glue classes.
enum xrt_result xrt_result_t
Result type used across Monado.
Definition xrt_defines.h:2198
Result of a locate call.
Definition xrt_body_tracker.h:75
A body tracker, owns the policy for selecting which device and body-tracking source back a single Ope...
Definition xrt_body_tracker.h:102
A pose composed of a position and orientation.
Definition xrt_defines.h:492
Object that oversees and manages spaces, one created for each XR system.
Definition xrt_space.h:97
A space very similar to a OpenXR XrSpace but not a full one-to-one mapping, but used to power XrSpace...
Definition xrt_space.h:32
Header defining xrt body tracker.