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
14
15namespace xrt::util {
16
17/*!
18 * Helper wrapper for @ref xrt_hand_tracker.
19 */
20template <class T> class HandTrackerBase
21{
22public: // Methods
23 HandTrackerBase() noexcept
24 {
25 auto &xht = *getXHT();
26
27 xht.locate = locateWrap;
28 xht.set_output = setOutputWrap;
29 xht.destroy = destroyHandTrackerWrap;
30 }
31
32 ~HandTrackerBase() noexcept = default;
33
34 const T &
35 derived() const noexcept
36 {
37 return static_cast<const T &>(*this);
38 }
39
40 T &
41 derived() noexcept
42 {
43 return static_cast<T &>(*this);
44 }
45
46 static const T *
47 fromXHT(const xrt_hand_tracker *xht) noexcept
48 {
49 return &(reinterpret_cast<const HandTrackerBase *>(xht)->derived());
50 }
51
52 static T *
53 fromXHT(xrt_hand_tracker *xht) noexcept
54 {
55 return &(reinterpret_cast<HandTrackerBase *>(xht)->derived());
56 }
57
58 const xrt_hand_tracker *
59 getXHT() const noexcept
60 {
61 return &mHandTracker;
62 }
63
65 getXHT() noexcept
66 {
67 return &mHandTracker;
68 }
69
70
71private: // Members
72 xrt_hand_tracker mHandTracker = {};
73
74
75private: // Functions
76#define GET(xht) (fromXHT(xht)->derived())
77
78 static xrt_result_t
79 locateWrap(struct xrt_hand_tracker *xht,
80 struct xrt_space_overseer *xso,
81 struct xrt_space *base_space,
82 const struct xrt_pose *base_offset,
83 int64_t at_timestamp_ns,
84 struct xrt_hand_tracker_location *out_location) noexcept
85 try {
86 return GET(xht).locate(xso, base_space, base_offset, at_timestamp_ns, out_location);
87 }
88 G_CATCH_GUARDS
89
90 static xrt_result_t
91 setOutputWrap(struct xrt_hand_tracker *xht,
92 enum xrt_output_name name,
93 const struct xrt_output_value *value) noexcept
94 try {
95 return GET(xht).setOutput(name, value);
96 }
97 G_CATCH_GUARDS
98
99 static void
100 destroyHandTrackerWrap(struct xrt_hand_tracker *xht) noexcept
101 try {
102 GET(xht).destroyHandTracker();
103 }
104 G_CATCH_GUARDS_VOID
105
106#undef GET
107};
108
109} // namespace xrt::util
Helper wrapper for xrt_hand_tracker.
Definition g_hand_tracker.hpp:21
Catch guards 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.