Monado OpenXR Runtime
qwerty_device.h
Go to the documentation of this file.
1// Copyright 2021, Mateo de Mayo.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Internal header for qwerty_device and its friends.
6 * @author Mateo de Mayo <mateodemayo@gmail.com>
7 * @ingroup drv_qwerty
8 */
9#pragma once
10
11#include "util/u_logging.h"
12#include "xrt/xrt_device.h"
13
14/*!
15 * @addtogroup drv_qwerty
16 * @{
17 */
18
19#define QWERTY_HMD_STR "Qwerty HMD"
20#define QWERTY_HMD_TRACKER_STR QWERTY_HMD_STR " Tracker"
21#define QWERTY_LEFT_STR "Qwerty Left Controller"
22#define QWERTY_LEFT_TRACKER_STR QWERTY_LEFT_STR " Tracker"
23#define QWERTY_RIGHT_STR "Qwerty Right Controller"
24#define QWERTY_RIGHT_TRACKER_STR QWERTY_RIGHT_STR " Tracker"
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30/*!
31 * @brief Container of qwerty devices and driver properties.
32 * @see qwerty_hmd, qwerty_controller
33 */
35{
36 struct qwerty_hmd *hmd; //!< Can be NULL
37 struct qwerty_controller *lctrl; //!< Cannot be NULL
38 struct qwerty_controller *rctrl; //!< Cannot be NULL
39 enum u_logging_level log_level;
40 bool process_keys; //!< If false disable keyboard and mouse input
41 bool hmd_focused; //!< For gui var tracking only, true if hmd is the focused device
42 bool lctrl_focused; //!< Same as `hmd_focused` but for the left controller
43 bool rctrl_focused; //!< Same as `hmd_focused` but for the right controller
44};
45
46/*!
47 * Fake device that modifies its tracked pose through its methods.
48 * @implements xrt_device
49 */
51{
52 struct xrt_device base;
53 struct xrt_pose pose; //!< Internal pose state
54 struct qwerty_system *sys; //!< Reference to the system this device is in.
55
56 float movement_speed; //!< In meters per frame
57 bool left_pressed;
58 bool right_pressed;
59 bool forward_pressed;
60 bool backward_pressed;
61 bool up_pressed;
62 bool down_pressed;
63
64 float look_speed; //!< In radians per frame
65 bool look_left_pressed;
66 bool look_right_pressed;
67 bool look_up_pressed;
68 bool look_down_pressed;
69
70 bool sprint_pressed; //!< Movement speed boost
71 float yaw_delta; //!< How much extra yaw to add for the next pose. Then reset to 0.
72 float pitch_delta; //!< Similar to `yaw_delta`
73};
74
75/*!
76 * @implements qwerty_device
77 * @see qwerty_system
78 */
80{
81 struct qwerty_device base;
82};
83
84/*!
85 * Supports input actions and can be attached to the HMD pose.
86 * @implements qwerty_device
87 * @see qwerty_system
88 */
90{
91 struct qwerty_device base;
92
93 bool select_clicked;
94 int64_t select_timestamp;
95 bool menu_clicked;
96 int64_t menu_timestamp;
97
98 /*!
99 * Only used when a qwerty_hmd exists in the system.
100 * Do not modify directly; use qwerty_follow_hmd().
101 * If true, `pose` is relative to the qwerty_hmd.
102 */
103 bool follow_hmd; // @todo: Make this work with non-qwerty HMDs.
104};
105
106/*!
107 * @public @memberof qwerty_system
108 */
109struct qwerty_system *
110qwerty_system_create(struct qwerty_hmd *qhmd,
111 struct qwerty_controller *qleft,
112 struct qwerty_controller *qright,
113 enum u_logging_level log_level);
114
115/*
116 *
117 * qwerty_device methods
118 *
119 */
120
121/*!
122 * @brief Cast to qwerty_device. Ensures returning a valid device or crashing.
123 * @public @memberof qwerty_device
124 */
125struct qwerty_device *
126qwerty_device(struct xrt_device *xd);
127
128//! @public @memberof qwerty_device
129void
130qwerty_press_left(struct qwerty_device *qd);
131//! @public @memberof qwerty_device
132void
133qwerty_release_left(struct qwerty_device *qd);
134//! @public @memberof qwerty_device
135void
136qwerty_press_right(struct qwerty_device *qd);
137//! @public @memberof qwerty_device
138void
139qwerty_release_right(struct qwerty_device *qd);
140//! @public @memberof qwerty_device
141void
142qwerty_press_forward(struct qwerty_device *qd);
143//! @public @memberof qwerty_device
144void
145qwerty_release_forward(struct qwerty_device *qd);
146//! @public @memberof qwerty_device
147void
148qwerty_press_backward(struct qwerty_device *qd);
149//! @public @memberof qwerty_device
150void
151qwerty_release_backward(struct qwerty_device *qd);
152//! @public @memberof qwerty_device
153void
154qwerty_press_up(struct qwerty_device *qd);
155//! @public @memberof qwerty_device
156void
157qwerty_release_up(struct qwerty_device *qd);
158//! @public @memberof qwerty_device
159void
160qwerty_press_down(struct qwerty_device *qd);
161//! @public @memberof qwerty_device
162void
163qwerty_release_down(struct qwerty_device *qd);
164
165//! @public @memberof qwerty_device
166void
167qwerty_press_look_left(struct qwerty_device *qd);
168//! @public @memberof qwerty_device
169void
170qwerty_release_look_left(struct qwerty_device *qd);
171//! @public @memberof qwerty_device
172void
173qwerty_press_look_right(struct qwerty_device *qd);
174//! @public @memberof qwerty_device
175void
176qwerty_release_look_right(struct qwerty_device *qd);
177//! @public @memberof qwerty_device
178void
179qwerty_press_look_up(struct qwerty_device *qd);
180//! @public @memberof qwerty_device
181void
182qwerty_release_look_up(struct qwerty_device *qd);
183//! @public @memberof qwerty_device
184void
185qwerty_press_look_down(struct qwerty_device *qd);
186//! @public @memberof qwerty_device
187void
188qwerty_release_look_down(struct qwerty_device *qd);
189
190/*!
191 * Momentarily increase `movement_speed` until `qwerty_release_sprint()`
192 * @public @memberof qwerty_device
193 */
194void
196
197/*!
198 * Stop doing what @ref qwerty_press_sprint started.
199 * @public @memberof qwerty_device
200 */
201void
203
204/*!
205 * Add yaw and pitch movement for the next frame
206 * @public @memberof qwerty_device
207 */
208void
209qwerty_add_look_delta(struct qwerty_device *qd, float yaw, float pitch);
210
211/*!
212 * Change movement speed in exponential steps (usually integers, but any float allowed)
213 * @public @memberof qwerty_device
214 */
215void
216qwerty_change_movement_speed(struct qwerty_device *qd, float steps);
217
218/*!
219 * Release all movement input
220 * @public @memberof qwerty_device
221 */
222void
224
225/*!
226 * Create qwerty_hmd. Crash on failure.
227 * @public @memberof qwerty_hmd
228 */
229struct qwerty_hmd *
231
232/*!
233 * Cast to qwerty_hmd. Ensures returning a valid HMD or crashing.
234 * @public @memberof qwerty_hmd
235 */
236struct qwerty_hmd *
237qwerty_hmd(struct xrt_device *xd);
238
239/*
240 *
241 * qwerty_controller methods
242 *
243 */
244/*!
245 * Create qwerty_controller. Crash on failure.
246 * @public @memberof qwerty_controller
247 */
248struct qwerty_controller *
249qwerty_controller_create(bool is_left, struct qwerty_hmd *qhmd);
250
251/*!
252 * Cast to qwerty_controller. Ensures returning a valid controller or crashing.
253 * @public @memberof qwerty_controller
254 */
255struct qwerty_controller *
256qwerty_controller(struct xrt_device *xd);
257
258/*!
259 * Simulate pressing input/select/click
260 * @public @memberof qwerty_controller
261 */
262void
264
265/*!
266 * Simulate releasing input/select/click
267 * @public @memberof qwerty_controller
268 */
269void
271
272/*!
273 * Simulate pressing input/menu/click
274 * @public @memberof qwerty_controller
275 */
276void
278
279/*!
280 * Simulate releasing input/menu/click
281 * @public @memberof qwerty_controller
282 */
283void
285
286/*!
287 * Attach/detach the pose of `qc` to its HMD. Only works when a qwerty_hmd is present.
288 * @public @memberof qwerty_controller
289 */
290void
291qwerty_follow_hmd(struct qwerty_controller *qc, bool follow);
292
293/*!
294 * Reset controller to initial pose and makes it follow the HMD
295 * @public @memberof qwerty_controller
296 */
297void
299
300
301/*!
302 * @}
303 */
304
305#ifdef __cplusplus
306}
307#endif
u_logging_level
Logging level enum.
Definition: u_logging.h:40
struct qwerty_controller * qwerty_controller_create(bool is_left, struct qwerty_hmd *qhmd)
Create qwerty_controller.
Definition: qwerty_device.c:272
void qwerty_release_select(struct qwerty_controller *qc)
Simulate releasing input/select/click.
Definition: qwerty_device.c:502
void qwerty_follow_hmd(struct qwerty_controller *qc, bool follow)
Attach/detach the pose of qc to its HMD.
Definition: qwerty_device.c:523
void qwerty_press_menu(struct qwerty_controller *qc)
Simulate pressing input/menu/click.
Definition: qwerty_device.c:509
struct qwerty_hmd * qwerty_hmd(struct xrt_device *xd)
Cast to qwerty_hmd.
Definition: qwerty_device.c:84
void qwerty_press_sprint(struct qwerty_device *qd)
Momentarily increase movement_speed until qwerty_release_sprint()
Definition: qwerty_device.c:451
void qwerty_add_look_delta(struct qwerty_device *qd, float yaw, float pitch)
Add yaw and pitch movement for the next frame.
Definition: qwerty_device.c:462
void qwerty_change_movement_speed(struct qwerty_device *qd, float steps)
Change movement speed in exponential steps (usually integers, but any float allowed)
Definition: qwerty_device.c:469
void qwerty_release_sprint(struct qwerty_device *qd)
Stop doing what qwerty_press_sprint started.
Definition: qwerty_device.c:456
struct qwerty_controller * qwerty_controller(struct xrt_device *xd)
Cast to qwerty_controller.
Definition: qwerty_device.c:96
struct qwerty_hmd * qwerty_hmd_create(void)
Create qwerty_hmd.
Definition: qwerty_device.c:218
void qwerty_press_select(struct qwerty_controller *qc)
Simulate pressing input/select/click.
Definition: qwerty_device.c:495
void qwerty_release_all(struct qwerty_device *qd)
Release all movement input.
Definition: qwerty_device.c:475
void qwerty_reset_controller_pose(struct qwerty_controller *qc)
Reset controller to initial pose and makes it follow the HMD.
Definition: qwerty_device.c:549
struct qwerty_device * qwerty_device(struct xrt_device *xd)
Cast to qwerty_device.
Definition: qwerty_device.c:72
void qwerty_release_menu(struct qwerty_controller *qc)
Simulate releasing input/menu/click.
Definition: qwerty_device.c:516
Supports input actions and can be attached to the HMD pose.
Definition: qwerty_device.h:90
bool follow_hmd
Only used when a qwerty_hmd exists in the system.
Definition: qwerty_device.h:103
Fake device that modifies its tracked pose through its methods.
Definition: qwerty_device.h:51
float pitch_delta
Similar to yaw_delta
Definition: qwerty_device.h:72
struct xrt_pose pose
Internal pose state.
Definition: qwerty_device.h:53
struct qwerty_system * sys
Reference to the system this device is in.
Definition: qwerty_device.h:54
bool sprint_pressed
Movement speed boost.
Definition: qwerty_device.h:70
float look_speed
In radians per frame.
Definition: qwerty_device.h:64
float yaw_delta
How much extra yaw to add for the next pose.
Definition: qwerty_device.h:71
float movement_speed
In meters per frame.
Definition: qwerty_device.h:56
Definition: qwerty_device.h:80
Container of qwerty devices and driver properties.
Definition: qwerty_device.h:35
struct qwerty_hmd * hmd
Can be NULL.
Definition: qwerty_device.h:36
bool process_keys
If false disable keyboard and mouse input.
Definition: qwerty_device.h:40
bool hmd_focused
For gui var tracking only, true if hmd is the focused device.
Definition: qwerty_device.h:41
struct qwerty_controller * lctrl
Cannot be NULL.
Definition: qwerty_device.h:37
bool rctrl_focused
Same as hmd_focused but for the right controller.
Definition: qwerty_device.h:43
bool lctrl_focused
Same as hmd_focused but for the left controller.
Definition: qwerty_device.h:42
struct qwerty_controller * rctrl
Cannot be NULL.
Definition: qwerty_device.h:38
A single HMD or input device.
Definition: xrt_device.h:230
A pose composed of a position and orientation.
Definition: xrt_defines.h:465
Basic logging functionality.
Header defining an xrt display or controller device.