comparison src/haptic/linux/SDL_syshaptic.c @ 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 84a634009a83
children f12ae0bae468
comparison
equal deleted inserted replaced
2509:3b54b3a97046 2510:e6ad7e678fca
36 #include <sys/stat.h> 36 #include <sys/stat.h>
37 #include <fcntl.h> 37 #include <fcntl.h>
38 #include <linux/limits.h> 38 #include <linux/limits.h>
39 #include <string.h> 39 #include <string.h>
40 #include <errno.h> 40 #include <errno.h>
41 #include <math.h>
42
43 #ifndef M_PI
44 # define M_PI 3.14159265358979323846
45 #endif
41 46
42 47
43 #define MAX_HAPTICS 32 48 #define MAX_HAPTICS 32
44 49
45 50
336 */ 341 */
337 static Uint16 342 static Uint16
338 SDL_SYS_ToDirection( SDL_HapticDirection * dir ) 343 SDL_SYS_ToDirection( SDL_HapticDirection * dir )
339 { 344 {
340 Uint32 tmp; 345 Uint32 tmp;
346 float f;
341 347
342 switch (dir->type) { 348 switch (dir->type) {
343 case SDL_HAPTIC_POLAR: 349 case SDL_HAPTIC_POLAR:
344 /* Linux directions are inverted. */ 350 /* Linux directions are inverted. */
345 tmp = (((18000 + dir->dir[0]) % 36000) * 0xFFFF) / 36000; 351 tmp = (((18000 + dir->dir[0]) % 36000) * 0xFFFF) / 36000;
346 return (Uint16) tmp; 352 return (Uint16) tmp;
347 break; 353 break;
348 case SDL_HAPTIC_CARTESIAN: 354 case SDL_HAPTIC_CARTESIAN:
349 /* TODO implement cartesian for linux since it's not supported 355 f = atan2(dir->dir[0], dir->dir[1]);
350 * by driver */ 356 tmp = (int)(f*18000./M_PI) % 36000;
357 tmp = (tmp * 0xFFFF) / 36000;
358 return (Uint16) tmp;
351 break; 359 break;
352 360
353 default: 361 default:
354 return -1; 362 return -1;
355 } 363 }