Gamepad axis bug fixes and improvement (#1228)
* Fix gamepad axis count
* Fix Xbox axis drawing
* Ignore low axis values
* Revert "Fix gamepad axis count"
This reverts commit f08ae4bf
* Fix GamepadAxis API
* Fix conflict with master
* Revert Gamepad MAX definitions
* Revert MAX_GAMEPAD_AXIS update
This commit is contained in:
parent
7efed56b66
commit
0bd64b7975
3 changed files with 14 additions and 52 deletions
47
src/core.c
47
src/core.c
|
@ -496,7 +496,6 @@ static void InitTimer(void); // Initialize timer
|
|||
static void Wait(float ms); // Wait for some milliseconds (stop program execution)
|
||||
|
||||
static int GetGamepadButton(int button); // Get gamepad button generic to all platforms
|
||||
static int GetGamepadAxis(int axis); // Get gamepad axis generic to all platforms
|
||||
static void PollInputEvents(void); // Register user events
|
||||
|
||||
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
|
||||
|
@ -2509,7 +2508,9 @@ float GetGamepadAxisMovement(int gamepad, int axis)
|
|||
float value = 0;
|
||||
|
||||
#if !defined(PLATFORM_ANDROID)
|
||||
if ((gamepad < MAX_GAMEPADS) && CORE.Input.Gamepad.ready[gamepad] && (axis < MAX_GAMEPAD_AXIS)) value = CORE.Input.Gamepad.axisState[gamepad][axis];
|
||||
if ((gamepad < MAX_GAMEPADS) && CORE.Input.Gamepad.ready[gamepad] && (axis < MAX_GAMEPAD_AXIS) &&
|
||||
(axis == GAMEPAD_AXIS_LEFT_TRIGGER || axis == GAMEPAD_AXIS_RIGHT_TRIGGER ||
|
||||
fabsf(CORE.Input.Gamepad.axisState[gamepad][axis]) >= 0.2f)) value = CORE.Input.Gamepad.axisState[gamepad][axis];
|
||||
#endif
|
||||
|
||||
return value;
|
||||
|
@ -3579,40 +3580,6 @@ static int GetGamepadButton(int button)
|
|||
return btn;
|
||||
}
|
||||
|
||||
// Get gamepad axis generic to all platforms
|
||||
static int GetGamepadAxis(int axis)
|
||||
{
|
||||
int axs = GAMEPAD_AXIS_UNKNOWN;
|
||||
#if defined(PLATFORM_DESKTOP)
|
||||
switch (axis)
|
||||
{
|
||||
case GLFW_GAMEPAD_AXIS_LEFT_X: axs = GAMEPAD_AXIS_LEFT_X; break;
|
||||
case GLFW_GAMEPAD_AXIS_LEFT_Y: axs = GAMEPAD_AXIS_LEFT_Y; break;
|
||||
case GLFW_GAMEPAD_AXIS_RIGHT_X: axs = GAMEPAD_AXIS_RIGHT_X; break;
|
||||
case GLFW_GAMEPAD_AXIS_RIGHT_Y: axs = GAMEPAD_AXIS_RIGHT_Y; break;
|
||||
case GLFW_GAMEPAD_AXIS_LEFT_TRIGGER: axs = GAMEPAD_AXIS_LEFT_TRIGGER; break;
|
||||
case GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER: axs = GAMEPAD_AXIS_RIGHT_TRIGGER; break;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PLATFORM_UWP)
|
||||
axs = axis; // UWP will provide the correct axis
|
||||
#endif
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
// Gamepad axis reference:https://www.w3.org/TR/gamepad/#gamepad-interface
|
||||
switch (axis)
|
||||
{
|
||||
case 0: axs = GAMEPAD_AXIS_LEFT_X;
|
||||
case 1: axs = GAMEPAD_AXIS_LEFT_Y;
|
||||
case 2: axs = GAMEPAD_AXIS_RIGHT_X;
|
||||
case 3: axs = GAMEPAD_AXIS_RIGHT_X;
|
||||
}
|
||||
#endif
|
||||
|
||||
return axs;
|
||||
}
|
||||
|
||||
// Poll (store) all input events
|
||||
static void PollInputEvents(void)
|
||||
{
|
||||
|
@ -3731,15 +3698,14 @@ static void PollInputEvents(void)
|
|||
|
||||
for (int k = 0; (axes != NULL) && (k < GLFW_GAMEPAD_AXIS_LAST + 1) && (k < MAX_GAMEPAD_AXIS); k++)
|
||||
{
|
||||
const int axis = GetGamepadAxis(k);
|
||||
CORE.Input.Gamepad.axisState[i][axis] = axes[k];
|
||||
CORE.Input.Gamepad.axisState[i][k] = axes[k];
|
||||
}
|
||||
|
||||
// Register buttons for 2nd triggers (because GLFW doesn't count these as buttons but rather axis)
|
||||
CORE.Input.Gamepad.currentState[i][GAMEPAD_BUTTON_LEFT_TRIGGER_2] = (char)(CORE.Input.Gamepad.axisState[i][GAMEPAD_AXIS_LEFT_TRIGGER] > 0.1);
|
||||
CORE.Input.Gamepad.currentState[i][GAMEPAD_BUTTON_RIGHT_TRIGGER_2] = (char)(CORE.Input.Gamepad.axisState[i][GAMEPAD_AXIS_RIGHT_TRIGGER] > 0.1);
|
||||
|
||||
CORE.Input.Gamepad.axisCount = GLFW_GAMEPAD_AXIS_LAST;
|
||||
CORE.Input.Gamepad.axisCount = GLFW_GAMEPAD_AXIS_LAST + 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3787,8 +3753,7 @@ static void PollInputEvents(void)
|
|||
// Register axis data for every connected gamepad
|
||||
for (int j = 0; (j < gamepadState.numAxes) && (j < MAX_GAMEPAD_AXIS); j++)
|
||||
{
|
||||
const int axis = GetGamepadAxis(j);
|
||||
CORE.Input.Gamepad.axisState[i][axis] = gamepadState.axis[j];
|
||||
CORE.Input.Gamepad.axisState[i][j] = gamepadState.axis[j];
|
||||
}
|
||||
|
||||
CORE.Input.Gamepad.axisCount = gamepadState.numAxes;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue