2021-03-11 14:25:00 +00:00
|
|
|
// 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
|
|
|
|
|
2021-03-11 20:13:58 +00:00
|
|
|
#include "util/u_logging.h"
|
2021-03-11 15:30:51 +00:00
|
|
|
#include "xrt/xrt_device.h"
|
|
|
|
|
2021-10-24 01:28:49 +00:00
|
|
|
/*!
|
|
|
|
* @addtogroup drv_qwerty
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2021-03-11 15:30:51 +00:00
|
|
|
#define QWERTY_HMD_STR "Qwerty HMD"
|
|
|
|
#define QWERTY_HMD_TRACKER_STR QWERTY_HMD_STR " Tracker"
|
2021-03-11 19:01:58 +00:00
|
|
|
#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"
|
2021-03-11 15:30:51 +00:00
|
|
|
|
2021-03-11 14:25:00 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2021-04-13 17:20:21 +00:00
|
|
|
/*!
|
|
|
|
* @brief Container of qwerty devices and driver properties.
|
|
|
|
* @see qwerty_hmd, qwerty_controller
|
|
|
|
*/
|
2021-03-11 19:56:52 +00:00
|
|
|
struct qwerty_system
|
|
|
|
{
|
|
|
|
struct qwerty_hmd *hmd; //!< Can be NULL
|
|
|
|
struct qwerty_controller *lctrl; //!< Cannot be NULL
|
|
|
|
struct qwerty_controller *rctrl; //!< Cannot be NULL
|
2021-03-11 20:13:58 +00:00
|
|
|
enum u_logging_level ll;
|
2021-03-11 19:56:52 +00:00
|
|
|
bool process_keys; //!< If false disable keyboard and mouse input
|
2021-03-11 20:10:24 +00:00
|
|
|
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
|
2021-03-11 19:56:52 +00:00
|
|
|
};
|
|
|
|
|
2021-04-13 17:20:21 +00:00
|
|
|
/*!
|
|
|
|
* Fake device that modifies its tracked pose through its methods.
|
|
|
|
* @implements xrt_device
|
|
|
|
*/
|
2021-03-11 15:30:51 +00:00
|
|
|
struct qwerty_device
|
|
|
|
{
|
|
|
|
struct xrt_device base;
|
2021-03-11 19:56:52 +00:00
|
|
|
struct xrt_pose pose; //!< Internal pose state
|
|
|
|
struct qwerty_system *sys; //!< Reference to the system this device is in.
|
2021-03-11 18:04:38 +00:00
|
|
|
|
|
|
|
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;
|
2021-03-11 18:14:54 +00:00
|
|
|
|
|
|
|
bool sprint_pressed; //!< Movement speed boost
|
2021-03-11 19:56:52 +00:00
|
|
|
float yaw_delta; //!< How much extra yaw to add for the next pose. Then reset to 0.
|
|
|
|
float pitch_delta; //!< Similar to `yaw_delta`
|
2021-03-11 15:30:51 +00:00
|
|
|
};
|
|
|
|
|
2021-04-13 17:20:21 +00:00
|
|
|
/*!
|
|
|
|
* @implements qwerty_device
|
|
|
|
* @see qwerty_system
|
|
|
|
*/
|
2021-03-11 19:01:58 +00:00
|
|
|
struct qwerty_hmd
|
|
|
|
{
|
|
|
|
struct qwerty_device base;
|
|
|
|
};
|
|
|
|
|
2021-04-13 17:20:21 +00:00
|
|
|
/*!
|
|
|
|
* Supports input actions and can be attached to the HMD pose.
|
|
|
|
* @implements qwerty_device
|
|
|
|
* @see qwerty_system
|
|
|
|
*/
|
2021-03-11 19:01:58 +00:00
|
|
|
struct qwerty_controller
|
|
|
|
{
|
|
|
|
struct qwerty_device base;
|
2021-03-11 20:23:17 +00:00
|
|
|
|
|
|
|
bool select_clicked;
|
|
|
|
bool menu_clicked;
|
2021-03-11 20:33:33 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* 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.
|
2021-03-11 19:01:58 +00:00
|
|
|
};
|
|
|
|
|
2021-03-11 19:56:52 +00:00
|
|
|
/*!
|
2021-04-13 17:20:21 +00:00
|
|
|
* @public @memberof qwerty_system
|
2021-03-11 19:56:52 +00:00
|
|
|
*/
|
|
|
|
struct qwerty_system *
|
|
|
|
qwerty_system_create(struct qwerty_hmd *qhmd,
|
|
|
|
struct qwerty_controller *qleft,
|
2021-03-11 20:13:58 +00:00
|
|
|
struct qwerty_controller *qright,
|
|
|
|
enum u_logging_level log_level);
|
2021-03-11 19:56:52 +00:00
|
|
|
|
2021-04-13 17:20:21 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* qwerty_device methods
|
|
|
|
*
|
2021-03-11 19:56:52 +00:00
|
|
|
*/
|
|
|
|
|
2021-03-11 18:04:38 +00:00
|
|
|
/*!
|
2021-04-13 17:20:21 +00:00
|
|
|
* @brief Cast to qwerty_device. Ensures returning a valid device or crashing.
|
|
|
|
* @public @memberof qwerty_device
|
2021-03-11 18:04:38 +00:00
|
|
|
*/
|
2021-03-11 15:30:51 +00:00
|
|
|
struct qwerty_device *
|
|
|
|
qwerty_device(struct xrt_device *xd);
|
|
|
|
|
2021-04-13 17:20:21 +00:00
|
|
|
//! @public @memberof qwerty_device
|
|
|
|
void
|
|
|
|
qwerty_press_left(struct qwerty_device *qd);
|
|
|
|
//! @public @memberof qwerty_device
|
|
|
|
void
|
|
|
|
qwerty_release_left(struct qwerty_device *qd);
|
|
|
|
//! @public @memberof qwerty_device
|
|
|
|
void
|
|
|
|
qwerty_press_right(struct qwerty_device *qd);
|
|
|
|
//! @public @memberof qwerty_device
|
|
|
|
void
|
|
|
|
qwerty_release_right(struct qwerty_device *qd);
|
|
|
|
//! @public @memberof qwerty_device
|
|
|
|
void
|
|
|
|
qwerty_press_forward(struct qwerty_device *qd);
|
|
|
|
//! @public @memberof qwerty_device
|
|
|
|
void
|
|
|
|
qwerty_release_forward(struct qwerty_device *qd);
|
|
|
|
//! @public @memberof qwerty_device
|
|
|
|
void
|
|
|
|
qwerty_press_backward(struct qwerty_device *qd);
|
|
|
|
//! @public @memberof qwerty_device
|
|
|
|
void
|
|
|
|
qwerty_release_backward(struct qwerty_device *qd);
|
|
|
|
//! @public @memberof qwerty_device
|
|
|
|
void
|
|
|
|
qwerty_press_up(struct qwerty_device *qd);
|
|
|
|
//! @public @memberof qwerty_device
|
|
|
|
void
|
|
|
|
qwerty_release_up(struct qwerty_device *qd);
|
|
|
|
//! @public @memberof qwerty_device
|
|
|
|
void
|
|
|
|
qwerty_press_down(struct qwerty_device *qd);
|
|
|
|
//! @public @memberof qwerty_device
|
|
|
|
void
|
|
|
|
qwerty_release_down(struct qwerty_device *qd);
|
|
|
|
|
|
|
|
//! @public @memberof qwerty_device
|
|
|
|
void
|
|
|
|
qwerty_press_look_left(struct qwerty_device *qd);
|
|
|
|
//! @public @memberof qwerty_device
|
|
|
|
void
|
|
|
|
qwerty_release_look_left(struct qwerty_device *qd);
|
|
|
|
//! @public @memberof qwerty_device
|
|
|
|
void
|
|
|
|
qwerty_press_look_right(struct qwerty_device *qd);
|
|
|
|
//! @public @memberof qwerty_device
|
|
|
|
void
|
|
|
|
qwerty_release_look_right(struct qwerty_device *qd);
|
|
|
|
//! @public @memberof qwerty_device
|
|
|
|
void
|
|
|
|
qwerty_press_look_up(struct qwerty_device *qd);
|
|
|
|
//! @public @memberof qwerty_device
|
|
|
|
void
|
|
|
|
qwerty_release_look_up(struct qwerty_device *qd);
|
|
|
|
//! @public @memberof qwerty_device
|
|
|
|
void
|
|
|
|
qwerty_press_look_down(struct qwerty_device *qd);
|
|
|
|
//! @public @memberof qwerty_device
|
|
|
|
void
|
|
|
|
qwerty_release_look_down(struct qwerty_device *qd);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Momentarily increase `movement_speed` until `qwerty_release_sprint()`
|
|
|
|
* @public @memberof qwerty_device
|
|
|
|
*/
|
2021-03-11 18:14:54 +00:00
|
|
|
void
|
|
|
|
qwerty_press_sprint(struct qwerty_device *qd);
|
|
|
|
|
2021-04-13 17:20:21 +00:00
|
|
|
/*!
|
|
|
|
* Stop doing what @ref qwerty_press_sprint started.
|
|
|
|
* @public @memberof qwerty_device
|
|
|
|
*/
|
2021-03-11 18:14:54 +00:00
|
|
|
void
|
|
|
|
qwerty_release_sprint(struct qwerty_device *qd);
|
|
|
|
|
2021-04-13 17:20:21 +00:00
|
|
|
/*!
|
|
|
|
* Add yaw and pitch movement for the next frame
|
|
|
|
* @public @memberof qwerty_device
|
|
|
|
*/
|
2021-03-11 18:14:54 +00:00
|
|
|
void
|
|
|
|
qwerty_add_look_delta(struct qwerty_device *qd, float yaw, float pitch);
|
|
|
|
|
2021-04-13 17:20:21 +00:00
|
|
|
/*!
|
|
|
|
* Change movement speed in exponential steps (usually integers, but any float allowed)
|
|
|
|
* @public @memberof qwerty_device
|
|
|
|
*/
|
2021-03-11 18:14:54 +00:00
|
|
|
void
|
|
|
|
qwerty_change_movement_speed(struct qwerty_device *qd, float steps);
|
|
|
|
|
2021-03-11 19:01:58 +00:00
|
|
|
/*!
|
2021-04-13 17:20:21 +00:00
|
|
|
* Release all movement input
|
|
|
|
* @public @memberof qwerty_device
|
2021-03-11 19:01:58 +00:00
|
|
|
*/
|
2021-04-13 17:20:21 +00:00
|
|
|
void
|
|
|
|
qwerty_release_all(struct qwerty_device *qd);
|
2021-03-11 19:01:58 +00:00
|
|
|
|
|
|
|
/*!
|
2021-04-13 17:20:21 +00:00
|
|
|
* Create qwerty_hmd. Crash on failure.
|
|
|
|
* @public @memberof qwerty_hmd
|
2021-03-11 19:01:58 +00:00
|
|
|
*/
|
|
|
|
struct qwerty_hmd *
|
|
|
|
qwerty_hmd_create(void);
|
|
|
|
|
2021-04-13 17:20:21 +00:00
|
|
|
/*!
|
|
|
|
* Cast to qwerty_hmd. Ensures returning a valid HMD or crashing.
|
|
|
|
* @public @memberof qwerty_hmd
|
|
|
|
*/
|
2021-03-11 19:30:14 +00:00
|
|
|
struct qwerty_hmd *
|
|
|
|
qwerty_hmd(struct xrt_device *xd);
|
|
|
|
|
2021-04-13 17:20:21 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* qwerty_controller methods
|
|
|
|
*
|
2021-03-11 19:01:58 +00:00
|
|
|
*/
|
|
|
|
/*!
|
2021-04-13 17:20:21 +00:00
|
|
|
* Create qwerty_controller. Crash on failure.
|
|
|
|
* @public @memberof qwerty_controller
|
2021-03-11 19:01:58 +00:00
|
|
|
*/
|
|
|
|
struct qwerty_controller *
|
|
|
|
qwerty_controller_create(bool is_left, struct qwerty_hmd *qhmd);
|
|
|
|
|
2021-04-13 17:20:21 +00:00
|
|
|
/*!
|
|
|
|
* Cast to qwerty_controller. Ensures returning a valid controller or crashing.
|
|
|
|
* @public @memberof qwerty_controller
|
|
|
|
*/
|
2021-03-11 19:30:14 +00:00
|
|
|
struct qwerty_controller *
|
|
|
|
qwerty_controller(struct xrt_device *xd);
|
|
|
|
|
2021-04-13 17:20:21 +00:00
|
|
|
/*!
|
|
|
|
* Simulate input/select/click
|
|
|
|
* @public @memberof qwerty_controller
|
|
|
|
*/
|
2021-03-11 20:23:17 +00:00
|
|
|
void
|
|
|
|
qwerty_select_click(struct qwerty_controller *qc);
|
|
|
|
|
2021-04-13 17:20:21 +00:00
|
|
|
/*!
|
|
|
|
* Simulate input/menu/click
|
|
|
|
* @public @memberof qwerty_controller
|
|
|
|
*/
|
2021-03-11 20:23:17 +00:00
|
|
|
void
|
|
|
|
qwerty_menu_click(struct qwerty_controller *qc);
|
|
|
|
|
2021-04-13 17:20:21 +00:00
|
|
|
/*!
|
|
|
|
* Attach/detach the pose of `qc` to its HMD. Only works when a qwerty_hmd is present.
|
|
|
|
* @public @memberof qwerty_controller
|
|
|
|
*/
|
2021-03-11 20:33:33 +00:00
|
|
|
void
|
|
|
|
qwerty_follow_hmd(struct qwerty_controller *qc, bool follow);
|
|
|
|
|
2021-04-13 17:20:21 +00:00
|
|
|
/*!
|
|
|
|
* Reset controller to initial pose and makes it follow the HMD
|
|
|
|
* @public @memberof qwerty_controller
|
|
|
|
*/
|
2021-03-11 20:35:14 +00:00
|
|
|
void
|
|
|
|
qwerty_reset_controller_pose(struct qwerty_controller *qc);
|
|
|
|
|
2021-03-11 18:04:38 +00:00
|
|
|
|
2021-03-11 14:25:00 +00:00
|
|
|
/*!
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|