This commit is contained in:
Camilla Berglund 2014-10-13 18:51:47 +02:00
parent 2d13eb0920
commit 6a3779d635

View File

@ -34,9 +34,9 @@
////// GLFW internal API ////// ////// GLFW internal API //////
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// Calculate normalized joystick position // Convert axis value to the [-1,1] range
// //
static float calcJoystickPos(DWORD pos, DWORD min, DWORD max) static float normalizeAxis(DWORD pos, DWORD min, DWORD max)
{ {
float fpos = (float) pos; float fpos = (float) pos;
float fmin = (float) min; float fmin = (float) min;
@ -96,20 +96,20 @@ const float* _glfwPlatformGetJoystickAxes(int joy, int* count)
if (_glfw_joyGetPosEx(joy, &ji) != JOYERR_NOERROR) if (_glfw_joyGetPosEx(joy, &ji) != JOYERR_NOERROR)
return NULL; return NULL;
axes[(*count)++] = calcJoystickPos(ji.dwXpos, jc.wXmin, jc.wXmax); axes[(*count)++] = normalizeAxis(ji.dwXpos, jc.wXmin, jc.wXmax);
axes[(*count)++] = calcJoystickPos(ji.dwYpos, jc.wYmin, jc.wYmax); axes[(*count)++] = normalizeAxis(ji.dwYpos, jc.wYmin, jc.wYmax);
if (jc.wCaps & JOYCAPS_HASZ) if (jc.wCaps & JOYCAPS_HASZ)
axes[(*count)++] = calcJoystickPos(ji.dwZpos, jc.wZmin, jc.wZmax); axes[(*count)++] = normalizeAxis(ji.dwZpos, jc.wZmin, jc.wZmax);
if (jc.wCaps & JOYCAPS_HASR) if (jc.wCaps & JOYCAPS_HASR)
axes[(*count)++] = calcJoystickPos(ji.dwRpos, jc.wRmin, jc.wRmax); axes[(*count)++] = normalizeAxis(ji.dwRpos, jc.wRmin, jc.wRmax);
if (jc.wCaps & JOYCAPS_HASU) if (jc.wCaps & JOYCAPS_HASU)
axes[(*count)++] = calcJoystickPos(ji.dwUpos, jc.wUmin, jc.wUmax); axes[(*count)++] = normalizeAxis(ji.dwUpos, jc.wUmin, jc.wUmax);
if (jc.wCaps & JOYCAPS_HASV) if (jc.wCaps & JOYCAPS_HASV)
axes[(*count)++] = calcJoystickPos(ji.dwVpos, jc.wVmin, jc.wVmax); axes[(*count)++] = normalizeAxis(ji.dwVpos, jc.wVmin, jc.wVmax);
return axes; return axes;
} }