Split controller axes into positive and negative sides so each can be bound independently.

Using this a D-Pad can be mapped to a thumbstick and vice versa.
Also added support for inverted axes, improving trigger binding support
This commit is contained in:
Sam Lantinga
2016-12-27 01:39:07 -08:00
parent 7c31636666
commit 6d7da0887d
7 changed files with 609 additions and 340 deletions

View File

@@ -33,9 +33,7 @@
#endif
#define INPUT_QSIZE 32 /* Buffer up to 32 input messages */
#define AXIS_MIN -32768 /* minimum value for axis coordinate */
#define AXIS_MAX 32767 /* maximum value for axis coordinate */
#define JOY_AXIS_THRESHOLD (((AXIS_MAX)-(AXIS_MIN))/100) /* 1% motion */
#define JOY_AXIS_THRESHOLD (((SDL_JOYSTICK_AXIS_MAX)-(SDL_JOYSTICK_AXIS_MIN))/100) /* 1% motion */
/* external variables referenced. */
extern HWND SDL_HelperWindow;
@@ -481,8 +479,8 @@ EnumDevObjectsCallback(LPCDIDEVICEOBJECTINSTANCE dev, LPVOID pvRef)
diprg.diph.dwHeaderSize = sizeof(diprg.diph);
diprg.diph.dwObj = dev->dwType;
diprg.diph.dwHow = DIPH_BYID;
diprg.lMin = AXIS_MIN;
diprg.lMax = AXIS_MAX;
diprg.lMin = SDL_JOYSTICK_AXIS_MIN;
diprg.lMax = SDL_JOYSTICK_AXIS_MAX;
result =
IDirectInputDevice8_SetProperty(joystick->hwdata->InputDevice,

View File

@@ -41,10 +41,8 @@
#define MAX_JOYSTICKS 16
#define MAX_AXES 6 /* each joystick can have up to 6 axes */
#define MAX_BUTTONS 32 /* and 32 buttons */
#define AXIS_MIN -32768 /* minimum value for axis coordinate */
#define AXIS_MAX 32767 /* maximum value for axis coordinate */
/* limit axis to 256 possible positions to filter out noise */
#define JOY_AXIS_THRESHOLD (((AXIS_MAX)-(AXIS_MIN))/256)
#define JOY_AXIS_THRESHOLD (((SDL_JOYSTICK_AXIS_MAX)-(SDL_JOYSTICK_AXIS_MIN))/256)
#define JOY_BUTTON_FLAG(n) (1<<n)
@@ -253,9 +251,9 @@ SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
joystick->hwdata->id = SYS_JoystickID[index];
for (i = 0; i < MAX_AXES; ++i) {
if ((i < 2) || (SYS_Joystick[index].wCaps & caps_flags[i - 2])) {
joystick->hwdata->transaxis[i].offset = AXIS_MIN - axis_min[i];
joystick->hwdata->transaxis[i].offset = SDL_JOYSTICK_AXIS_MIN - axis_min[i];
joystick->hwdata->transaxis[i].scale =
(float) (AXIS_MAX - AXIS_MIN) / (axis_max[i] - axis_min[i]);
(float) (SDL_JOYSTICK_AXIS_MAX - SDL_JOYSTICK_AXIS_MIN) / (axis_max[i] - axis_min[i]);
} else {
joystick->hwdata->transaxis[i].offset = 0;
joystick->hwdata->transaxis[i].scale = 1.0; /* Just in case */