Monado OpenXR Runtime
Loading...
Searching...
No Matches
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 "util/u_time.h"
13
14#include "xrt/xrt_device.h"
15
16
17/*!
18 * @addtogroup drv_qwerty
19 * @{
20 */
21
22#define QWERTY_HMD_STR "Qwerty HMD"
23#define QWERTY_HMD_TRACKER_STR QWERTY_HMD_STR " Tracker"
24#define QWERTY_LEFT_STR "Qwerty Left Controller"
25#define QWERTY_LEFT_TRACKER_STR QWERTY_LEFT_STR " Tracker"
26#define QWERTY_RIGHT_STR "Qwerty Right Controller"
27#define QWERTY_RIGHT_TRACKER_STR QWERTY_RIGHT_STR " Tracker"
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33/*!
34 * @brief Container of qwerty devices and driver properties.
35 * @see qwerty_hmd, qwerty_controller
36 */
38{
39 struct qwerty_hmd *hmd; //!< Can be NULL
40 struct qwerty_controller *lctrl; //!< Cannot be NULL
41 struct qwerty_controller *rctrl; //!< Cannot be NULL
42 enum u_logging_level log_level;
43 bool process_keys; //!< If false disable keyboard and mouse input
44 bool hmd_focused; //!< For gui var tracking only, true if hmd is the focused device
45 bool lctrl_focused; //!< Same as `hmd_focused` but for the left controller
46 bool rctrl_focused; //!< Same as `hmd_focused` but for the right controller
47};
48
49/*!
50 * Fake device that modifies its tracked pose through its methods.
51 * @implements xrt_device
52 */
54{
55 struct xrt_device base;
56 struct xrt_pose pose; //!< Internal pose state
57 struct qwerty_system *sys; //!< Reference to the system this device is in.
58
59 float movement_speed; //!< In meters per frame
60 bool left_pressed;
61 bool right_pressed;
62 bool forward_pressed;
63 bool backward_pressed;
64 bool up_pressed;
65 bool down_pressed;
66
67 float look_speed; //!< In radians per frame
68 bool look_left_pressed;
69 bool look_right_pressed;
70 bool look_up_pressed;
71 bool look_down_pressed;
72
73 bool sprint_pressed; //!< Movement speed boost
74 float yaw_delta; //!< How much extra yaw to add for the next pose. Then reset to 0.
75 float pitch_delta; //!< Similar to `yaw_delta`
76};
77
78/*!
79 * @implements qwerty_device
80 * @see qwerty_system
81 */
83{
84 struct qwerty_device base;
85
86 time_duration_ns present_to_display_offset_ns;
87};
88
89/*!
90 * Supports input actions and can be attached to the HMD pose.
91 * @implements qwerty_device
92 * @see qwerty_system
93 */
95{
96 struct qwerty_device base;
97
98 bool trigger_clicked;
99 int64_t trigger_timestamp;
100 bool menu_clicked;
101 int64_t menu_timestamp;
102 bool squeeze_clicked;
103 int64_t squeeze_timestamp;
104 bool system_clicked;
105 int64_t system_timestamp;
106
107 bool thumbstick_left_pressed;
108 bool thumbstick_right_pressed;
109 bool thumbstick_up_pressed;
110 bool thumbstick_down_pressed;
111 int64_t thumbstick_timestamp;
112 bool thumbstick_clicked;
113 int64_t thumbstick_click_timestamp;
114
115 bool trackpad_left_pressed;
116 bool trackpad_right_pressed;
117 bool trackpad_up_pressed;
118 bool trackpad_down_pressed;
119 int64_t trackpad_timestamp;
120 bool trackpad_clicked;
121 int64_t trackpad_click_timestamp;
122
123 /*!
124 * Only used when a qwerty_hmd exists in the system.
125 * Do not modify directly; use qwerty_follow_hmd().
126 * If true, `pose` is relative to the qwerty_hmd.
127 */
128 bool follow_hmd; // @todo: Make this work with non-qwerty HMDs.
129};
130
131/*!
132 * @public @memberof qwerty_system
133 */
134struct qwerty_system *
135qwerty_system_create(struct qwerty_hmd *qhmd,
136 struct qwerty_controller *qleft,
137 struct qwerty_controller *qright,
138 enum u_logging_level log_level);
139
140/*
141 *
142 * qwerty_device methods
143 *
144 */
145
146/*!
147 * @brief Cast to qwerty_device. Ensures returning a valid device or crashing.
148 * @public @memberof qwerty_device
149 */
150struct qwerty_device *
151qwerty_device(struct xrt_device *xd);
152
153//! @public @memberof qwerty_device
154void
155qwerty_press_left(struct qwerty_device *qd);
156//! @public @memberof qwerty_device
157void
158qwerty_release_left(struct qwerty_device *qd);
159//! @public @memberof qwerty_device
160void
161qwerty_press_right(struct qwerty_device *qd);
162//! @public @memberof qwerty_device
163void
164qwerty_release_right(struct qwerty_device *qd);
165//! @public @memberof qwerty_device
166void
167qwerty_press_forward(struct qwerty_device *qd);
168//! @public @memberof qwerty_device
169void
170qwerty_release_forward(struct qwerty_device *qd);
171//! @public @memberof qwerty_device
172void
173qwerty_press_backward(struct qwerty_device *qd);
174//! @public @memberof qwerty_device
175void
176qwerty_release_backward(struct qwerty_device *qd);
177//! @public @memberof qwerty_device
178void
179qwerty_press_up(struct qwerty_device *qd);
180//! @public @memberof qwerty_device
181void
182qwerty_release_up(struct qwerty_device *qd);
183//! @public @memberof qwerty_device
184void
185qwerty_press_down(struct qwerty_device *qd);
186//! @public @memberof qwerty_device
187void
188qwerty_release_down(struct qwerty_device *qd);
189
190//! @public @memberof qwerty_device
191void
192qwerty_press_look_left(struct qwerty_device *qd);
193//! @public @memberof qwerty_device
194void
195qwerty_release_look_left(struct qwerty_device *qd);
196//! @public @memberof qwerty_device
197void
198qwerty_press_look_right(struct qwerty_device *qd);
199//! @public @memberof qwerty_device
200void
201qwerty_release_look_right(struct qwerty_device *qd);
202//! @public @memberof qwerty_device
203void
204qwerty_press_look_up(struct qwerty_device *qd);
205//! @public @memberof qwerty_device
206void
207qwerty_release_look_up(struct qwerty_device *qd);
208//! @public @memberof qwerty_device
209void
210qwerty_press_look_down(struct qwerty_device *qd);
211//! @public @memberof qwerty_device
212void
213qwerty_release_look_down(struct qwerty_device *qd);
214
215/*!
216 * Momentarily increase `movement_speed` until `qwerty_release_sprint()`
217 * @public @memberof qwerty_device
218 */
219void
221
222/*!
223 * Stop doing what @ref qwerty_press_sprint started.
224 * @public @memberof qwerty_device
225 */
226void
228
229/*!
230 * Add yaw and pitch movement for the next frame
231 * @public @memberof qwerty_device
232 */
233void
234qwerty_add_look_delta(struct qwerty_device *qd, float yaw, float pitch);
235
236/*!
237 * Change movement speed in exponential steps (usually integers, but any float allowed)
238 * @public @memberof qwerty_device
239 */
240void
241qwerty_change_movement_speed(struct qwerty_device *qd, float steps);
242
243/*!
244 * Release all movement input
245 * @public @memberof qwerty_device
246 */
247void
249
250/*!
251 * Create qwerty_hmd. Crash on failure.
252 * @public @memberof qwerty_hmd
253 */
254struct qwerty_hmd *
256
257/*!
258 * Cast to qwerty_hmd. Ensures returning a valid HMD or crashing.
259 * @public @memberof qwerty_hmd
260 */
261struct qwerty_hmd *
262qwerty_hmd(struct xrt_device *xd);
263
264/*
265 *
266 * qwerty_controller methods
267 *
268 */
269/*!
270 * Create qwerty_controller. Crash on failure.
271 * @public @memberof qwerty_controller
272 */
273struct qwerty_controller *
274qwerty_controller_create(bool is_left, struct qwerty_hmd *qhmd);
275
276/*!
277 * Cast to qwerty_controller. Ensures returning a valid controller or crashing.
278 * @public @memberof qwerty_controller
279 */
280struct qwerty_controller *
281qwerty_controller(struct xrt_device *xd);
282
283/*!
284 * Simulate pressing input/trigger/value to 1.0
285 * @public @memberof qwerty_controller
286 */
287void
289
290/*!
291 * Simulate releasing input/trigger/value to 0.0
292 * @public @memberof qwerty_controller
293 */
294void
296
297/*!
298 * Simulate pressing input/menu/click
299 * @public @memberof qwerty_controller
300 */
301void
303
304/*!
305 * Simulate releasing input/menu/click
306 * @public @memberof qwerty_controller
307 */
308void
310
311/*!
312 * Simulate pressing input/squeeze/click
313 * @public @memberof qwerty_controller
314 */
315void
317
318/*!
319 * Simulate releasing input/squeeze/click
320 * @public @memberof qwerty_controller
321 */
322void
324
325/*!
326 * Simulate pressing input/system/click
327 * @public @memberof qwerty_controller
328 */
329void
331
332/*!
333 * Simulate releasing input/system/click
334 * @public @memberof qwerty_controller
335 */
336void
338
339//! @public @memberof qwerty_controller
340void
341qwerty_press_thumbstick_left(struct qwerty_controller *qc);
342//! @public @memberof qwerty_controller
343void
344qwerty_release_thumbstick_left(struct qwerty_controller *qc);
345//! @public @memberof qwerty_controller
346void
347qwerty_press_thumbstick_right(struct qwerty_controller *qc);
348//! @public @memberof qwerty_controller
349void
350qwerty_release_thumbstick_right(struct qwerty_controller *qc);
351//! @public @memberof qwerty_controller
352void
353qwerty_press_thumbstick_up(struct qwerty_controller *qc);
354//! @public @memberof qwerty_controller
355void
356qwerty_release_thumbstick_up(struct qwerty_controller *qc);
357//! @public @memberof qwerty_controller
358void
359qwerty_press_thumbstick_down(struct qwerty_controller *qc);
360//! @public @memberof qwerty_controller
361void
362qwerty_release_thumbstick_down(struct qwerty_controller *qc);
363//! @public @memberof qwerty_controller
364void
365qwerty_press_thumbstick_click(struct qwerty_controller *qc);
366//! @public @memberof qwerty_controller
367void
368qwerty_release_thumbstick_click(struct qwerty_controller *qc);
369
370//! @public @memberof qwerty_controller
371void
372qwerty_press_trackpad_left(struct qwerty_controller *qc);
373//! @public @memberof qwerty_controller
374void
375qwerty_release_trackpad_left(struct qwerty_controller *qc);
376//! @public @memberof qwerty_controller
377void
378qwerty_press_trackpad_right(struct qwerty_controller *qc);
379//! @public @memberof qwerty_controller
380void
381qwerty_release_trackpad_right(struct qwerty_controller *qc);
382//! @public @memberof qwerty_controller
383void
384qwerty_press_trackpad_up(struct qwerty_controller *qc);
385//! @public @memberof qwerty_controller
386void
387qwerty_release_trackpad_up(struct qwerty_controller *qc);
388//! @public @memberof qwerty_controller
389void
390qwerty_press_trackpad_down(struct qwerty_controller *qc);
391//! @public @memberof qwerty_controller
392void
393qwerty_release_trackpad_down(struct qwerty_controller *qc);
394//! @public @memberof qwerty_controller
395void
396qwerty_press_trackpad_click(struct qwerty_controller *qc);
397//! @public @memberof qwerty_controller
398void
399qwerty_release_trackpad_click(struct qwerty_controller *qc);
400
401/*!
402 * Attach/detach the pose of `qc` to its HMD. Only works when a qwerty_hmd is present.
403 * @public @memberof qwerty_controller
404 */
405void
406qwerty_follow_hmd(struct qwerty_controller *qc, bool follow);
407
408/*!
409 * Reset controller to initial pose and makes it follow the HMD
410 * @public @memberof qwerty_controller
411 */
412void
414
415
416/*!
417 * @}
418 */
419
420#ifdef __cplusplus
421}
422#endif
u_logging_level
Logging level enum.
Definition u_logging.h:45
int64_t time_duration_ns
Integer duration type in nanoseconds.
Definition u_time.h:88
void qwerty_follow_hmd(struct qwerty_controller *qc, bool follow)
Attach/detach the pose of qc to its HMD.
Definition qwerty_device.c:669
void qwerty_press_menu(struct qwerty_controller *qc)
Simulate pressing input/menu/click.
Definition qwerty_device.c:583
void qwerty_release_squeeze(struct qwerty_controller *qc)
Simulate releasing input/squeeze/click.
Definition qwerty_device.c:604
void qwerty_press_system(struct qwerty_controller *qc)
Simulate pressing input/system/click.
Definition qwerty_device.c:611
void qwerty_press_sprint(struct qwerty_device *qd)
Momentarily increase movement_speed until qwerty_release_sprint()
Definition qwerty_device.c:525
void qwerty_release_system(struct qwerty_controller *qc)
Simulate releasing input/system/click.
Definition qwerty_device.c:618
void qwerty_release_trigger(struct qwerty_controller *qc)
Simulate releasing input/trigger/value to 0.0.
Definition qwerty_device.c:576
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:536
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:543
void qwerty_press_trigger(struct qwerty_controller *qc)
Simulate pressing input/trigger/value to 1.0.
Definition qwerty_device.c:569
void qwerty_release_sprint(struct qwerty_device *qd)
Stop doing what qwerty_press_sprint started.
Definition qwerty_device.c:530
struct qwerty_hmd * qwerty_hmd_create(void)
Create qwerty_hmd.
Definition qwerty_device.c:272
void qwerty_release_all(struct qwerty_device *qd)
Release all movement input.
Definition qwerty_device.c:549
void qwerty_reset_controller_pose(struct qwerty_controller *qc)
Reset controller to initial pose and makes it follow the HMD.
Definition qwerty_device.c:695
void qwerty_press_squeeze(struct qwerty_controller *qc)
Simulate pressing input/squeeze/click.
Definition qwerty_device.c:597
void qwerty_release_menu(struct qwerty_controller *qc)
Simulate releasing input/menu/click.
Definition qwerty_device.c:590
struct qwerty_controller * qwerty_controller_create(bool is_left, struct qwerty_hmd *qhmd)
Definition qwerty_device.c:329
Supports input actions and can be attached to the HMD pose.
Definition qwerty_device.h:95
bool follow_hmd
Only used when a qwerty_hmd exists in the system.
Definition qwerty_device.h:128
Fake device that modifies its tracked pose through its methods.
Definition qwerty_device.h:54
float pitch_delta
Similar to yaw_delta
Definition qwerty_device.h:75
struct xrt_pose pose
Internal pose state.
Definition qwerty_device.h:56
struct qwerty_system * sys
Reference to the system this device is in.
Definition qwerty_device.h:57
bool sprint_pressed
Movement speed boost.
Definition qwerty_device.h:73
float look_speed
In radians per frame.
Definition qwerty_device.h:67
float yaw_delta
How much extra yaw to add for the next pose.
Definition qwerty_device.h:74
float movement_speed
In meters per frame.
Definition qwerty_device.h:59
Definition qwerty_device.h:83
Container of qwerty devices and driver properties.
Definition qwerty_device.h:38
struct qwerty_hmd * hmd
Can be NULL.
Definition qwerty_device.h:39
bool process_keys
If false disable keyboard and mouse input.
Definition qwerty_device.h:43
bool hmd_focused
For gui var tracking only, true if hmd is the focused device.
Definition qwerty_device.h:44
struct qwerty_controller * lctrl
Cannot be NULL.
Definition qwerty_device.h:40
bool rctrl_focused
Same as hmd_focused but for the right controller.
Definition qwerty_device.h:46
bool lctrl_focused
Same as hmd_focused but for the left controller.
Definition qwerty_device.h:45
struct qwerty_controller * rctrl
Cannot be NULL.
Definition qwerty_device.h:41
A single HMD or input device.
Definition xrt_device.h:345
A pose composed of a position and orientation.
Definition xrt_defines.h:535
Basic logging functionality.
Time-keeping: a clock that is steady, convertible to system time, and ideally high-resolution.
Header defining an xrt display or controller device.