1
0
Fork 0
mirror of https://github.com/bjornbytes/lovr.git synced 2024-07-04 13:33:34 +00:00
lovr/src/modules/headset/headset_webxr.c

88 lines
3.3 KiB
C
Raw Normal View History

2020-03-05 06:47:24 +00:00
#include "headset/headset.h"
extern bool webxr_init(HeadsetConfig* config);
extern void webxr_start(void);
2020-03-05 06:47:24 +00:00
extern void webxr_destroy(void);
extern bool webxr_getDriverName(char* name, size_t length);
2020-03-05 06:47:24 +00:00
extern bool webxr_getName(char* name, size_t length);
Replace HeadsetOrigin with 'seated' flag; Origin type used to be a query-able property of the VR system that indicated whether the tracking was roomscale or seated-scale. The t.headset.offset config value could be used to design an origin-agnostic experience, which by default shifted content up 1.7 meters when tracking was seated-scale. That way, stuff rendered at y=1.7m was always at "eye level". It worked pretty well. It's getting replaced with a t.headset.seated flag. - If seated is false (the default), the origin of the coordinate space will be on the floor, enabling the y=1.7m eye level paradigm. If tracking is not roomscale, a floor offset of 1.7m will be emulated. - If seated is true, the origin of the coordinate space will be y=0 at eye level (where the headset was when the app started). This is the case on both roomscale and seated-scale tracking. So basically 'seated' is an opt-in preference for where the app wants its vertical origin to be. One advantage of this is that it's possible to consistently get a y=0 eye level coordinate space, which was not possible before. This makes it easier to design simpler experiences that only need to render a floating UI and don't want to render a full environment or deal with offsetting everything relative to a 'floor'. This also makes it easier to implement hybrid VR+flatscreen experiences, because the camera is at y=0 when the headset module is disabled. The opt-in nature of the flag, coupled with the fact that it is consistent across all types of tracking and hardware, is hopefully a more useful design.
2023-06-28 23:38:36 +00:00
extern bool webxr_isSeated(void);
extern void webxr_getDisplayDimensions(uint32_t* width, uint32_t* height);
2020-03-05 06:47:24 +00:00
extern double webxr_getDisplayTime(void);
extern double webxr_getDeltaTime(void);
2020-03-05 06:47:24 +00:00
extern uint32_t webxr_getViewCount(void);
extern bool webxr_getViewPose(uint32_t view, float* position, float* orientation);
extern bool webxr_getViewAngles(uint32_t view, float* left, float* right, float* up, float* down);
extern void webxr_getClipDistance(float* near, float* far);
extern void webxr_setClipDistance(float near, float far);
extern void webxr_getBoundsDimensions(float* width, float* depth);
extern const float* webxr_getBoundsGeometry(uint32_t* count);
extern bool webxr_getPose(Device device, float* position, float* orientation);
extern bool webxr_getVelocity(Device device, float* velocity, float* angularVelocity);
extern bool webxr_isDown(Device device, DeviceButton button, bool* down, bool* changed);
extern bool webxr_isTouched(Device device, DeviceButton button, bool* touched);
extern bool webxr_getAxis(Device device, DeviceAxis axis, float* value);
extern bool webxr_getSkeleton(Device device, float* poses);
2020-03-05 06:47:24 +00:00
extern bool webxr_vibrate(Device device, float strength, float duration, float frequency);
2023-06-28 03:45:44 +00:00
extern void webxr_stopVibration(Device device);
extern struct ModelData* webxr_newModelData(Device device, bool animated);
extern bool webxr_animate(struct Model* model);
2020-03-05 06:47:24 +00:00
extern void webxr_renderTo(void (*callback)(void*), void* userdata);
2022-03-23 02:43:00 +00:00
extern bool webxr_isFocused(void);
extern bool webxr_isPassthroughEnabled(void);
extern bool webxr_setPassthroughEnabled(bool enable);
extern double webxr_update(void);
2020-03-05 06:47:24 +00:00
static bool webxrAttached = false;
static HeadsetInterface* previousHeadsetDriver;
2023-04-26 04:45:30 +00:00
void webxr_attach(void) {
2022-03-23 20:11:16 +00:00
if (webxrAttached || lovrHeadsetInterface == &lovrHeadsetWebXRDriver) {
return;
}
2022-03-23 20:11:16 +00:00
previousHeadsetDriver = lovrHeadsetInterface;
lovrHeadsetInterface = &lovrHeadsetWebXRDriver;
webxrAttached = true;
}
2023-04-26 04:45:30 +00:00
void webxr_detach(void) {
if (!webxrAttached) {
return;
}
2022-03-23 20:11:16 +00:00
lovrHeadsetInterface = previousHeadsetDriver;
previousHeadsetDriver = NULL;
webxrAttached = false;
}
2020-03-05 06:47:24 +00:00
HeadsetInterface lovrHeadsetWebXRDriver = {
2020-08-16 06:31:20 +00:00
.driverType = DRIVER_WEBXR,
2020-03-05 06:47:24 +00:00
.init = webxr_init,
.start = webxr_start,
2020-03-05 06:47:24 +00:00
.destroy = webxr_destroy,
.getDriverName = webxr_getDriverName,
2020-03-05 06:47:24 +00:00
.getName = webxr_getName,
Replace HeadsetOrigin with 'seated' flag; Origin type used to be a query-able property of the VR system that indicated whether the tracking was roomscale or seated-scale. The t.headset.offset config value could be used to design an origin-agnostic experience, which by default shifted content up 1.7 meters when tracking was seated-scale. That way, stuff rendered at y=1.7m was always at "eye level". It worked pretty well. It's getting replaced with a t.headset.seated flag. - If seated is false (the default), the origin of the coordinate space will be on the floor, enabling the y=1.7m eye level paradigm. If tracking is not roomscale, a floor offset of 1.7m will be emulated. - If seated is true, the origin of the coordinate space will be y=0 at eye level (where the headset was when the app started). This is the case on both roomscale and seated-scale tracking. So basically 'seated' is an opt-in preference for where the app wants its vertical origin to be. One advantage of this is that it's possible to consistently get a y=0 eye level coordinate space, which was not possible before. This makes it easier to design simpler experiences that only need to render a floating UI and don't want to render a full environment or deal with offsetting everything relative to a 'floor'. This also makes it easier to implement hybrid VR+flatscreen experiences, because the camera is at y=0 when the headset module is disabled. The opt-in nature of the flag, coupled with the fact that it is consistent across all types of tracking and hardware, is hopefully a more useful design.
2023-06-28 23:38:36 +00:00
.isSeated = webxr_isSeated,
2020-03-05 06:47:24 +00:00
.getDisplayTime = webxr_getDisplayTime,
.getDisplayDimensions = webxr_getDisplayDimensions,
.getViewCount = webxr_getViewCount,
.getViewPose = webxr_getViewPose,
.getViewAngles = webxr_getViewAngles,
.getClipDistance = webxr_getClipDistance,
.setClipDistance = webxr_setClipDistance,
.getBoundsDimensions = webxr_getBoundsDimensions,
.getBoundsGeometry = webxr_getBoundsGeometry,
.getPose = webxr_getPose,
.getVelocity = webxr_getVelocity,
.isDown = webxr_isDown,
.isTouched = webxr_isTouched,
.getAxis = webxr_getAxis,
.getSkeleton = webxr_getSkeleton,
2020-03-05 06:47:24 +00:00
.vibrate = webxr_vibrate,
2023-06-28 03:45:44 +00:00
.stopVibration = webxr_stopVibration,
2020-03-05 06:47:24 +00:00
.newModelData = webxr_newModelData,
.animate = webxr_animate,
2022-03-23 02:43:00 +00:00
.isFocused = webxr_isFocused,
2020-03-05 06:47:24 +00:00
.update = webxr_update
};