Monado OpenXR Runtime
Loading...
Searching...
No Matches
g_hand_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 hand tracker interfaces.
6 * @ingroup aux_util
7 */
8
9#pragma once
10
12#include "g_catch_guard.hpp"
13#include "g_traits.hpp"
14
15#include <type_traits>
16
17
18namespace xrt::util {
19
20/*!
21 * CRTP glue wrapper for @ref xrt_hand_tracker. Relies on standard layout to
22 * recover the derived object from the C struct, and has some requirements and
23 * limitations because of that. See @ref cpp-glue-wrappers for the guide and
24 * conventions for these wrappers.
25 */
26template <class T> class HandTrackerBase
27{
28public: // Methods
29 HandTrackerBase() noexcept
30 {
31 static_assert(std::is_standard_layout_v<HandTrackerBase>,
32 "glue base must be standard layout for pointer recovery");
33 static_assert(is_non_virtual_base_v<HandTrackerBase, T>,
34 "glue base must be a non-virtual base of T for pointer recovery");
35
36 auto &xht = *getXHT();
37
38 xht.locate = locateWrap;
39 xht.set_output = setOutputWrap;
40 xht.destroy = destroyHandTrackerWrap;
41 }
42
43 ~HandTrackerBase() noexcept = default;
44
45 const T &
46 derived() const noexcept
47 {
48 return static_cast<const T &>(*this);
49 }
50
51 T &
52 derived() noexcept
53 {
54 return static_cast<T &>(*this);
55 }
56
57 static const T *
58 fromXHT(const xrt_hand_tracker *xht) noexcept
59 {
60 return &(reinterpret_cast<const HandTrackerBase *>(xht)->derived());
61 }
62
63 static T *
64 fromXHT(xrt_hand_tracker *xht) noexcept
65 {
66 return &(reinterpret_cast<HandTrackerBase *>(xht)->derived());
67 }
68
69 const xrt_hand_tracker *
70 getXHT() const noexcept
71 {
72 return &mHandTracker;
73 }
74
76 getXHT() noexcept
77 {
78 return &mHandTracker;
79 }
80
81
82private: // Members
83 /*!
84 * Wrapped @ref xrt_hand_tracker. Must be the first data member: a pointer to
85 * it is then interconvertible with a pointer to this standard-layout base,
86 * which lets the glue cast a C pointer back to the derived C++ class. See
87 * @ref cpp-glue-wrappers.
88 */
89 xrt_hand_tracker mHandTracker = {};
90
91
92private: // Functions
93#define GET(xht) (fromXHT(xht)->derived())
94
95 static xrt_result_t
96 locateWrap(struct xrt_hand_tracker *xht,
97 struct xrt_space_overseer *xso,
98 struct xrt_space *base_space,
99 const struct xrt_pose *base_offset,
100 int64_t at_timestamp_ns,
101 struct xrt_hand_tracker_location *out_location) noexcept
102 try {
103 return GET(xht).locate(xso, base_space, base_offset, at_timestamp_ns, out_location);
104 }
105 G_CATCH_GUARDS
106
107 static xrt_result_t
108 setOutputWrap(struct xrt_hand_tracker *xht,
109 enum xrt_output_name name,
110 const struct xrt_output_value *value) noexcept
111 try {
112 return GET(xht).setOutput(name, value);
113 }
114 G_CATCH_GUARDS
115
116 static void
117 destroyHandTrackerWrap(struct xrt_hand_tracker *xht) noexcept
118 try {
119 T::destroyHandTracker(xht);
120 }
121 G_CATCH_GUARDS_VOID
122
123#undef GET
124};
125
126} // namespace xrt::util
CRTP glue wrapper for xrt_hand_tracker.
Definition g_hand_tracker.hpp:27
Catch guards for glue classes.
Shared type traits for glue classes.
enum xrt_result xrt_result_t
Result type used across Monado.
xrt_output_name
Name of a output with a baked in type.
Definition xrt_defines.h:1612
Result of locating a hand tracker.
Definition xrt_hand_tracker.h:59
A hand tracker that owns device/source selection policy.
Definition xrt_hand_tracker.h:76
A union of all output types.
Definition xrt_defines.h:2386
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 hand tracker.