2016-11-19 09:28:01 +00:00
|
|
|
#include "headset/headset.h"
|
2016-12-01 07:03:58 +00:00
|
|
|
#include "event/event.h"
|
2016-08-11 04:17:14 +00:00
|
|
|
|
2017-10-22 23:44:26 +00:00
|
|
|
static HeadsetInterface* headset = NULL;
|
2018-02-23 09:28:42 +00:00
|
|
|
static bool initialized = false;
|
2017-10-20 20:32:46 +00:00
|
|
|
|
2018-03-05 04:43:42 +00:00
|
|
|
void lovrHeadsetInit(HeadsetDriver* drivers, int count, float offset) {
|
2018-02-23 09:28:42 +00:00
|
|
|
if (initialized) return;
|
|
|
|
initialized = true;
|
2018-02-24 04:01:13 +00:00
|
|
|
headset = NULL;
|
2018-02-23 09:28:42 +00:00
|
|
|
|
2017-11-25 21:01:56 +00:00
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
HeadsetInterface* interface = NULL;
|
|
|
|
|
|
|
|
switch (drivers[i]) {
|
|
|
|
case DRIVER_FAKE: interface = &lovrHeadsetFakeDriver; break;
|
|
|
|
#ifndef EMSCRIPTEN
|
|
|
|
case DRIVER_OPENVR: interface = &lovrHeadsetOpenVRDriver; break;
|
2017-10-21 09:52:07 +00:00
|
|
|
#else
|
2017-11-25 21:01:56 +00:00
|
|
|
case DRIVER_WEBVR: interface = &lovrHeadsetWebVRDriver; break;
|
2017-10-21 09:52:07 +00:00
|
|
|
#endif
|
2017-11-25 21:01:56 +00:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
2018-03-05 04:43:42 +00:00
|
|
|
if (interface && interface->init(offset)) {
|
2017-11-25 21:01:56 +00:00
|
|
|
headset = interface;
|
2017-10-20 20:32:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void lovrHeadsetDestroy() {
|
2018-02-23 09:28:42 +00:00
|
|
|
if (!initialized) return;
|
|
|
|
initialized = false;
|
|
|
|
|
2017-10-20 20:32:46 +00:00
|
|
|
if (headset) {
|
|
|
|
headset->destroy();
|
2017-11-25 20:14:00 +00:00
|
|
|
headset = NULL;
|
2017-10-20 20:32:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-25 21:01:56 +00:00
|
|
|
const HeadsetDriver* lovrHeadsetGetDriver() {
|
|
|
|
if (!headset) {
|
|
|
|
lovrThrow("Headset is not initialized");
|
|
|
|
}
|
|
|
|
|
|
|
|
return &headset->driverType;
|
|
|
|
}
|
|
|
|
|
2017-10-20 20:32:46 +00:00
|
|
|
HeadsetType lovrHeadsetGetType() {
|
|
|
|
return headset ? headset->getType() : HEADSET_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
HeadsetOrigin lovrHeadsetGetOriginType() {
|
|
|
|
return headset ? headset->getOriginType() : ORIGIN_HEAD;
|
|
|
|
}
|
|
|
|
|
2018-02-26 00:40:48 +00:00
|
|
|
bool lovrHeadsetIsMounted() {
|
|
|
|
return headset ? headset->isMounted() : false;
|
|
|
|
}
|
|
|
|
|
2017-10-31 08:14:09 +00:00
|
|
|
bool lovrHeadsetIsMirrored() {
|
|
|
|
return headset ? headset->isMirrored() : false;
|
2017-10-20 20:32:46 +00:00
|
|
|
}
|
|
|
|
|
2017-10-31 08:14:09 +00:00
|
|
|
void lovrHeadsetSetMirrored(bool mirror) {
|
2017-10-20 20:32:46 +00:00
|
|
|
if (headset) {
|
|
|
|
headset->setMirrored(mirror);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void lovrHeadsetGetDisplayDimensions(int* width, int* height) {
|
|
|
|
if (!headset) {
|
|
|
|
*width = *height = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
headset->getDisplayDimensions(width, height);
|
|
|
|
}
|
|
|
|
|
2018-02-23 05:01:34 +00:00
|
|
|
void lovrHeadsetGetClipDistance(float* clipNear, float* clipFar) {
|
2017-10-20 20:32:46 +00:00
|
|
|
if (!headset) {
|
2018-02-23 05:01:34 +00:00
|
|
|
*clipNear = *clipFar = 0.f;
|
2017-10-20 20:32:46 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-02-23 05:01:34 +00:00
|
|
|
headset->getClipDistance(clipNear, clipFar);
|
2017-10-20 20:32:46 +00:00
|
|
|
}
|
|
|
|
|
2018-02-23 05:01:34 +00:00
|
|
|
void lovrHeadsetSetClipDistance(float clipNear, float clipFar) {
|
2017-10-20 20:32:46 +00:00
|
|
|
if (headset) {
|
2018-02-23 05:01:34 +00:00
|
|
|
headset->setClipDistance(clipNear, clipFar);
|
2017-10-20 20:32:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
float lovrHeadsetGetBoundsWidth() {
|
2017-11-25 20:14:00 +00:00
|
|
|
return headset ? headset->getBoundsWidth() : 0.f;
|
2017-10-20 20:32:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float lovrHeadsetGetBoundsDepth() {
|
2017-11-25 20:14:00 +00:00
|
|
|
return headset ? headset->getBoundsDepth() : 0.f;
|
2017-10-20 20:32:46 +00:00
|
|
|
}
|
|
|
|
|
2017-12-18 06:13:58 +00:00
|
|
|
void lovrHeadsetGetPose(float* x, float* y, float* z, float* angle, float* ax, float* ay, float* az) {
|
2017-10-20 20:32:46 +00:00
|
|
|
if (!headset) {
|
2017-12-18 06:13:58 +00:00
|
|
|
*x = *y = *z = *angle = *ax = *ay = *az = 0.f;
|
2017-10-20 20:32:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-18 06:13:58 +00:00
|
|
|
headset->getPose(x, y, z, angle, ax, ay, az);
|
2017-10-20 20:32:46 +00:00
|
|
|
}
|
|
|
|
|
2017-12-18 06:13:58 +00:00
|
|
|
void lovrHeadsetGetEyePose(HeadsetEye eye, float* x, float* y, float* z, float* angle, float* ax, float* ay, float* az) {
|
2017-10-20 20:32:46 +00:00
|
|
|
if (!headset) {
|
2017-12-18 06:13:58 +00:00
|
|
|
*x = *y = *z = *angle = *ax = *ay = *az = 0.f;
|
2017-10-20 20:32:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-18 06:13:58 +00:00
|
|
|
headset->getEyePose(eye, x, y, z, angle, ax, ay, az);
|
2017-10-20 20:32:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void lovrHeadsetGetVelocity(float* x, float* y, float* z) {
|
|
|
|
if (!headset) {
|
|
|
|
*x = *y = *z = 0.f;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
headset->getVelocity(x,y,z);
|
|
|
|
}
|
|
|
|
|
|
|
|
void lovrHeadsetGetAngularVelocity(float* x, float* y, float* z) {
|
|
|
|
if (!headset) {
|
|
|
|
*x = *y = *z = 0.f;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
headset->getAngularVelocity(x,y,z);
|
|
|
|
}
|
|
|
|
|
|
|
|
vec_controller_t* lovrHeadsetGetControllers() {
|
|
|
|
if (!headset) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return headset->getControllers();
|
|
|
|
}
|
|
|
|
|
2018-02-26 00:40:48 +00:00
|
|
|
bool lovrHeadsetControllerIsConnected(Controller* controller) {
|
2017-10-20 20:32:46 +00:00
|
|
|
if (!headset || !controller) {
|
2017-10-31 08:14:09 +00:00
|
|
|
return false;
|
2017-10-20 20:32:46 +00:00
|
|
|
}
|
|
|
|
|
2018-02-26 00:40:48 +00:00
|
|
|
return headset->controllerIsConnected(controller);
|
2017-10-20 20:32:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ControllerHand lovrHeadsetControllerGetHand(Controller* controller) {
|
|
|
|
return headset ? headset->controllerGetHand(controller) : HAND_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2017-12-18 06:13:58 +00:00
|
|
|
void lovrHeadsetControllerGetPose(Controller* controller, float* x, float* y, float* z, float* angle, float* ax, float* ay, float* az) {
|
2017-10-20 20:32:46 +00:00
|
|
|
if (!headset || !controller) {
|
2017-12-18 06:13:58 +00:00
|
|
|
*x = *y = *z = *angle = *ax = *ay = *az = 0.f;
|
2017-10-20 20:32:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-18 06:13:58 +00:00
|
|
|
headset->controllerGetPose(controller, x, y, z, angle, ax, ay, az);
|
2017-10-20 20:32:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float lovrHeadsetControllerGetAxis(Controller* controller, ControllerAxis axis) {
|
|
|
|
if (!headset || !controller) {
|
|
|
|
return 0.f;
|
|
|
|
}
|
|
|
|
|
|
|
|
return headset->controllerGetAxis(controller, axis);
|
|
|
|
}
|
|
|
|
|
2017-10-31 08:14:09 +00:00
|
|
|
bool lovrHeadsetControllerIsDown(Controller* controller, ControllerButton button) {
|
2017-10-20 20:32:46 +00:00
|
|
|
if (!headset || !controller) {
|
2017-10-31 08:14:09 +00:00
|
|
|
return false;
|
2017-10-20 20:32:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return headset->controllerIsDown(controller, button);
|
|
|
|
}
|
|
|
|
|
2017-10-31 08:14:09 +00:00
|
|
|
bool lovrHeadsetControllerIsTouched(Controller* controller, ControllerButton button) {
|
|
|
|
return (headset && controller) ? headset->controllerIsTouched(controller,button) : false;
|
2017-10-20 20:32:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void lovrHeadsetControllerVibrate(Controller* controller, float duration, float power) {
|
|
|
|
if (!headset || !controller) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
headset->controllerVibrate(controller, duration, power);
|
|
|
|
}
|
|
|
|
|
2017-11-25 20:14:00 +00:00
|
|
|
ModelData* lovrHeadsetControllerNewModelData(Controller* controller) {
|
|
|
|
if (headset && controller) {
|
2017-10-20 20:32:46 +00:00
|
|
|
return headset->controllerNewModelData(controller);
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-11 07:42:33 +00:00
|
|
|
void lovrHeadsetRenderTo(void (*callback)(void*), void* userdata) {
|
2017-10-20 20:32:46 +00:00
|
|
|
if (headset) {
|
|
|
|
headset->renderTo(callback, userdata);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void lovrHeadsetUpdate(float dt) {
|
2018-02-24 04:01:13 +00:00
|
|
|
if (headset && headset->update) {
|
2017-10-20 20:32:46 +00:00
|
|
|
headset->update(dt);
|
|
|
|
}
|
|
|
|
}
|