changeset 2510:e6ad7e678fca gsoc2008_force_feedback

Implemented SDL_HAPTIC_CARTESIAN on linux.
author Edgar Simo <bobbens@gmail.com>
date Wed, 09 Jul 2008 18:23:54 +0000
parents 3b54b3a97046
children f12ae0bae468
files src/haptic/linux/SDL_syshaptic.c
diffstat 1 files changed, 10 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/haptic/linux/SDL_syshaptic.c	Wed Jul 09 17:06:54 2008 +0000
+++ b/src/haptic/linux/SDL_syshaptic.c	Wed Jul 09 18:23:54 2008 +0000
@@ -38,6 +38,11 @@
 #include <linux/limits.h>
 #include <string.h>
 #include <errno.h>
+#include <math.h>
+
+#ifndef M_PI
+#  define M_PI     3.14159265358979323846
+#endif
 
 
 #define MAX_HAPTICS  32
@@ -338,6 +343,7 @@
 SDL_SYS_ToDirection( SDL_HapticDirection * dir )
 {
    Uint32 tmp;
+   float f;
 
    switch (dir->type) {
       case SDL_HAPTIC_POLAR:
@@ -346,8 +352,10 @@
          return (Uint16) tmp;
          break;
       case SDL_HAPTIC_CARTESIAN:
-         /* TODO implement cartesian for linux since it's not supported
-          * by driver */
+         f = atan2(dir->dir[0], dir->dir[1]);
+         tmp = (int)(f*18000./M_PI) % 36000;
+         tmp = (tmp * 0xFFFF) / 36000;
+         return (Uint16) tmp;
          break;
 
       default: