From e7447f38cf6797eed5a4fbfe763eeee8e9d1dc4a Mon Sep 17 00:00:00 2001 From: Luflosi Date: Sun, 24 May 2020 19:54:45 +0200 Subject: [PATCH 1/2] Fix half-axis to gamepad button value mapping From upstream: https://github.com/glfw/glfw/commit/c32dc3a0856e339d8de582582fcbedec430e14b4. --- glfw/input.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/glfw/input.c b/glfw/input.c index d5121c75f..cd1e3f2c6 100644 --- a/glfw/input.c +++ b/glfw/input.c @@ -1436,8 +1436,18 @@ GLFWAPI int glfwGetGamepadState(int jid, GLFWgamepadstate* state) if (e->type == _GLFW_JOYSTICK_AXIS) { const float value = js->axes[e->index] * e->axisScale + e->axisOffset; - if (value > 0.f) - state->buttons[i] = GLFW_PRESS; + // HACK: This should be baked into the value transform + // TODO: Bake into transform when implementing output modifiers + if (e->axisScale < 0 || e->axisOffset < 0) + { + if (value > 0.f) + state->buttons[i] = GLFW_PRESS; + } + else + { + if (value < 0.f) + state->buttons[i] = GLFW_PRESS; + } } else if (e->type == _GLFW_JOYSTICK_HATBIT) { From fcc7a0255ac4f76ac1a79b37386286686f9603d6 Mon Sep 17 00:00:00 2001 From: Luflosi Date: Mon, 25 May 2020 11:44:14 +0200 Subject: [PATCH 2/2] Align joystick axis to gamepad button behavior From upstream: https://github.com/glfw/glfw/commit/02874d9c148cf549abc403e07856d7531f4fcce6. --- glfw/input.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/glfw/input.c b/glfw/input.c index cd1e3f2c6..a08fd1097 100644 --- a/glfw/input.c +++ b/glfw/input.c @@ -1438,14 +1438,14 @@ GLFWAPI int glfwGetGamepadState(int jid, GLFWgamepadstate* state) const float value = js->axes[e->index] * e->axisScale + e->axisOffset; // HACK: This should be baked into the value transform // TODO: Bake into transform when implementing output modifiers - if (e->axisScale < 0 || e->axisOffset < 0) + if (e->axisOffset < 0 || (e->axisOffset == 0 && e->axisScale > 0)) { - if (value > 0.f) + if (value >= 0.f) state->buttons[i] = GLFW_PRESS; } else { - if (value < 0.f) + if (value <= 0.f) state->buttons[i] = GLFW_PRESS; } }