浏览代码

Fix half-axis to gamepad button value mapping

Negative half-axes were not negated when mapped onto gamepad buttons.
Camilla Löwy 6 年之前
父节点
当前提交
c32dc3a085
共有 1 个文件被更改,包括 12 次插入2 次删除
  1. 12 2
      src/input.c

+ 12 - 2
src/input.c

@@ -1258,8 +1258,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)
         {