1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-23 02:38:52 -05:00

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*)
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)