Cocoa: Made axis auto-calibration less jumpy

This commit is contained in:
Camilla Löwy 2017-03-23 17:30:39 +01:00
parent 55d0560746
commit cf2eab5b4e

View File

@ -338,18 +338,21 @@ int _glfwPlatformPollJoystick(int jid, int mode)
_GLFWjoyelementNS* axis = (_GLFWjoyelementNS*) _GLFWjoyelementNS* axis = (_GLFWjoyelementNS*)
CFArrayGetValueAtIndex(js->ns.axes, i); CFArrayGetValueAtIndex(js->ns.axes, i);
const long value = getElementValue(js, axis); const long raw = getElementValue(js, axis);
// Perform auto calibration // Perform auto calibration
if (value < axis->minimum) if (raw < axis->minimum)
axis->minimum = value; axis->minimum = raw;
if (value > axis->maximum) if (raw > axis->maximum)
axis->maximum = value; axis->maximum = raw;
const long delta = axis->maximum - axis->minimum; const long delta = axis->maximum - axis->minimum;
if (delta == 0) if (delta == 0)
_glfwInputJoystickAxis(jid, i, value); _glfwInputJoystickAxis(jid, i, 0.f);
else 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) else if (mode == _GLFW_POLL_BUTTONS)