From 8da2af639c04830e808cab212900abd227b6b6e6 Mon Sep 17 00:00:00 2001 From: Edgar Simo Date: Wed, 9 Jul 2008 18:23:54 +0000 Subject: [PATCH] Implemented SDL_HAPTIC_CARTESIAN on linux. --- src/haptic/linux/SDL_syshaptic.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/haptic/linux/SDL_syshaptic.c b/src/haptic/linux/SDL_syshaptic.c index c4621bf65..b6428ece4 100644 --- a/src/haptic/linux/SDL_syshaptic.c +++ b/src/haptic/linux/SDL_syshaptic.c @@ -38,6 +38,11 @@ #include #include #include +#include + +#ifndef M_PI +# define M_PI 3.14159265358979323846 +#endif #define MAX_HAPTICS 32 @@ -338,6 +343,7 @@ static Uint16 SDL_SYS_ToDirection( SDL_HapticDirection * dir ) { Uint32 tmp; + float f; switch (dir->type) { case SDL_HAPTIC_POLAR: @@ -346,8 +352,10 @@ SDL_SYS_ToDirection( SDL_HapticDirection * dir ) 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: