From 65ad45340d23bfa86f0f163dec753b57026c1091 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 4 May 2020 13:17:43 -0700 Subject: [PATCH] Improvement for bug 3446 - The haptic API does not allow to select the direction axes meyraud705 I see how the documentation is confusing. I think that the choice of the axis is an implementation detail. The documentation should state the goal of this value, so I propose this wording: "Use this value to play an effect on the steering wheel axis. This provides better compatibility across platforms and devices as SDL will guess the correct axis." Value could even be renamed 'SDL_HAPTIC_STEERING_AXIS'. For Linux, sending an effect on the X axis with a Logitech wheel works. Others brands don't have driver for Linux as far as I know. --- include/SDL_haptic.h | 19 +++++-------------- src/haptic/darwin/SDL_syshaptic.c | 4 ++-- src/haptic/linux/SDL_syshaptic.c | 2 +- src/haptic/windows/SDL_dinputhaptic.c | 4 ++-- 4 files changed, 10 insertions(+), 19 deletions(-) diff --git a/include/SDL_haptic.h b/include/SDL_haptic.h index 18c74eff6e1a7..c27da1186c4f2 100644 --- a/include/SDL_haptic.h +++ b/include/SDL_haptic.h @@ -337,21 +337,12 @@ typedef struct _SDL_Haptic SDL_Haptic; #define SDL_HAPTIC_SPHERICAL 2 /** - * \brief Uses first axis only. - * For some device with only one axis (steering wheel,...), - * SDL_HAPTIC_CARTESIAN does not work. SDL_HAPTIC_FIRST_AXIS can be used in - * this case. - * Using SDL_HAPTIC_FIRST_AXIS is equivalent to : - * \code - * SDL_HapticDirection direction; - * direction.type = SDL_HAPTIC_CARTESIAN; - * direction.dir[0] = 1; - * direction.dir[1] = 0; - * direction.dir[2] = 0; - * \endcode + * \brief Use this value to play an effect on the steering wheel axis. This + * provides better compatibility across platforms and devices as SDL will guess + * the correct axis. * \sa SDL_HapticDirection */ -#define SDL_HAPTIC_FIRST_AXIS 3 +#define SDL_HAPTIC_STEERING_AXIS 3 /* @} *//* Direction encodings */ @@ -461,7 +452,7 @@ typedef struct _SDL_Haptic SDL_Haptic; * \sa SDL_HAPTIC_POLAR * \sa SDL_HAPTIC_CARTESIAN * \sa SDL_HAPTIC_SPHERICAL - * \sa SDL_HAPTIC_FIRST_AXIS + * \sa SDL_HAPTIC_STEERING_AXIS * \sa SDL_HapticEffect * \sa SDL_HapticNumAxes */ diff --git a/src/haptic/darwin/SDL_syshaptic.c b/src/haptic/darwin/SDL_syshaptic.c index 55d28b80e994d..f37a10c5ce3e6 100644 --- a/src/haptic/darwin/SDL_syshaptic.c +++ b/src/haptic/darwin/SDL_syshaptic.c @@ -765,7 +765,7 @@ SDL_SYS_SetDirection(FFEFFECT * effect, SDL_HapticDirection * dir, int naxes) rglDir[2] = dir->dir[2]; } return 0; - case SDL_HAPTIC_FIRST_AXIS: + case SDL_HAPTIC_STEERING_AXIS: effect->dwFlags |= FFEFF_CARTESIAN; rglDir[0] = 0; return 0; @@ -817,7 +817,7 @@ SDL_SYS_ToFFEFFECT(SDL_Haptic * haptic, FFEFFECT * dest, SDL_HapticEffect * src) envelope->dwSize = sizeof(FFENVELOPE); /* Always should be this. */ /* Axes. */ - if (src->constant.direction.type == SDL_HAPTIC_FIRST_AXIS) { + if (src->constant.direction.type == SDL_HAPTIC_STEERING_AXIS) { dest->cAxes = 1; } else { dest->cAxes = haptic->naxes; diff --git a/src/haptic/linux/SDL_syshaptic.c b/src/haptic/linux/SDL_syshaptic.c index b8e7f13384f37..3a2fbf695785b 100644 --- a/src/haptic/linux/SDL_syshaptic.c +++ b/src/haptic/linux/SDL_syshaptic.c @@ -718,7 +718,7 @@ SDL_SYS_ToDirection(Uint16 *dest, SDL_HapticDirection * src) *dest = (Uint16) tmp; } break; - case SDL_HAPTIC_FIRST_AXIS: + case SDL_HAPTIC_STEERING_AXIS: *dest = 0x4000; break; default: diff --git a/src/haptic/windows/SDL_dinputhaptic.c b/src/haptic/windows/SDL_dinputhaptic.c index ea7526acae349..019e508651666 100644 --- a/src/haptic/windows/SDL_dinputhaptic.c +++ b/src/haptic/windows/SDL_dinputhaptic.c @@ -589,7 +589,7 @@ SDL_SYS_SetDirection(DIEFFECT * effect, SDL_HapticDirection * dir, int naxes) if (naxes > 2) rglDir[2] = dir->dir[2]; return 0; - case SDL_HAPTIC_FIRST_AXIS: + case SDL_HAPTIC_STEERING_AXIS: effect->dwFlags |= DIEFF_CARTESIAN; rglDir[0] = 0; return 0; @@ -641,7 +641,7 @@ SDL_SYS_ToDIEFFECT(SDL_Haptic * haptic, DIEFFECT * dest, envelope->dwSize = sizeof(DIENVELOPE); /* Always should be this. */ /* Axes. */ - if (src->constant.direction.type == SDL_HAPTIC_FIRST_AXIS) { + if (src->constant.direction.type == SDL_HAPTIC_STEERING_AXIS) { dest->cAxes = 1; } else { dest->cAxes = haptic->naxes;