From 1127abeaf0e88fcf9b549cabc23cb48729c37022 Mon Sep 17 00:00:00 2001 From: Ben Campbell Date: Sun, 29 Oct 2017 09:33:54 +1300 Subject: [PATCH 1/2] fake controller events (left mouse for trigger) --- src/headset/fake.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/headset/fake.c b/src/headset/fake.c index 29839c78..78e8f80a 100644 --- a/src/headset/fake.c +++ b/src/headset/fake.c @@ -118,13 +118,43 @@ static void cursor_position_callback(GLFWwindow* window, double xpos, double ypo } + static void mouse_button_callback(GLFWwindow* window, int button, int action, int mods) { + + // clicking in window grabs mouse if (!state.mouselook) { if (button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_PRESS) { enableMouselook(window); } } + + // now generate events on fake controllers + { + Event ev; + Controller* controller; + int i; + switch (action) { + case GLFW_PRESS: + ev.type = EVENT_CONTROLLER_PRESSED; + break; + case GLFW_RELEASE: + ev.type = EVENT_CONTROLLER_RELEASED; + break; + default: + return; + } + + vec_foreach(&state.controllers, controller, i) { + if (controller->id == 0) { + if (button == GLFW_MOUSE_BUTTON_LEFT) { + ev.data.controllerpressed.controller = controller; + ev.data.controllerpressed.button = CONTROLLER_BUTTON_TRIGGER; + lovrEventPush(ev); + } + } + } + } } // headset can start up without a window, so we poll window existance here From 9d75de96a2947ccdc02c1ce628044149cbf7ad07 Mon Sep 17 00:00:00 2001 From: Ben Campbell Date: Sun, 29 Oct 2017 10:42:20 +1300 Subject: [PATCH 2/2] fake controller: apply offset --- src/headset/fake.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/headset/fake.c b/src/headset/fake.c index 78e8f80a..a64ddfee 100644 --- a/src/headset/fake.c +++ b/src/headset/fake.c @@ -271,8 +271,8 @@ static HeadsetType fakeGetType() { } static HeadsetOrigin fakeGetOriginType() { - return ORIGIN_HEAD; // seated - //return ORIGIN_FLOOR; // standing + //return ORIGIN_HEAD; // seated + return ORIGIN_FLOOR; // standing } static int fakeIsMirrored() { @@ -366,7 +366,14 @@ static ControllerHand fakeControllerGetHand(Controller* controller) { static void fakeControllerGetPosition(Controller* controller, float* x, float* y, float* z) { // for now, locked to headset - fakeGetPosition(x,y,z); + + float offset[3]; + vec3_set(offset, 0, 0,-1.0f); + + mat4_transform(state.transform, offset); + *x = offset[0]; + *y = offset[1]; + *z = offset[2]; } static void fakeControllerGetOrientation(Controller* controller, float* angle, float* x, float* y, float* z) {