Controller basics;

This commit is contained in:
bjorn 2016-10-02 18:09:33 -07:00
parent 814b62c323
commit 58a2d60ef7
4 changed files with 39 additions and 4 deletions

View File

@ -51,6 +51,10 @@ void lovrHeadsetGetAngularVelocity(float* x, float* y, float* z) {
headset->interface->getAngularVelocity(headset, x, y, z);
}
Controller* lovrHeadsetGetController(ControllerHand hand) {
return headset->interface->getController(headset, hand);
}
void lovrHeadsetRenderTo(headsetRenderCallback callback, void* userdata) {
headset->interface->renderTo(headset, callback, userdata);
}

View File

@ -2,6 +2,15 @@
#define LOVR_HEADSET_TYPES
typedef void (*headsetRenderCallback)(int eyeIndex, void* userdata);
typedef enum {
CONTROLLER_HAND_LEFT,
CONTROLLER_HAND_RIGHT
} ControllerHand;
typedef struct {
ControllerHand hand;
} Controller;
typedef struct {
int (*isPresent)(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 (*getVelocity)(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);
} HeadsetInterface;
@ -35,4 +45,5 @@ void lovrHeadsetGetPosition(float* x, float* y, float* z);
void lovrHeadsetGetOrientation(float* x, float* y, float* z, float* w);
void lovrHeadsetGetVelocity(float* x, float* y, float* z);
void lovrHeadsetGetAngularVelocity(float* x, float* y, float* z);
Controller* lovrHeadsetGetController(ControllerHand hand);
void lovrHeadsetRenderTo(headsetRenderCallback callback, void* userdata);

View File

@ -9,7 +9,10 @@ typedef struct {
struct VR_IVRCompositor_FnTable* vrCompositor;
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 clipFar;
@ -36,6 +39,7 @@ static HeadsetInterface interface = {
.getOrientation = viveGetOrientation,
.getVelocity = viveGetVelocity,
.getAngularVelocity = viveGetAngularVelocity,
.getController = viveGetController,
.renderTo = viveRenderTo
};
@ -83,11 +87,21 @@ Headset* viveInit() {
return NULL;
}
state->deviceIndex = k_unTrackedDeviceIndex_Hmd;
state->headsetIndex = k_unTrackedDeviceIndex_Hmd;
state->clipNear = 0.1f;
state->clipFar = 30.f;
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);
glBindFramebuffer(GL_FRAMEBUFFER, state->framebuffer);
@ -123,8 +137,7 @@ Headset* viveInit() {
int viveIsPresent(void* headset) {
Headset* this = (Headset*) headset;
ViveState* state = this->state;
return (int) state->vrSystem->IsTrackedDeviceConnected(state->deviceIndex);
return (int) state->vrSystem->IsTrackedDeviceConnected(state->headsetIndex);
}
const char* viveGetType(void* headset) {
@ -225,6 +238,12 @@ void viveGetAngularVelocity(void* headset, float* x, float* y, float* z) {
*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) {
Headset* this = headset;
ViveState* state = this->state;

View File

@ -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 viveGetVelocity(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);