diff options
| author | Mickaël Malécot <[email protected]> | 2020-05-09 12:39:41 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-05-09 12:39:41 +0200 |
| commit | 0bd64b7975722382773a5928e80dfe64da30b335 (patch) | |
| tree | effbd2770b71df8f5d009c449a5ab454f7172ba7 /src/core.c | |
| parent | 7efed56b664d3caf8af01ae017fb3585123997f6 (diff) | |
| download | raylib-0bd64b7975722382773a5928e80dfe64da30b335.tar.gz raylib-0bd64b7975722382773a5928e80dfe64da30b335.zip | |
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
Diffstat (limited to 'src/core.c')
| -rw-r--r-- | src/core.c | 47 |
1 files changed, 6 insertions, 41 deletions
@@ -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; |
