Haptic: DInput's POLAR direction actually matches Linux's direction.
authorRyan C. Gordon <icculus@icculus.org>
Sat, 16 Aug 2014 16:41:25 -0400
changeset 9068a57a1d70ae07
parent 9067 2412ba127e23
child 9069 16b5dda99337
Haptic: DInput's POLAR direction actually matches Linux's direction.

Thanks, Elias!

Partially fixes Bugzilla #2686.
include/SDL_haptic.h
src/haptic/linux/SDL_syshaptic.c
     1.1 --- a/include/SDL_haptic.h	Sat Aug 16 16:40:01 2014 -0400
     1.2 +++ b/include/SDL_haptic.h	Sat Aug 16 16:41:25 2014 -0400
     1.3 @@ -370,7 +370,7 @@
     1.4                           ^
     1.5                           |
     1.6                           |
     1.7 -    (1,0)  West <----[ HAPTIC ]----> East (-1,0)
     1.8 +   (-1,0)  West <----[ HAPTIC ]----> East (1,0)
     1.9                           |
    1.10                           |
    1.11                           v
    1.12 @@ -395,9 +395,9 @@
    1.13   *  (X axis, Y axis and Z axis (with 3 axes)).  ::SDL_HAPTIC_CARTESIAN uses
    1.14   *  the first three \c dir parameters.  The cardinal directions would be:
    1.15   *   - North:  0,-1, 0
    1.16 - *   - East:  -1, 0, 0
    1.17 + *   - East:   1, 0, 0
    1.18   *   - South:  0, 1, 0
    1.19 - *   - West:   1, 0, 0
    1.20 + *   - West:  -1, 0, 0
    1.21   *
    1.22   *  The Z axis represents the height of the effect if supported, otherwise
    1.23   *  it's unused.  In cartesian encoding (1, 2) would be the same as (2, 4), you
     2.1 --- a/src/haptic/linux/SDL_syshaptic.c	Sat Aug 16 16:40:01 2014 -0400
     2.2 +++ b/src/haptic/linux/SDL_syshaptic.c	Sat Aug 16 16:41:25 2014 -0400
     2.3 @@ -671,7 +671,7 @@
     2.4                          180 deg -> 0x8000 (up)
     2.5                          270 deg -> 0xC000 (right)
     2.6                      */
     2.7 -        tmp = (((18000 + src->dir[0]) % 36000) * 0xFFFF) / 36000; /* convert to range [0,0xFFFF] */
     2.8 +        tmp = ((src->dir[0] % 36000) * 0x8000) / 18000; /* convert to range [0,0xFFFF] */
     2.9          *dest = (Uint16) tmp;
    2.10          break;
    2.11  
    2.12 @@ -682,10 +682,10 @@
    2.13                  Polar direction, except that we have to add 90 degrees. It is the angle
    2.14                  from EAST {1,0} towards SOUTH {0,1}.
    2.15                  --> add 9000
    2.16 -                --> finally add 18000 and convert to [0,0xFFFF] as in case SDL_HAPTIC_POLAR.
    2.17 +                --> finally convert to [0,0xFFFF] as in case SDL_HAPTIC_POLAR.
    2.18              */
    2.19              tmp = ((src->dir[0]) + 9000) % 36000;    /* Convert to polars */
    2.20 -        tmp = (((18000 + tmp) % 36000) * 0xFFFF) / 36000; /* convert to range [0,0xFFFF] */
    2.21 +        tmp = (tmp * 0x8000) / 18000; /* convert to range [0,0xFFFF] */
    2.22          *dest = (Uint16) tmp;
    2.23          break;
    2.24  
    2.25 @@ -699,10 +699,10 @@
    2.26                          have the first spherical value. Therefore we proceed as in case
    2.27                          SDL_HAPTIC_SPHERICAL and add another 9000 to get the polar value.
    2.28                        --> add 45000 in total
    2.29 -                      --> finally add 18000 and convert to [0,0xFFFF] as in case SDL_HAPTIC_POLAR.
    2.30 +                      --> finally convert to [0,0xFFFF] as in case SDL_HAPTIC_POLAR.
    2.31                      */
    2.32 -                tmp = (((int) (f * 18000. / M_PI)) + 45000) % 36000;
    2.33 -        tmp = (((18000 + tmp) % 36000) * 0xFFFF) / 36000; /* convert to range [0,0xFFFF] */
    2.34 +                tmp = (((Sint32) (f * 18000. / M_PI)) + 45000) % 36000;
    2.35 +        tmp = (tmp * 0x8000) / 18000; /* convert to range [0,0xFFFF] */
    2.36          *dest = (Uint16) tmp;
    2.37          break;
    2.38