2017-04-16 23:56:49 +00:00
|
|
|
#include "headset/headset.h"
|
|
|
|
#include "graphics/graphics.h"
|
2017-10-31 08:14:09 +00:00
|
|
|
#include <stdbool.h>
|
2017-04-16 23:56:49 +00:00
|
|
|
|
2018-05-01 22:10:51 +00:00
|
|
|
// Provided by resources/lovr.js
|
2019-05-09 07:46:47 +00:00
|
|
|
extern bool webvr_init(float offset, int msaa);
|
|
|
|
extern void webvr_destroy(void);
|
|
|
|
extern bool webvr_getName(char* name, size_t length);
|
|
|
|
extern HeadsetOrigin webvr_getOriginType(void);
|
|
|
|
extern void webvr_getDisplayDimensions(uint32_t* width, uint32_t* height);
|
|
|
|
extern void webvr_getClipDistance(float* near, float* far);
|
|
|
|
extern void webvr_setClipDistance(float near, float far);
|
|
|
|
extern void webvr_getBoundsDimensions(float* width, float* depth);
|
|
|
|
extern const float* webvr_getBoundsGeometry(int* count);
|
|
|
|
extern bool webvr_getPose(Device device, float* position, float* orientation);
|
|
|
|
extern bool webvr_getBonePose(Device device, DeviceBone bone, float* position, float* orientation);
|
|
|
|
extern bool webvr_getVelocity(Device device, float* velocity, float* angularVelocity);
|
|
|
|
extern bool webvr_getAcceleration(Device device, float* acceleration, float* angularAcceleration);
|
|
|
|
extern bool webvr_isDown(Device device, DeviceButton button, bool* down);
|
|
|
|
extern bool webvr_isTouched(Device device, DeviceButton button, bool* touched);
|
|
|
|
extern bool webvr_getAxis(Device device, DeviceAxis axis, float* value);
|
|
|
|
extern bool webvr_vibrate(Device device, float strength, float duration, float frequency);
|
|
|
|
extern struct ModelData* webvr_newModelData(Device device);
|
|
|
|
extern void webvr_update(float dt);
|
2018-04-29 21:38:08 +00:00
|
|
|
|
2019-05-09 07:46:47 +00:00
|
|
|
static struct {
|
2018-05-23 09:22:56 +00:00
|
|
|
void (*renderCallback)(void*);
|
2019-05-09 07:46:47 +00:00
|
|
|
void* renderData;
|
|
|
|
} state;
|
2017-04-21 03:46:35 +00:00
|
|
|
|
2019-05-09 07:46:47 +00:00
|
|
|
static void webvr_onAnimationFrame(float* leftView, float* rightView, float* leftProjection, float* rightProjection) {
|
2018-08-30 03:57:30 +00:00
|
|
|
Camera camera = { .canvas = NULL, .stereo = true };
|
2018-08-02 10:40:47 +00:00
|
|
|
memcpy(camera.projection[0], leftProjection, 16 * sizeof(float));
|
|
|
|
memcpy(camera.projection[1], rightProjection, 16 * sizeof(float));
|
|
|
|
memcpy(camera.viewMatrix[0], leftView, 16 * sizeof(float));
|
|
|
|
memcpy(camera.viewMatrix[1], rightView, 16 * sizeof(float));
|
2018-07-21 12:30:13 +00:00
|
|
|
lovrGraphicsSetCamera(&camera, true);
|
2019-05-09 07:46:47 +00:00
|
|
|
state.renderCallback(state.renderData);
|
2018-07-17 06:51:11 +00:00
|
|
|
lovrGraphicsSetCamera(NULL, false);
|
2018-05-23 09:22:56 +00:00
|
|
|
}
|
|
|
|
|
2019-05-09 07:46:47 +00:00
|
|
|
void webvr_renderTo(void (*callback)(void*), void* userdata) {
|
2018-05-23 09:22:56 +00:00
|
|
|
state.renderCallback = callback;
|
2019-05-09 07:46:47 +00:00
|
|
|
state.renderData = userdata;
|
2018-05-23 09:22:56 +00:00
|
|
|
}
|
|
|
|
|
2017-10-22 23:44:26 +00:00
|
|
|
HeadsetInterface lovrHeadsetWebVRDriver = {
|
2019-03-20 00:21:16 +00:00
|
|
|
.driverType = DRIVER_WEBVR,
|
2019-05-09 07:46:47 +00:00
|
|
|
.init = webvr_init,
|
|
|
|
.destroy = webvr_destroy,
|
|
|
|
.getName = webvr_getName,
|
|
|
|
.getOriginType = webvr_getOriginType,
|
|
|
|
.getDisplayDimensions = webvr_getDisplayDimensions,
|
|
|
|
.getClipDistance = webvr_getClipDistance,
|
|
|
|
.setClipDistance = webvr_setClipDistance,
|
|
|
|
.getBoundsDimensions = webvr_getBoundsDimensions,
|
|
|
|
.getBoundsGeometry = webvr_getBoundsGeometry,
|
|
|
|
.getPose = webvr_getPose,
|
|
|
|
.getBonePose = webvr_getBonePose,
|
|
|
|
.getVelocity = webvr_getVelocity,
|
|
|
|
.getAcceleration = webvr_getAcceleration,
|
|
|
|
.isDown = webvr_isDown,
|
|
|
|
.isTouched = webvr_isTouched,
|
|
|
|
.getAxis = webvr_getAxis,
|
|
|
|
.vibrate = webvr_vibrate,
|
|
|
|
.newModelData = webvr_newModelData,
|
|
|
|
.renderTo = webvr_renderTo,
|
|
|
|
.update = webvr_update
|
2017-10-21 09:52:07 +00:00
|
|
|
};
|