lovr/src/modules/headset/headset.h

159 lines
4.5 KiB
C
Raw Normal View History

2017-10-31 08:14:09 +00:00
#include <stdbool.h>
2019-04-05 12:08:03 +00:00
#include <stdint.h>
#include <stddef.h>
2016-12-01 04:32:14 +00:00
2017-01-26 10:20:30 +00:00
#pragma once
2016-11-15 00:20:56 +00:00
2020-08-12 21:47:10 +00:00
#define HAND_JOINT_COUNT 26
2020-02-13 05:37:52 +00:00
struct Model;
2019-04-05 12:08:03 +00:00
struct ModelData;
struct Texture;
typedef enum {
2019-03-07 07:02:03 +00:00
DRIVER_DESKTOP,
2019-04-11 20:47:25 +00:00
DRIVER_OPENXR,
2020-03-05 06:47:24 +00:00
DRIVER_WEBXR
} HeadsetDriver;
2020-02-13 05:37:52 +00:00
typedef enum {
ORIGIN_HEAD,
ORIGIN_FLOOR
} HeadsetOrigin;
typedef enum {
DEVICE_HEAD,
DEVICE_HAND_LEFT,
DEVICE_HAND_RIGHT,
2020-02-15 03:10:37 +00:00
DEVICE_HAND_LEFT_POINT,
DEVICE_HAND_RIGHT_POINT,
2020-11-19 07:39:38 +00:00
DEVICE_ELBOW_LEFT,
DEVICE_ELBOW_RIGHT,
DEVICE_SHOULDER_LEFT,
DEVICE_SHOULDER_RIGHT,
DEVICE_CHEST,
DEVICE_WAIST,
DEVICE_KNEE_LEFT,
DEVICE_KNEE_RIGHT,
DEVICE_FOOT_LEFT,
DEVICE_FOOT_RIGHT,
DEVICE_CAMERA,
DEVICE_KEYBOARD,
DEVICE_EYE_LEFT,
DEVICE_EYE_RIGHT,
DEVICE_EYE_GAZE,
DEVICE_BEACON_1,
DEVICE_BEACON_2,
DEVICE_BEACON_3,
DEVICE_BEACON_4,
2019-05-13 05:04:41 +00:00
MAX_DEVICES
} Device;
typedef enum {
BUTTON_TRIGGER,
BUTTON_THUMBSTICK,
2022-01-29 23:39:55 +00:00
BUTTON_THUMBREST,
2019-05-08 23:57:51 +00:00
BUTTON_TOUCHPAD,
BUTTON_GRIP,
BUTTON_MENU,
BUTTON_A,
BUTTON_B,
BUTTON_X,
BUTTON_Y,
2019-05-13 05:04:41 +00:00
BUTTON_PROXIMITY,
MAX_BUTTONS
} DeviceButton;
typedef enum {
AXIS_TRIGGER,
2019-05-13 05:04:41 +00:00
AXIS_THUMBSTICK,
AXIS_TOUCHPAD,
AXIS_GRIP,
MAX_AXES
} DeviceAxis;
2020-08-12 21:47:10 +00:00
typedef enum {
JOINT_PALM,
JOINT_WRIST,
JOINT_THUMB_METACARPAL,
JOINT_THUMB_PROXIMAL,
JOINT_THUMB_DISTAL,
JOINT_THUMB_TIP,
JOINT_INDEX_METACARPAL,
JOINT_INDEX_PROXIMAL,
JOINT_INDEX_INTERMEDIATE,
JOINT_INDEX_DISTAL,
JOINT_INDEX_TIP,
JOINT_MIDDLE_METACARPAL,
JOINT_MIDDLE_PROXIMAL,
JOINT_MIDDLE_INTERMEDIATE,
JOINT_MIDDLE_DISTAL,
JOINT_MIDDLE_TIP,
JOINT_RING_METACARPAL,
JOINT_RING_PROXIMAL,
JOINT_RING_INTERMEDIATE,
JOINT_RING_DISTAL,
JOINT_RING_TIP,
JOINT_PINKY_METACARPAL,
JOINT_PINKY_PROXIMAL,
JOINT_PINKY_INTERMEDIATE,
JOINT_PINKY_DISTAL,
JOINT_PINKY_TIP
} HandJoint;
// Notes:
// - init is called immediately, the graphics module may not exist yet
// - start is called after the graphics module is initialized, can be used to set up graphics objects
// - getDisplayFrequency may return 0.f if the information is unavailable.
// - For isDown, changed can be set to false if change information is unavailable or inconvenient.
// - getAxis may write 4 floats to the output value. The expected number is a constant (see axisCounts in l_headset).
// - In general, most input results should be kept constant between calls to update.
typedef struct HeadsetInterface {
struct HeadsetInterface* next;
HeadsetDriver driverType;
2020-11-18 00:38:27 +00:00
bool (*init)(float supersample, float offset, uint32_t msaa, bool overlay);
void (*start)(void);
2019-02-17 22:39:51 +00:00
void (*destroy)(void);
2019-04-19 04:03:38 +00:00
bool (*getName)(char* name, size_t length);
2019-02-17 22:39:51 +00:00
HeadsetOrigin (*getOriginType)(void);
void (*getDisplayDimensions)(uint32_t* width, uint32_t* height);
2020-01-25 07:06:30 +00:00
float (*getDisplayFrequency)(void);
2019-06-28 07:13:30 +00:00
const float* (*getDisplayMask)(uint32_t* count);
2019-04-30 23:46:36 +00:00
double (*getDisplayTime)(void);
uint32_t (*getViewCount)(void);
bool (*getViewPose)(uint32_t view, float* position, float* orientation);
bool (*getViewAngles)(uint32_t view, float* left, float* right, float* up, float* down);
void (*getClipDistance)(float* clipNear, float* clipFar);
void (*setClipDistance)(float clipNear, float clipFar);
2018-04-29 21:38:08 +00:00
void (*getBoundsDimensions)(float* width, float* depth);
2019-05-21 03:35:07 +00:00
const float* (*getBoundsGeometry)(uint32_t* count);
bool (*getPose)(Device device, float* position, float* orientation);
bool (*getVelocity)(Device device, float* velocity, float* angularVelocity);
bool (*isDown)(Device device, DeviceButton button, bool* down, bool* changed);
bool (*isTouched)(Device device, DeviceButton button, bool* touched);
bool (*getAxis)(Device device, DeviceAxis axis, float* value);
2020-08-12 21:47:10 +00:00
bool (*getSkeleton)(Device device, float* poses);
bool (*vibrate)(Device device, float strength, float duration, float frequency);
struct ModelData* (*newModelData)(Device device, bool animated);
bool (*animate)(Device device, struct Model* model);
2018-03-11 07:42:33 +00:00
void (*renderTo)(void (*callback)(void*), void* userdata);
2019-04-05 12:08:03 +00:00
struct Texture* (*getMirrorTexture)(void);
void (*update)(float dt);
2017-10-22 23:44:26 +00:00
} HeadsetInterface;
2018-04-28 23:59:53 +00:00
// Available drivers
2019-04-11 20:47:25 +00:00
extern HeadsetInterface lovrHeadsetOpenXRDriver;
2020-03-05 06:47:24 +00:00
extern HeadsetInterface lovrHeadsetWebXRDriver;
2019-03-07 07:02:03 +00:00
extern HeadsetInterface lovrHeadsetDesktopDriver;
// Active drivers
2020-09-28 00:13:00 +00:00
extern HeadsetInterface* lovrHeadsetDisplayDriver;
extern HeadsetInterface* lovrHeadsetTrackingDrivers;
#define FOREACH_TRACKING_DRIVER(i)\
for (HeadsetInterface* i = lovrHeadsetTrackingDrivers; i != NULL; i = i->next)
2016-12-01 07:03:58 +00:00
2020-11-18 00:38:27 +00:00
bool lovrHeadsetInit(HeadsetDriver* drivers, size_t count, float supersample, float offset, uint32_t msaa, bool overlay);
2019-02-17 22:39:51 +00:00
void lovrHeadsetDestroy(void);