Haptic: DInput's POLAR direction actually matches Linux's direction. Thanks, Elias! Partially fixes Bugzilla #2686.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
diff --git a/include/SDL_haptic.h b/include/SDL_haptic.h
index bc33a79..dceaeb8 100644
--- a/include/SDL_haptic.h
+++ b/include/SDL_haptic.h
@@ -370,7 +370,7 @@ typedef struct _SDL_Haptic SDL_Haptic;
^
|
|
- (1,0) West <----[ HAPTIC ]----> East (-1,0)
+ (-1,0) West <----[ HAPTIC ]----> East (1,0)
|
|
v
@@ -395,9 +395,9 @@ typedef struct _SDL_Haptic SDL_Haptic;
* (X axis, Y axis and Z axis (with 3 axes)). ::SDL_HAPTIC_CARTESIAN uses
* the first three \c dir parameters. The cardinal directions would be:
* - North: 0,-1, 0
- * - East: -1, 0, 0
+ * - East: 1, 0, 0
* - South: 0, 1, 0
- * - West: 1, 0, 0
+ * - West: -1, 0, 0
*
* The Z axis represents the height of the effect if supported, otherwise
* it's unused. In cartesian encoding (1, 2) would be the same as (2, 4), you
diff --git a/src/haptic/linux/SDL_syshaptic.c b/src/haptic/linux/SDL_syshaptic.c
index fc8ab5f..c70a470 100644
--- a/src/haptic/linux/SDL_syshaptic.c
+++ b/src/haptic/linux/SDL_syshaptic.c
@@ -671,7 +671,7 @@ SDL_SYS_ToDirection(Uint16 *dest, SDL_HapticDirection * src)
180 deg -> 0x8000 (up)
270 deg -> 0xC000 (right)
*/
- tmp = (((18000 + src->dir[0]) % 36000) * 0xFFFF) / 36000; /* convert to range [0,0xFFFF] */
+ tmp = ((src->dir[0] % 36000) * 0x8000) / 18000; /* convert to range [0,0xFFFF] */
*dest = (Uint16) tmp;
break;
@@ -682,10 +682,10 @@ SDL_SYS_ToDirection(Uint16 *dest, SDL_HapticDirection * src)
Polar direction, except that we have to add 90 degrees. It is the angle
from EAST {1,0} towards SOUTH {0,1}.
--> add 9000
- --> finally add 18000 and convert to [0,0xFFFF] as in case SDL_HAPTIC_POLAR.
+ --> finally convert to [0,0xFFFF] as in case SDL_HAPTIC_POLAR.
*/
tmp = ((src->dir[0]) + 9000) % 36000; /* Convert to polars */
- tmp = (((18000 + tmp) % 36000) * 0xFFFF) / 36000; /* convert to range [0,0xFFFF] */
+ tmp = (tmp * 0x8000) / 18000; /* convert to range [0,0xFFFF] */
*dest = (Uint16) tmp;
break;
@@ -699,10 +699,10 @@ SDL_SYS_ToDirection(Uint16 *dest, SDL_HapticDirection * src)
have the first spherical value. Therefore we proceed as in case
SDL_HAPTIC_SPHERICAL and add another 9000 to get the polar value.
--> add 45000 in total
- --> finally add 18000 and convert to [0,0xFFFF] as in case SDL_HAPTIC_POLAR.
+ --> finally convert to [0,0xFFFF] as in case SDL_HAPTIC_POLAR.
*/
- tmp = (((int) (f * 18000. / M_PI)) + 45000) % 36000;
- tmp = (((18000 + tmp) % 36000) * 0xFFFF) / 36000; /* convert to range [0,0xFFFF] */
+ tmp = (((Sint32) (f * 18000. / M_PI)) + 45000) % 36000;
+ tmp = (tmp * 0x8000) / 18000; /* convert to range [0,0xFFFF] */
*dest = (Uint16) tmp;
break;