From cf2eab5b4ee2de1808e80a2a49096f011fbd0b82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Thu, 23 Mar 2017 17:30:39 +0100 Subject: [PATCH] Cocoa: Made axis auto-calibration less jumpy --- src/cocoa_joystick.m | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/cocoa_joystick.m b/src/cocoa_joystick.m index 61d85a9f..d1a23035 100644 --- a/src/cocoa_joystick.m +++ b/src/cocoa_joystick.m @@ -338,18 +338,21 @@ int _glfwPlatformPollJoystick(int jid, int mode) _GLFWjoyelementNS* axis = (_GLFWjoyelementNS*) CFArrayGetValueAtIndex(js->ns.axes, i); - const long value = getElementValue(js, axis); + const long raw = getElementValue(js, axis); // Perform auto calibration - if (value < axis->minimum) - axis->minimum = value; - if (value > axis->maximum) - axis->maximum = value; + if (raw < axis->minimum) + axis->minimum = raw; + if (raw > axis->maximum) + axis->maximum = raw; const long delta = axis->maximum - axis->minimum; if (delta == 0) - _glfwInputJoystickAxis(jid, i, value); + _glfwInputJoystickAxis(jid, i, 0.f); else - _glfwInputJoystickAxis(jid, i, (2.f * (value - axis->minimum) / delta) - 1.f); + { + const float value = (2.f * (raw - axis->minimum) / delta) - 1.f; + _glfwInputJoystickAxis(jid, i, value); + } } } else if (mode == _GLFW_POLL_BUTTONS)