Implemented polar coordinates in linux. gsoc2008_force_feedback
authorEdgar Simo <bobbens@gmail.com>
Sun, 06 Jul 2008 21:47:41 +0000
branchgsoc2008_force_feedback
changeset 25005251d0510b7e
parent 2499 cc2b270608b2
child 2501 ff12f79dfc8d
Implemented polar coordinates in linux.
SDL_ConditionEffect now takes into account both axes.
include/SDL_haptic.h
src/haptic/linux/SDL_syshaptic.c
     1.1 --- a/include/SDL_haptic.h	Sun Jul 06 20:41:00 2008 +0000
     1.2 +++ b/include/SDL_haptic.h	Sun Jul 06 21:47:41 2008 +0000
     1.3 @@ -450,6 +450,9 @@
     1.4   * \brief A structure containing a template for a Condition effect.
     1.5   *
     1.6   * Direction is handled by condition internals instead of a direction member.
     1.7 + *  Each of right_sat, lefT-sat, right_coeff, left_coeff, deadband and center
     1.8 + *  have two parameters, first is for x value, second is for y value following
     1.9 + *  the scheme set by SDL_HapticDirection.
    1.10   *
    1.11   * The struct handles the following effects:
    1.12   *   - SDL_HAPTIC_SPRING: Effect based on axes position.
    1.13 @@ -457,6 +460,7 @@
    1.14   *   - SDL_HAPTIC_INERTIA: Effect based on axes acceleration.
    1.15   *   - SDL_HAPTIC_FRICTION: Effect based on axes movement.
    1.16   *
    1.17 + * \sa SDL_HapticDirection
    1.18   * \sa SDL_HAPTIC_SPRING
    1.19   * \sa SDL_HAPTIC_DAMPER
    1.20   * \sa SDL_HAPTIC_INERTIA
    1.21 @@ -476,12 +480,12 @@
    1.22     Uint16 interval; /**< How soon it can be triggered again after button. */
    1.23  
    1.24     /* Condition */
    1.25 -   Uint16 right_sat; /**< Level when joystick is to the right. */
    1.26 -   Uint16 left_sat; /**< Level when joystick is to the left. */
    1.27 -   Sint16 right_coeff; /**< How fast to increase the force towards the right. */
    1.28 -   Sint16 left_coeff; /**< How fast to increase the force towards the left. */
    1.29 -   Uint16 deadband; /**< Size of the dead zone. */
    1.30 -   Sint16 center; /**< Position of the dead zone. */
    1.31 +   Uint16 right_sat[2]; /**< Level when joystick is to the right. */
    1.32 +   Uint16 left_sat[2]; /**< Level when joystick is to the left. */
    1.33 +   Sint16 right_coeff[2]; /**< How fast to increase the force towards the right. */
    1.34 +   Sint16 left_coeff[2]; /**< How fast to increase the force towards the left. */
    1.35 +   Uint16 deadband[2]; /**< Size of the dead zone. */
    1.36 +   Sint16 center[2]; /**< Position of the dead zone. */
    1.37  } SDL_HapticCondition;
    1.38  /**
    1.39   * \struct SDL_HapticRamp
    1.40 @@ -574,7 +578,7 @@
    1.41     Uint16 type; /**< Effect type. */
    1.42     SDL_HapticConstant constant; /**< Constant effect. */
    1.43     SDL_HapticPeriodic periodic; /**< Periodic effect. */
    1.44 -   SDL_HapticCondition condition[2]; /**< Condition effect, one for each axis. */
    1.45 +   SDL_HapticCondition condition; /**< Condition effect. */
    1.46     SDL_HapticRamp ramp; /**< Ramp effect. */
    1.47  } SDL_HapticEffect;
    1.48  
     2.1 --- a/src/haptic/linux/SDL_syshaptic.c	Sun Jul 06 20:41:00 2008 +0000
     2.2 +++ b/src/haptic/linux/SDL_syshaptic.c	Sun Jul 06 21:47:41 2008 +0000
     2.3 @@ -111,6 +111,9 @@
     2.4     return ret;
     2.5  }
     2.6  
     2.7 +/*
     2.8 + * Initializes the haptic subsystem by finding available devices.
     2.9 + */
    2.10  int
    2.11  SDL_SYS_HapticInit(void)
    2.12  {
    2.13 @@ -328,6 +331,31 @@
    2.14     SDL_hapticlist[0].fname = NULL;
    2.15  }
    2.16  
    2.17 +/*
    2.18 + * Returns the ff_effect usable direction from a SDL_HapticDirection.
    2.19 + */
    2.20 +static Uint16
    2.21 +SDL_SYS_ToDirection( SDL_HapticDirection * dir )
    2.22 +{
    2.23 +   Uint32 tmp;
    2.24 +
    2.25 +   switch (dir->type) {
    2.26 +      case SDL_HAPTIC_POLAR:
    2.27 +         tmp = ((dir->dir[0] % 36000) * 0xFFFF) / 36000;
    2.28 +         return (Uint16) tmp;
    2.29 +         break;
    2.30 +      case SDL_HAPTIC_CARTESIAN:
    2.31 +         /* TODO implement cartesian for linux since it's not supported
    2.32 +          * by driver */
    2.33 +         break;
    2.34 +
    2.35 +      default:
    2.36 +         return -1;
    2.37 +   }
    2.38 +
    2.39 +   return 0;
    2.40 +}
    2.41 +
    2.42  #define  CLAMP(x)    (((x) > 32767) ? 32767 : x)
    2.43  /*
    2.44   * Initializes the linux effect struct from a haptic_effect.
    2.45 @@ -351,7 +379,7 @@
    2.46  
    2.47           /* Header */
    2.48           dest->type = FF_CONSTANT;
    2.49 -         dest->direction = CLAMP(constant->direction);
    2.50 +         dest->direction = SDL_SYS_ToDirection(&constant->direction);
    2.51  
    2.52           /* Replay */
    2.53           dest->replay.length = CLAMP(constant->length);
    2.54 @@ -381,7 +409,7 @@
    2.55  
    2.56           /* Header */
    2.57           dest->type = FF_PERIODIC;
    2.58 -         dest->direction = CLAMP(periodic->direction);
    2.59 +         dest->direction = SDL_SYS_ToDirection(&periodic->direction);
    2.60           
    2.61           /* Replay */
    2.62           dest->replay.length = CLAMP(periodic->length);
    2.63 @@ -430,7 +458,7 @@
    2.64              dest->type = FF_INERTIA;
    2.65           else if (dest->type == SDL_HAPTIC_FRICTION)
    2.66              dest->type = FF_FRICTION;
    2.67 -         dest->direction = CLAMP(condition->direction);
    2.68 +         dest->direction = 0; /* Handled by the condition-specifics. */
    2.69  
    2.70           /* Replay */
    2.71           dest->replay.length = CLAMP(condition->length);
    2.72 @@ -440,13 +468,21 @@
    2.73           dest->trigger.button = CLAMP(condition->button);
    2.74           dest->trigger.interval = CLAMP(condition->interval);
    2.75  
    2.76 -         /* Condition - TODO handle axes */
    2.77 -         dest->u.condition[0].right_saturation = CLAMP(condition->right_sat);
    2.78 -         dest->u.condition[0].left_saturation = CLAMP(condition->left_sat);
    2.79 -         dest->u.condition[0].right_coeff = condition->right_coeff;
    2.80 -         dest->u.condition[0].left_coeff = condition->left_coeff;
    2.81 -         dest->u.condition[0].deadband = CLAMP(condition->deadband);
    2.82 -         dest->u.condition[0].center = condition->center;
    2.83 +         /* Condition */
    2.84 +         /* X axis */
    2.85 +         dest->u.condition[0].right_saturation = CLAMP(condition->right_sat[0]);
    2.86 +         dest->u.condition[0].left_saturation = CLAMP(condition->left_sat[0]);
    2.87 +         dest->u.condition[0].right_coeff = condition->right_coeff[0];
    2.88 +         dest->u.condition[0].left_coeff = condition->left_coeff[0];
    2.89 +         dest->u.condition[0].deadband = CLAMP(condition->deadband[0]);
    2.90 +         dest->u.condition[0].center = condition->center[0];
    2.91 +         /* Y axis */
    2.92 +         dest->u.condition[1].right_saturation = CLAMP(condition->right_sat[1]);
    2.93 +         dest->u.condition[1].left_saturation = CLAMP(condition->left_sat[1]);
    2.94 +         dest->u.condition[1].right_coeff = condition->right_coeff[1];
    2.95 +         dest->u.condition[1].left_coeff = condition->left_coeff[1];  
    2.96 +         dest->u.condition[1].deadband = CLAMP(condition->deadband[1]);
    2.97 +         dest->u.condition[1].center = condition->center[1];
    2.98  
    2.99           break;
   2.100  
   2.101 @@ -455,7 +491,7 @@
   2.102  
   2.103           /* Header */
   2.104           dest->type = FF_RAMP;
   2.105 -         dest->direction = CLAMP(ramp->direction);
   2.106 +         dest->direction = SDL_SYS_ToDirection(&ramp->direction);
   2.107  
   2.108           /* Replay */
   2.109           dest->replay.length = CLAMP(ramp->length);