Hey, so i’m having a strange issue with SDL_Haptic (latest rev), i’m using it on Windows 7 x64 and the controller is a Sony DualShock (PS2) gamepad.
For some reasons Force Feedback didn’t work at all in the app i’m doing, neither did it work on the small test haptic sample included in the doc. So i was a bit clueless, since using plain DirectInput code as the one provided in the DX SDK works quite well.
So i compiled the testhaptic and found out it was “Unable to create effect”, actually the IDirectInputDevice2_CreateEffect() func returns “E_INVALIDARG” which is quite odd.
After a bit more testing, i found out my gamepad has 3 FF axis, X axis, Y axis and RZ axis, and SDL uses them all, contrary to the DX SDK sample which only uses X and Y, but it turned out 3 axis can only be used in conjunction with SDL_HAPTIC_CARTESIAN or SDL_HAPTIC_SPHERICAL (while the testhaptic uses SDL_HAPTIC_POLAR everywhere).
Using SDL_HAPTIC_CARTESIAN effectively fixed the issues with creating the effect, but obviously, it still won’t rumble, at this point, it seems to be a driver issue though [Evil or Very Mad]
So just like it’s done in DirectInput, it might be a good idea to let the user specify the number of axis to use through a SDL function something like the following : ( “works-for-me” )
What do you guys think ? Am i doing it wrong?
Code:
Index: include/SDL_haptic.h===================================================================
— include/SDL_haptic.h (revision 5241)
+++ include/SDL_haptic.h (working copy)
@@ -921,10 +921,22 @@
- \brief Gets the number of haptic axes the device has.
- \sa SDL_HapticDirection
-
- \sa SDL_HapticSetAxes
*/
extern DECLSPEC int SDLCALL SDL_HapticNumAxes(SDL_Haptic * haptic);
- \sa SDL_HapticSetAxes
/**
-
- \brief Sets the number of haptic axes to use.
-
-
- \sa SDL_HapticDirection
-
- \sa SDL_HapticNumAxes
- */
+extern DECLSPEC int SDLCALL SDL_HapticSetAxes(SDL_Haptic * haptic, int axes);
+/**
- \brief Checks to see if effect is supported by haptic.
- \param haptic Haptic device to check on.
Index: src/haptic/SDL_haptic.c
===================================================================
— src/haptic/SDL_haptic.c (revision 5241)
+++ src/haptic/SDL_haptic.c (working copy)
@@ -416,6 +416,29 @@
}
/*
-
- Manually set the number of axis on the device.
- */
+int
+SDL_HapticSetAxes(SDL_Haptic * haptic, int axes)
+{ - static int origNaxes = 0;
- if (!ValidHaptic(haptic)) {
-
return -1;
- }
- if (axes > 0) {
-
if (!origNaxes)
-
origNaxes = haptic->naxes;
-
if (axes <= origNaxes)
-
haptic->naxes = axes;
-
else
-
return -1;
- }
- return 0;
+}
+/*
- Checks to see if the device can support the effect.
*/
int
Index: test/testhaptic.c
===================================================================
— test/testhaptic.c (revision 5241)
+++ test/testhaptic.c (working copy)
@@ -97,6 +97,10 @@
SDL_GetError());
return 1;
}
-
// Use a maximum of 2 axis
-
SDL_HapticSetAxes(haptic, 2);
-
} else {printf("Device: %s\n", SDL_HapticName(i)); HapticPrintSupported(haptic);