mirror of https://github.com/bjornbytes/lovr.git
Controller basics;
This commit is contained in:
parent
814b62c323
commit
58a2d60ef7
|
@ -51,6 +51,10 @@ void lovrHeadsetGetAngularVelocity(float* x, float* y, float* z) {
|
||||||
headset->interface->getAngularVelocity(headset, x, y, z);
|
headset->interface->getAngularVelocity(headset, x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Controller* lovrHeadsetGetController(ControllerHand hand) {
|
||||||
|
return headset->interface->getController(headset, hand);
|
||||||
|
}
|
||||||
|
|
||||||
void lovrHeadsetRenderTo(headsetRenderCallback callback, void* userdata) {
|
void lovrHeadsetRenderTo(headsetRenderCallback callback, void* userdata) {
|
||||||
headset->interface->renderTo(headset, callback, userdata);
|
headset->interface->renderTo(headset, callback, userdata);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,15 @@
|
||||||
#define LOVR_HEADSET_TYPES
|
#define LOVR_HEADSET_TYPES
|
||||||
typedef void (*headsetRenderCallback)(int eyeIndex, void* userdata);
|
typedef void (*headsetRenderCallback)(int eyeIndex, void* userdata);
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
CONTROLLER_HAND_LEFT,
|
||||||
|
CONTROLLER_HAND_RIGHT
|
||||||
|
} ControllerHand;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
ControllerHand hand;
|
||||||
|
} Controller;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int (*isPresent)(void* headset);
|
int (*isPresent)(void* headset);
|
||||||
const char* (*getType)(void* headset);
|
const char* (*getType)(void* headset);
|
||||||
|
@ -14,6 +23,7 @@ typedef struct {
|
||||||
void (*getOrientation)(void* headset, float* x, float* y, float* z, float* w);
|
void (*getOrientation)(void* headset, float* x, float* y, float* z, float* w);
|
||||||
void (*getVelocity)(void* headset, float* x, float* y, float* z);
|
void (*getVelocity)(void* headset, float* x, float* y, float* z);
|
||||||
void (*getAngularVelocity)(void* headset, float* x, float* y, float* z);
|
void (*getAngularVelocity)(void* headset, float* x, float* y, float* z);
|
||||||
|
Controller* (*getController)(void* headset, ControllerHand hand);
|
||||||
void (*renderTo)(void* headset, headsetRenderCallback callback, void* userdata);
|
void (*renderTo)(void* headset, headsetRenderCallback callback, void* userdata);
|
||||||
} HeadsetInterface;
|
} HeadsetInterface;
|
||||||
|
|
||||||
|
@ -35,4 +45,5 @@ void lovrHeadsetGetPosition(float* x, float* y, float* z);
|
||||||
void lovrHeadsetGetOrientation(float* x, float* y, float* z, float* w);
|
void lovrHeadsetGetOrientation(float* x, float* y, float* z, float* w);
|
||||||
void lovrHeadsetGetVelocity(float* x, float* y, float* z);
|
void lovrHeadsetGetVelocity(float* x, float* y, float* z);
|
||||||
void lovrHeadsetGetAngularVelocity(float* x, float* y, float* z);
|
void lovrHeadsetGetAngularVelocity(float* x, float* y, float* z);
|
||||||
|
Controller* lovrHeadsetGetController(ControllerHand hand);
|
||||||
void lovrHeadsetRenderTo(headsetRenderCallback callback, void* userdata);
|
void lovrHeadsetRenderTo(headsetRenderCallback callback, void* userdata);
|
||||||
|
|
|
@ -9,7 +9,10 @@ typedef struct {
|
||||||
struct VR_IVRCompositor_FnTable* vrCompositor;
|
struct VR_IVRCompositor_FnTable* vrCompositor;
|
||||||
struct VR_IVRChaperone_FnTable* vrChaperone;
|
struct VR_IVRChaperone_FnTable* vrChaperone;
|
||||||
|
|
||||||
unsigned int deviceIndex;
|
unsigned int headsetIndex;
|
||||||
|
unsigned int controllerIndex[CONTROLLER_HAND_RIGHT + 1];
|
||||||
|
|
||||||
|
Controller* controllers[CONTROLLER_HAND_RIGHT + 1];
|
||||||
|
|
||||||
float clipNear;
|
float clipNear;
|
||||||
float clipFar;
|
float clipFar;
|
||||||
|
@ -36,6 +39,7 @@ static HeadsetInterface interface = {
|
||||||
.getOrientation = viveGetOrientation,
|
.getOrientation = viveGetOrientation,
|
||||||
.getVelocity = viveGetVelocity,
|
.getVelocity = viveGetVelocity,
|
||||||
.getAngularVelocity = viveGetAngularVelocity,
|
.getAngularVelocity = viveGetAngularVelocity,
|
||||||
|
.getController = viveGetController,
|
||||||
.renderTo = viveRenderTo
|
.renderTo = viveRenderTo
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -83,11 +87,21 @@ Headset* viveInit() {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
state->deviceIndex = k_unTrackedDeviceIndex_Hmd;
|
state->headsetIndex = k_unTrackedDeviceIndex_Hmd;
|
||||||
state->clipNear = 0.1f;
|
state->clipNear = 0.1f;
|
||||||
state->clipFar = 30.f;
|
state->clipFar = 30.f;
|
||||||
state->vrSystem->GetRecommendedRenderTargetSize(&state->renderWidth, &state->renderHeight);
|
state->vrSystem->GetRecommendedRenderTargetSize(&state->renderWidth, &state->renderHeight);
|
||||||
|
|
||||||
|
Controller* leftController = malloc(sizeof(Controller));
|
||||||
|
leftController->hand = CONTROLLER_HAND_LEFT;
|
||||||
|
state->controllers[CONTROLLER_HAND_LEFT] = leftController;
|
||||||
|
state->controllerIndex[CONTROLLER_HAND_LEFT] = state->vrSystem->GetTrackedDeviceIndexForControllerRole(ETrackedControllerRole_TrackedControllerRole_LeftHand);
|
||||||
|
|
||||||
|
Controller* rightController = malloc(sizeof(Controller));
|
||||||
|
rightController->hand = CONTROLLER_HAND_RIGHT;
|
||||||
|
state->controllers[CONTROLLER_HAND_RIGHT] = rightController;
|
||||||
|
state->controllerIndex[CONTROLLER_HAND_RIGHT] = state->vrSystem->GetTrackedDeviceIndexForControllerRole(ETrackedControllerRole_TrackedControllerRole_RightHand);
|
||||||
|
|
||||||
glGenFramebuffers(1, &state->framebuffer);
|
glGenFramebuffers(1, &state->framebuffer);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, state->framebuffer);
|
glBindFramebuffer(GL_FRAMEBUFFER, state->framebuffer);
|
||||||
|
|
||||||
|
@ -123,8 +137,7 @@ Headset* viveInit() {
|
||||||
int viveIsPresent(void* headset) {
|
int viveIsPresent(void* headset) {
|
||||||
Headset* this = (Headset*) headset;
|
Headset* this = (Headset*) headset;
|
||||||
ViveState* state = this->state;
|
ViveState* state = this->state;
|
||||||
|
return (int) state->vrSystem->IsTrackedDeviceConnected(state->headsetIndex);
|
||||||
return (int) state->vrSystem->IsTrackedDeviceConnected(state->deviceIndex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* viveGetType(void* headset) {
|
const char* viveGetType(void* headset) {
|
||||||
|
@ -225,6 +238,12 @@ void viveGetAngularVelocity(void* headset, float* x, float* y, float* z) {
|
||||||
*z = pose.vAngularVelocity.v[2];
|
*z = pose.vAngularVelocity.v[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Controller* viveGetController(void* headset, ControllerHand hand) {
|
||||||
|
Headset* this = headset;
|
||||||
|
ViveState* state = this->state;
|
||||||
|
return state->controllers[hand];
|
||||||
|
}
|
||||||
|
|
||||||
void viveRenderTo(void* headset, headsetRenderCallback callback, void* userdata) {
|
void viveRenderTo(void* headset, headsetRenderCallback callback, void* userdata) {
|
||||||
Headset* this = headset;
|
Headset* this = headset;
|
||||||
ViveState* state = this->state;
|
ViveState* state = this->state;
|
||||||
|
|
|
@ -14,4 +14,5 @@ void viveGetPosition(void* headset, float* x, float* y, float* z);
|
||||||
void viveGetOrientation(void* headset, float* x, float* y, float* z, float* w);
|
void viveGetOrientation(void* headset, float* x, float* y, float* z, float* w);
|
||||||
void viveGetVelocity(void* headset, float* x, float* y, float* z);
|
void viveGetVelocity(void* headset, float* x, float* y, float* z);
|
||||||
void viveGetAngularVelocity(void* headset, float* x, float* y, float* z);
|
void viveGetAngularVelocity(void* headset, float* x, float* y, float* z);
|
||||||
|
Controller* viveGetController(void* headset, ControllerHand hand);
|
||||||
void viveRenderTo(void* headset, headsetRenderCallback callback, void* userdata);
|
void viveRenderTo(void* headset, headsetRenderCallback callback, void* userdata);
|
||||||
|
|
Loading…
Reference in New Issue