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 trigger_clicked;
94 int64_t trigger_timestamp;
95 bool menu_clicked;
96 int64_t menu_timestamp;
97 bool squeeze_clicked;
98 int64_t squeeze_timestamp;
99 bool system_clicked;
100 int64_t system_timestamp;
101
102 bool thumbstick_left_pressed;
103 bool thumbstick_right_pressed;
104 bool thumbstick_up_pressed;
105 bool thumbstick_down_pressed;
106 int64_t thumbstick_timestamp;
107 bool thumbstick_clicked;
108 int64_t thumbstick_click_timestamp;
109
110 bool trackpad_left_pressed;
111 bool trackpad_right_pressed;
112 bool trackpad_up_pressed;
113 bool trackpad_down_pressed;
114 int64_t trackpad_timestamp;
115 bool trackpad_clicked;
116 int64_t trackpad_click_timestamp;
117
118 /*!
119 * Only used when a qwerty_hmd exists in the system.
120 * Do not modify directly; use qwerty_follow_hmd().
121 * If true, `pose` is relative to the qwerty_hmd.
122 */
123 bool follow_hmd; // @todo: Make this work with non-qwerty HMDs.
124};
125
126/*!
127 * @public @memberof qwerty_system
128 */
129struct qwerty_system *
130qwerty_system_create(struct qwerty_hmd *qhmd,
131 struct qwerty_controller *qleft,
132 struct qwerty_controller *qright,
133 enum u_logging_level log_level);
134
135/*
136 *
137 * qwerty_device methods
138 *
139 */
140
141/*!
142 * @brief Cast to qwerty_device. Ensures returning a valid device or crashing.
143 * @public @memberof qwerty_device
144 */
145struct qwerty_device *
146qwerty_device(struct xrt_device *xd);
147
148//! @public @memberof qwerty_device
149void
150qwerty_press_left(struct qwerty_device *qd);
151//! @public @memberof qwerty_device
152void
153qwerty_release_left(struct qwerty_device *qd);
154//! @public @memberof qwerty_device
155void
156qwerty_press_right(struct qwerty_device *qd);
157//! @public @memberof qwerty_device
158void
159qwerty_release_right(struct qwerty_device *qd);
160//! @public @memberof qwerty_device
161void
162qwerty_press_forward(struct qwerty_device *qd);
163//! @public @memberof qwerty_device
164void
165qwerty_release_forward(struct qwerty_device *qd);
166//! @public @memberof qwerty_device
167void
168qwerty_press_backward(struct qwerty_device *qd);
169//! @public @memberof qwerty_device
170void
171qwerty_release_backward(struct qwerty_device *qd);
172//! @public @memberof qwerty_device
173void
174qwerty_press_up(struct qwerty_device *qd);
175//! @public @memberof qwerty_device
176void
177qwerty_release_up(struct qwerty_device *qd);
178//! @public @memberof qwerty_device
179void
180qwerty_press_down(struct qwerty_device *qd);
181//! @public @memberof qwerty_device
182void
183qwerty_release_down(struct qwerty_device *qd);
184
185//! @public @memberof qwerty_device
186void
187qwerty_press_look_left(struct qwerty_device *qd);
188//! @public @memberof qwerty_device
189void
190qwerty_release_look_left(struct qwerty_device *qd);
191//! @public @memberof qwerty_device
192void
193qwerty_press_look_right(struct qwerty_device *qd);
194//! @public @memberof qwerty_device
195void
196qwerty_release_look_right(struct qwerty_device *qd);
197//! @public @memberof qwerty_device
198void
199qwerty_press_look_up(struct qwerty_device *qd);
200//! @public @memberof qwerty_device
201void
202qwerty_release_look_up(struct qwerty_device *qd);
203//! @public @memberof qwerty_device
204void
205qwerty_press_look_down(struct qwerty_device *qd);
206//! @public @memberof qwerty_device
207void
208qwerty_release_look_down(struct qwerty_device *qd);
209
210/*!
211 * Momentarily increase `movement_speed` until `qwerty_release_sprint()`
212 * @public @memberof qwerty_device
213 */
214void
216
217/*!
218 * Stop doing what @ref qwerty_press_sprint started.
219 * @public @memberof qwerty_device
220 */
221void
223
224/*!
225 * Add yaw and pitch movement for the next frame
226 * @public @memberof qwerty_device
227 */
228void
229qwerty_add_look_delta(struct qwerty_device *qd, float yaw, float pitch);
230
231/*!
232 * Change movement speed in exponential steps (usually integers, but any float allowed)
233 * @public @memberof qwerty_device
234 */
235void
236qwerty_change_movement_speed(struct qwerty_device *qd, float steps);
237
238/*!
239 * Release all movement input
240 * @public @memberof qwerty_device
241 */
242void
244
245/*!
246 * Create qwerty_hmd. Crash on failure.
247 * @public @memberof qwerty_hmd
248 */
249struct qwerty_hmd *
251
252/*!
253 * Cast to qwerty_hmd. Ensures returning a valid HMD or crashing.
254 * @public @memberof qwerty_hmd
255 */
256struct qwerty_hmd *
257qwerty_hmd(struct xrt_device *xd);
258
259/*
260 *
261 * qwerty_controller methods
262 *
263 */
264/*!
265 * Create qwerty_controller. Crash on failure.
266 * @public @memberof qwerty_controller
267 */
268struct qwerty_controller *
269qwerty_controller_create(bool is_left, struct qwerty_hmd *qhmd);
270
271/*!
272 * Cast to qwerty_controller. Ensures returning a valid controller or crashing.
273 * @public @memberof qwerty_controller
274 */
275struct qwerty_controller *
276qwerty_controller(struct xrt_device *xd);
277
278/*!
279 * Simulate pressing input/trigger/value to 1.0
280 * @public @memberof qwerty_controller
281 */
282void
284
285/*!
286 * Simulate releasing input/trigger/value to 0.0
287 * @public @memberof qwerty_controller
288 */
289void
291
292/*!
293 * Simulate pressing input/menu/click
294 * @public @memberof qwerty_controller
295 */
296void
298
299/*!
300 * Simulate releasing input/menu/click
301 * @public @memberof qwerty_controller
302 */
303void
305
306/*!
307 * Simulate pressing input/squeeze/click
308 * @public @memberof qwerty_controller
309 */
310void
312
313/*!
314 * Simulate releasing input/squeeze/click
315 * @public @memberof qwerty_controller
316 */
317void
319
320/*!
321 * Simulate pressing input/system/click
322 * @public @memberof qwerty_controller
323 */
324void
326
327/*!
328 * Simulate releasing input/system/click
329 * @public @memberof qwerty_controller
330 */
331void
333
334//! @public @memberof qwerty_controller
335void
336qwerty_press_thumbstick_left(struct qwerty_controller *qc);
337//! @public @memberof qwerty_controller
338void
339qwerty_release_thumbstick_left(struct qwerty_controller *qc);
340//! @public @memberof qwerty_controller
341void
342qwerty_press_thumbstick_right(struct qwerty_controller *qc);
343//! @public @memberof qwerty_controller
344void
345qwerty_release_thumbstick_right(struct qwerty_controller *qc);
346//! @public @memberof qwerty_controller
347void
348qwerty_press_thumbstick_up(struct qwerty_controller *qc);
349//! @public @memberof qwerty_controller
350void
351qwerty_release_thumbstick_up(struct qwerty_controller *qc);
352//! @public @memberof qwerty_controller
353void
354qwerty_press_thumbstick_down(struct qwerty_controller *qc);
355//! @public @memberof qwerty_controller
356void
357qwerty_release_thumbstick_down(struct qwerty_controller *qc);
358//! @public @memberof qwerty_controller
359void
360qwerty_press_thumbstick_click(struct qwerty_controller *qc);
361//! @public @memberof qwerty_controller
362void
363qwerty_release_thumbstick_click(struct qwerty_controller *qc);
364
365//! @public @memberof qwerty_controller
366void
367qwerty_press_trackpad_left(struct qwerty_controller *qc);
368//! @public @memberof qwerty_controller
369void
370qwerty_release_trackpad_left(struct qwerty_controller *qc);
371//! @public @memberof qwerty_controller
372void
373qwerty_press_trackpad_right(struct qwerty_controller *qc);
374//! @public @memberof qwerty_controller
375void
376qwerty_release_trackpad_right(struct qwerty_controller *qc);
377//! @public @memberof qwerty_controller
378void
379qwerty_press_trackpad_up(struct qwerty_controller *qc);
380//! @public @memberof qwerty_controller
381void
382qwerty_release_trackpad_up(struct qwerty_controller *qc);
383//! @public @memberof qwerty_controller
384void
385qwerty_press_trackpad_down(struct qwerty_controller *qc);
386//! @public @memberof qwerty_controller
387void
388qwerty_release_trackpad_down(struct qwerty_controller *qc);
389//! @public @memberof qwerty_controller
390void
391qwerty_press_trackpad_click(struct qwerty_controller *qc);
392//! @public @memberof qwerty_controller
393void
394qwerty_release_trackpad_click(struct qwerty_controller *qc);
395
396/*!
397 * Attach/detach the pose of `qc` to its HMD. Only works when a qwerty_hmd is present.
398 * @public @memberof qwerty_controller
399 */
400void
401qwerty_follow_hmd(struct qwerty_controller *qc, bool follow);
402
403/*!
404 * Reset controller to initial pose and makes it follow the HMD
405 * @public @memberof qwerty_controller
406 */
407void
409
410
411/*!
412 * @}
413 */
414
415#ifdef __cplusplus
416}
417#endif
u_logging_level
Logging level enum.
Definition: u_logging.h:43
struct qwerty_controller * qwerty_controller_create(bool is_left, struct qwerty_hmd *qhmd)
Create qwerty_controller.
Definition: qwerty_device.c:328
void qwerty_follow_hmd(struct qwerty_controller *qc, bool follow)
Attach/detach the pose of qc to its HMD.
Definition: qwerty_device.c:666
void qwerty_press_menu(struct qwerty_controller *qc)
Simulate pressing input/menu/click.
Definition: qwerty_device.c:580
void qwerty_release_squeeze(struct qwerty_controller *qc)
Simulate releasing input/squeeze/click.
Definition: qwerty_device.c:601
void qwerty_press_system(struct qwerty_controller *qc)
Simulate pressing input/system/click.
Definition: qwerty_device.c:608
struct qwerty_hmd * qwerty_hmd(struct xrt_device *xd)
Cast to qwerty_hmd.
Definition: qwerty_device.c:111
void qwerty_press_sprint(struct qwerty_device *qd)
Momentarily increase movement_speed until qwerty_release_sprint()
Definition: qwerty_device.c:522
void qwerty_release_system(struct qwerty_controller *qc)
Simulate releasing input/system/click.
Definition: qwerty_device.c:615
void qwerty_release_trigger(struct qwerty_controller *qc)
Simulate releasing input/trigger/value to 0.0.
Definition: qwerty_device.c:573
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:533
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:540
void qwerty_press_trigger(struct qwerty_controller *qc)
Simulate pressing input/trigger/value to 1.0.
Definition: qwerty_device.c:566
void qwerty_release_sprint(struct qwerty_device *qd)
Stop doing what qwerty_press_sprint started.
Definition: qwerty_device.c:527
struct qwerty_controller * qwerty_controller(struct xrt_device *xd)
Cast to qwerty_controller.
Definition: qwerty_device.c:123
struct qwerty_hmd * qwerty_hmd_create(void)
Create qwerty_hmd.
Definition: qwerty_device.c:274
void qwerty_release_all(struct qwerty_device *qd)
Release all movement input.
Definition: qwerty_device.c:546
void qwerty_reset_controller_pose(struct qwerty_controller *qc)
Reset controller to initial pose and makes it follow the HMD.
Definition: qwerty_device.c:692
struct qwerty_device * qwerty_device(struct xrt_device *xd)
Cast to qwerty_device.
Definition: qwerty_device.c:99
void qwerty_press_squeeze(struct qwerty_controller *qc)
Simulate pressing input/squeeze/click.
Definition: qwerty_device.c:594
void qwerty_release_menu(struct qwerty_controller *qc)
Simulate releasing input/menu/click.
Definition: qwerty_device.c:587
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:123
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:241
A pose composed of a position and orientation.
Definition: xrt_defines.h:465
Basic logging functionality.
Header defining an xrt display or controller device.