Implemented SDL_HAPTIC_CARTESIAN on linux. gsoc2008_force_feedback
authorEdgar Simo <bobbens@gmail.com>
Wed, 09 Jul 2008 18:23:54 +0000
branchgsoc2008_force_feedback
changeset 2510e6ad7e678fca
parent 2509 3b54b3a97046
child 2511 f12ae0bae468
Implemented SDL_HAPTIC_CARTESIAN on linux.
src/haptic/linux/SDL_syshaptic.c
     1.1 --- a/src/haptic/linux/SDL_syshaptic.c	Wed Jul 09 17:06:54 2008 +0000
     1.2 +++ b/src/haptic/linux/SDL_syshaptic.c	Wed Jul 09 18:23:54 2008 +0000
     1.3 @@ -38,6 +38,11 @@
     1.4  #include <linux/limits.h>
     1.5  #include <string.h>
     1.6  #include <errno.h>
     1.7 +#include <math.h>
     1.8 +
     1.9 +#ifndef M_PI
    1.10 +#  define M_PI     3.14159265358979323846
    1.11 +#endif
    1.12  
    1.13  
    1.14  #define MAX_HAPTICS  32
    1.15 @@ -338,6 +343,7 @@
    1.16  SDL_SYS_ToDirection( SDL_HapticDirection * dir )
    1.17  {
    1.18     Uint32 tmp;
    1.19 +   float f;
    1.20  
    1.21     switch (dir->type) {
    1.22        case SDL_HAPTIC_POLAR:
    1.23 @@ -346,8 +352,10 @@
    1.24           return (Uint16) tmp;
    1.25           break;
    1.26        case SDL_HAPTIC_CARTESIAN:
    1.27 -         /* TODO implement cartesian for linux since it's not supported
    1.28 -          * by driver */
    1.29 +         f = atan2(dir->dir[0], dir->dir[1]);
    1.30 +         tmp = (int)(f*18000./M_PI) % 36000;
    1.31 +         tmp = (tmp * 0xFFFF) / 36000;
    1.32 +         return (Uint16) tmp;
    1.33           break;
    1.34  
    1.35        default: