-
Notifications
You must be signed in to change notification settings - Fork 1
/
qwerty_device.h
224 lines (186 loc) · 5.86 KB
/
qwerty_device.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
// Copyright 2021, Mateo de Mayo.
// SPDX-License-Identifier: BSL-1.0
/*!
* @file
* @brief Internal header for qwerty_device and its friends.
* @author Mateo de Mayo <mateodemayo@gmail.com>
* @ingroup drv_qwerty
*/
#pragma once
#include "util/u_logging.h"
#include "xrt/xrt_device.h"
#define QWERTY_HMD_STR "Qwerty HMD"
#define QWERTY_HMD_TRACKER_STR QWERTY_HMD_STR " Tracker"
#define QWERTY_LEFT_STR "Qwerty Left Controller"
#define QWERTY_LEFT_TRACKER_STR QWERTY_LEFT_STR " Tracker"
#define QWERTY_RIGHT_STR "Qwerty Right Controller"
#define QWERTY_RIGHT_TRACKER_STR QWERTY_RIGHT_STR " Tracker"
#ifdef __cplusplus
extern "C" {
#endif
/*!
* @addtogroup drv_qwerty
* @{
*/
//! Container of qwerty devices and driver properties.
struct qwerty_system
{
struct qwerty_hmd *hmd;
struct qwerty_controller *lctrl;
struct qwerty_controller *rctrl;
enum u_logging_level ll;
bool process_keys; //!< If false disable keyboard and mouse input
bool hmd_focused; //!< For gui var tracking only, true if hmd is the focused device
bool lctrl_focused; //!< Same as `hmd_focused` but for the left controller
bool rctrl_focused; //!< Same as `hmd_focused` but for the right controller
};
//! Fake device that modifies its tracked pose through its methods.
//! @implements xrt_device
struct qwerty_device
{
struct xrt_device base;
struct xrt_pose pose; //!< Internal pose state
struct qwerty_system *sys; //!< Reference to the system this device is in.
float movement_speed; //!< In meters per frame
bool left_pressed;
bool right_pressed;
bool forward_pressed;
bool backward_pressed;
bool up_pressed;
bool down_pressed;
float look_speed; //!< In radians per frame
bool look_left_pressed;
bool look_right_pressed;
bool look_up_pressed;
bool look_down_pressed;
float yaw_delta; //!< How much extra yaw to add for the next pose. Then reset to 0.
float pitch_delta; //!< Similar to `yaw_delta`
};
//! @implements qwerty_device
struct qwerty_hmd
{
struct qwerty_device base;
};
//! Supports input actions and can be attached to the HMD pose.
//! @implements qwerty_device
struct qwerty_controller
{
struct qwerty_device base;
bool select_clicked;
bool menu_clicked;
/*!
* Only used when a qwerty_hmd exists in the system.
* Do not modify directly; use qwerty_follow_hmd().
* If true, `pose` is relative to the qwerty_hmd.
*/
bool follow_hmd; // @todo: Make this work with non-qwerty HMDs.
};
/*!
* @name Qwerty System
* @memberof qwerty_system
* qwerty_system public methods
* @{
*/
//! @public @memberof qwerty_system <!-- Trick for doxygen -->
struct qwerty_system *
qwerty_system_create(struct qwerty_hmd *qhmd,
struct qwerty_controller *qleft,
struct qwerty_controller *qright,
enum u_logging_level log_level);
/*!
* @}
*/
/*!
* @name Qwerty Device
* @memberof qwerty_device
* qwerty_device public methods
* @{
*/
//! @public @memberof qwerty_device <!-- Trick for doxygen -->
//! Cast to qwerty_device. Ensures returning a valid device or crashing.
struct qwerty_device *
qwerty_device(struct xrt_device *xd);
// clang-format off
void qwerty_press_left(struct qwerty_device *qd);
void qwerty_release_left(struct qwerty_device *qd);
void qwerty_press_right(struct qwerty_device *qd);
void qwerty_release_right(struct qwerty_device *qd);
void qwerty_press_forward(struct qwerty_device *qd);
void qwerty_release_forward(struct qwerty_device *qd);
void qwerty_press_backward(struct qwerty_device *qd);
void qwerty_release_backward(struct qwerty_device *qd);
void qwerty_press_up(struct qwerty_device *qd);
void qwerty_release_up(struct qwerty_device *qd);
void qwerty_press_down(struct qwerty_device *qd);
void qwerty_release_down(struct qwerty_device *qd);
void qwerty_press_look_left(struct qwerty_device *qd);
void qwerty_release_look_left(struct qwerty_device *qd);
void qwerty_press_look_right(struct qwerty_device *qd);
void qwerty_release_look_right(struct qwerty_device *qd);
void qwerty_press_look_up(struct qwerty_device *qd);
void qwerty_release_look_up(struct qwerty_device *qd);
void qwerty_press_look_down(struct qwerty_device *qd);
void qwerty_release_look_down(struct qwerty_device *qd);
// clang-format on
//! Add yaw and pitch movement for the next frame
void
qwerty_add_look_delta(struct qwerty_device *qd, float yaw, float pitch);
//! Change movement speed in exponential steps (usually integers, but any float allowed)
void
qwerty_change_movement_speed(struct qwerty_device *qd, float steps);
//! Release all movement input
void
qwerty_release_all(struct qwerty_device *qd);
/*!
* @}
*/
/*!
* @name Qwerty HMD
* @memberof qwerty_hmd
* qwerty_hmd public methods
* @{
*/
//! @public @memberof qwerty_hmd <!-- Trick for doxygen -->
//! Create qwerty_hmd. Crash on failure.
struct qwerty_hmd *
qwerty_hmd_create(void);
//! Cast to qwerty_hmd. Ensures returning a valid HMD or crashing.
struct qwerty_hmd *
qwerty_hmd(struct xrt_device *xd);
/*!
* @}
*/
/*!
* @name Qwerty Controller
* @memberof qwerty_controller
* qwerty_controller public methods
* @{
*/
//! @public @memberof qwerty_controller <!-- Trick for doxygen -->
//! Create qwerty_controller. Crash on failure.
struct qwerty_controller *
qwerty_controller_create(bool is_left, struct qwerty_hmd *qhmd);
//! Cast to qwerty_controller. Ensures returning a valid controller or crashing.
struct qwerty_controller *
qwerty_controller(struct xrt_device *xd);
//! Simulate input/select/click
void
qwerty_select_click(struct qwerty_controller *qc);
//! Simulate input/menu/click
void
qwerty_menu_click(struct qwerty_controller *qc);
//! Attach/detach the pose of `qc` to its HMD. Only works when a qwerty_hmd is present.
void
qwerty_follow_hmd(struct qwerty_controller *qc, bool follow);
//! Reset controller to initial pose and makes it follow the HMD
void
qwerty_reset_controller_pose(struct qwerty_controller *qc);
/*!
* @}
*/
/*!
* @}
*/
#ifdef __cplusplus
}
#endif