1
0
Fork 0
mirror of https://github.com/bjornbytes/lovr.git synced 2024-07-22 13:43:35 +00:00
lovr/src/headset/headset.c

216 lines
4.2 KiB
C
Raw Normal View History

2016-11-19 09:28:01 +00:00
#include "headset/headset.h"
#include "headset/vive.h"
2016-12-01 07:03:58 +00:00
#include "event/event.h"
2016-08-11 04:17:14 +00:00
2016-09-17 04:37:30 +00:00
static Headset* headset;
2016-08-11 04:17:14 +00:00
void lovrHeadsetInit() {
2016-09-17 04:37:30 +00:00
headset = viveInit();
2016-12-01 07:03:58 +00:00
if (headset) {
lovrEventAddPump(lovrHeadsetPoll);
}
}
void lovrHeadsetPoll() {
headset->poll(headset);
2016-08-11 04:17:14 +00:00
}
2016-10-03 18:40:20 +00:00
char lovrHeadsetIsPresent() {
if (!headset) {
return 0;
}
2016-11-26 10:32:19 +00:00
return headset->isPresent(headset);
2016-10-01 21:12:55 +00:00
}
const char* lovrHeadsetGetType() {
2016-12-02 01:06:27 +00:00
if (!headset) {
return NULL;
}
2016-11-26 10:32:19 +00:00
return headset->getType(headset);
2016-09-27 06:48:09 +00:00
}
2016-10-24 23:03:29 +00:00
void lovrHeadsetGetDisplayDimensions(int* width, int* height) {
2016-12-02 01:06:27 +00:00
if (!headset) {
*width = *height = 0;
return;
}
2016-11-26 10:32:19 +00:00
headset->getDisplayDimensions(headset, width, height);
2016-10-24 23:03:29 +00:00
}
2016-09-27 06:48:09 +00:00
void lovrHeadsetGetClipDistance(float* near, float* far) {
2016-12-02 01:06:27 +00:00
if (!headset) {
*near = *far = 0.f;
return;
}
2016-11-26 10:32:19 +00:00
headset->getClipDistance(headset, near, far);
2016-08-11 04:17:14 +00:00
}
2016-10-01 21:12:55 +00:00
void lovrHeadsetSetClipDistance(float near, float far) {
2016-12-02 01:06:27 +00:00
if (!headset) {
return;
}
2016-11-26 10:32:19 +00:00
headset->setClipDistance(headset, near, far);
2016-09-16 06:57:01 +00:00
}
float lovrHeadsetGetBoundsWidth() {
2016-12-02 01:06:27 +00:00
if (!headset) {
return 0.f;
}
2016-11-26 10:32:19 +00:00
return headset->getBoundsWidth(headset);
}
float lovrHeadsetGetBoundsDepth() {
2016-12-02 01:06:27 +00:00
if (!headset) {
return 0.f;
}
2016-11-26 10:32:19 +00:00
return headset->getBoundsDepth(headset);
}
void lovrHeadsetGetBoundsGeometry(float* geometry) {
2016-12-02 01:06:27 +00:00
if (!headset) {
*geometry = 0.f;
return;
}
2016-11-26 10:32:19 +00:00
headset->getBoundsGeometry(headset, geometry);
2016-10-01 21:17:26 +00:00
}
2016-10-01 22:11:45 +00:00
char lovrHeadsetIsBoundsVisible() {
2016-12-02 01:06:27 +00:00
if (!headset) {
return 0;
}
2016-11-26 10:32:19 +00:00
return headset->isBoundsVisible(headset);
2016-10-01 22:11:45 +00:00
}
void lovrHeadsetSetBoundsVisible(char visible) {
2016-12-02 01:06:27 +00:00
if (!headset) {
return;
}
2016-11-26 10:32:19 +00:00
headset->setBoundsVisible(headset, visible);
2016-10-01 22:11:45 +00:00
}
2016-09-27 06:48:09 +00:00
void lovrHeadsetGetPosition(float* x, float* y, float* z) {
2016-12-02 01:06:27 +00:00
if (!headset) {
*x = *y = *z = 0.f;
return;
}
2016-11-26 10:32:19 +00:00
headset->getPosition(headset, x, y, z);
2016-09-17 02:43:43 +00:00
}
2016-09-16 06:57:01 +00:00
2016-10-04 00:02:01 +00:00
void lovrHeadsetGetOrientation(float* w, float* x, float* y, float* z) {
2016-12-02 01:06:27 +00:00
if (!headset) {
*w = *x = *y = *z = 0.f;
return;
}
2016-11-26 10:32:19 +00:00
headset->getOrientation(headset, w, x, y, z);
2016-10-01 21:12:55 +00:00
}
2016-09-27 06:48:09 +00:00
void lovrHeadsetGetVelocity(float* x, float* y, float* z) {
2016-12-02 01:06:27 +00:00
if (!headset) {
*x = *y = *z = 0.f;
return;
}
2016-11-26 10:32:19 +00:00
headset->getVelocity(headset, x, y, z);
2016-09-17 02:43:43 +00:00
}
2016-09-16 06:57:01 +00:00
2016-10-01 21:12:55 +00:00
void lovrHeadsetGetAngularVelocity(float* x, float* y, float* z) {
2016-12-02 01:06:27 +00:00
if (!headset) {
*x = *y = *z = 0.f;
return;
}
2016-11-26 10:32:19 +00:00
headset->getAngularVelocity(headset, x, y, z);
2016-09-16 06:57:01 +00:00
}
2016-12-01 07:03:58 +00:00
vec_controller_t* lovrHeadsetGetControllers() {
2016-12-02 01:06:27 +00:00
if (!headset) {
return NULL;
}
2016-12-01 07:03:58 +00:00
return headset->getControllers(headset);
2016-10-03 01:09:33 +00:00
}
2016-11-15 03:47:24 +00:00
char lovrHeadsetControllerIsPresent(Controller* controller) {
2016-12-02 01:06:27 +00:00
if (!headset || !controller) {
return 0;
}
2016-11-26 10:32:19 +00:00
return headset->controllerIsPresent(headset, controller);
2016-10-03 18:12:06 +00:00
}
2016-11-15 03:47:24 +00:00
void lovrHeadsetControllerGetPosition(Controller* controller, float* x, float* y, float* z) {
2016-12-02 01:06:27 +00:00
if (!headset || !controller) {
*x = *y = *z = 0.f;
return;
}
2016-11-26 10:32:19 +00:00
headset->controllerGetPosition(headset, controller, x, y, z);
2016-10-03 18:12:21 +00:00
}
2016-11-15 03:47:24 +00:00
void lovrHeadsetControllerGetOrientation(Controller* controller, float* w, float* x, float* y, float* z) {
2016-12-02 01:06:27 +00:00
if (!headset || !controller) {
*w = *x = *y = *z = 0.f;
return;
}
2016-11-26 10:32:19 +00:00
headset->controllerGetOrientation(headset, controller, w, x, y, z);
2016-10-03 18:16:48 +00:00
}
2016-11-15 03:47:24 +00:00
float lovrHeadsetControllerGetAxis(Controller* controller, ControllerAxis axis) {
2016-12-02 01:06:27 +00:00
if (!headset || !controller) {
return 0.f;
}
2016-11-26 10:32:19 +00:00
return headset->controllerGetAxis(headset, controller, axis);
2016-11-12 11:44:33 +00:00
}
2016-11-15 03:57:23 +00:00
int lovrHeadsetControllerIsDown(Controller* controller, ControllerButton button) {
2016-12-02 01:06:27 +00:00
if (!headset || !controller) {
return 0;
}
2016-11-26 10:32:19 +00:00
return headset->controllerIsDown(headset, controller, button);
2016-11-15 03:57:23 +00:00
}
2016-11-15 03:33:42 +00:00
void lovrHeadsetControllerVibrate(Controller* controller, float duration) {
2016-12-02 01:06:27 +00:00
if (!headset || !controller) {
return;
}
2016-11-26 10:32:19 +00:00
headset->controllerVibrate(headset, controller, duration);
2016-11-15 03:33:42 +00:00
}
2016-11-26 07:32:48 +00:00
void* lovrHeadsetControllerGetModel(Controller* controller, ControllerModelFormat* format) {
2016-12-02 01:06:27 +00:00
if (!headset || !controller) {
return NULL;
}
2016-11-26 10:32:19 +00:00
return headset->controllerGetModel(headset, controller, format);
2016-11-25 09:12:36 +00:00
}
2016-08-11 04:17:14 +00:00
void lovrHeadsetRenderTo(headsetRenderCallback callback, void* userdata) {
2016-12-02 01:06:27 +00:00
if (!headset) {
return;
}
2016-11-26 10:32:19 +00:00
headset->renderTo(headset, callback, userdata);
2016-08-11 04:17:14 +00:00
}
2016-12-01 07:03:58 +00:00
void lovrControllerDestroy(const Ref* ref) {
Controller* controller = containerof(ref, Controller);
free(controller);
}