src/events/SDL_gesture.c
changeset 7677 871d43c6968a
parent 7662 d31efd717578
child 7678 286c42d7c5ed
     1.1 --- a/src/events/SDL_gesture.c	Tue Aug 20 23:20:32 2013 -0400
     1.2 +++ b/src/events/SDL_gesture.c	Wed Aug 21 09:43:09 2013 -0300
     1.3 @@ -121,8 +121,8 @@
     1.4      if (src == NULL) return 0;
     1.5  
     1.6  
     1.7 -    /*No Longer storing the Hash, rehash on load*/
     1.8 -    /*if(SDL_RWops.write(src,&(templ->hash),sizeof(templ->hash),1) != 1) return 0;*/
     1.9 +    /*No Longer storing the Hash, rehash on load */
    1.10 +    /*if(SDL_RWops.write(src,&(templ->hash),sizeof(templ->hash),1) != 1) return 0; */
    1.11  
    1.12      if (SDL_RWwrite(src,templ->path,
    1.13                      sizeof(templ->path[0]),DOLLARNPOINTS) != DOLLARNPOINTS)
    1.14 @@ -159,7 +159,7 @@
    1.15  }
    1.16  
    1.17  /*path is an already sampled set of points
    1.18 -Returns the index of the gesture on success, or -1*/
    1.19 +Returns the index of the gesture on success, or -1 */
    1.20  static int SDL_AddDollarGesture_one(SDL_GestureTouch* inTouch, SDL_FloatPoint* path)
    1.21  {
    1.22      SDL_DollarTemplate* dollarTemplate;
    1.23 @@ -196,7 +196,7 @@
    1.24              if (index < 0)
    1.25                  return -1;
    1.26          }
    1.27 -        /* Use the index of the last one added.*/
    1.28 +        /* Use the index of the last one added. */
    1.29          return index;
    1.30      } else {
    1.31          return SDL_AddDollarGesture_one(inTouch, path);
    1.32 @@ -223,16 +223,16 @@
    1.33             DOLLARNPOINTS) break;
    1.34  
    1.35          if (touchId >= 0) {
    1.36 -            /*printf("Adding loaded gesture to 1 touch\n");*/
    1.37 +            /*printf("Adding loaded gesture to 1 touch\n"); */
    1.38              if (SDL_AddDollarGesture(touch, templ.path) >= 0)
    1.39                  loaded++;
    1.40          }
    1.41          else {
    1.42 -            /*printf("Adding to: %i touches\n",SDL_numGestureTouches);*/
    1.43 +            /*printf("Adding to: %i touches\n",SDL_numGestureTouches); */
    1.44              for (i = 0; i < SDL_numGestureTouches; i++) {
    1.45                  touch = &SDL_gestureTouch[i];
    1.46 -                /*printf("Adding loaded gesture to + touches\n");*/
    1.47 -                /*TODO: What if this fails?*/
    1.48 +                /*printf("Adding loaded gesture to + touches\n"); */
    1.49 +                /*TODO: What if this fails? */
    1.50                  SDL_AddDollarGesture(touch,templ.path);
    1.51              }
    1.52              loaded++;
    1.53 @@ -245,7 +245,7 @@
    1.54  
    1.55  static float dollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ,float ang)
    1.56  {
    1.57 -    /*  SDL_FloatPoint p[DOLLARNPOINTS];*/
    1.58 +    /*  SDL_FloatPoint p[DOLLARNPOINTS]; */
    1.59      float dist = 0;
    1.60      SDL_FloatPoint p;
    1.61      int i;
    1.62 @@ -297,7 +297,7 @@
    1.63      return SDL_min(f1,f2);
    1.64  }
    1.65  
    1.66 -/*DollarPath contains raw points, plus (possibly) the calculated length*/
    1.67 +/*DollarPath contains raw points, plus (possibly) the calculated length */
    1.68  static int dollarNormalize(const SDL_DollarPath *path,SDL_FloatPoint *points)
    1.69  {
    1.70      int i;
    1.71 @@ -310,7 +310,7 @@
    1.72      float w,h;
    1.73      float length = path->length;
    1.74  
    1.75 -    /*Calculate length if it hasn't already been done*/
    1.76 +    /*Calculate length if it hasn't already been done */
    1.77      if (length <= 0) {
    1.78          for (i=1;i < path->numPoints; i++) {
    1.79              float dx = path->p[i  ].x - path->p[i-1].x;
    1.80 @@ -319,17 +319,17 @@
    1.81          }
    1.82      }
    1.83  
    1.84 -    /*Resample*/
    1.85 +    /*Resample */
    1.86      interval = length/(DOLLARNPOINTS - 1);
    1.87      dist = interval;
    1.88  
    1.89      centroid.x = 0;centroid.y = 0;
    1.90  
    1.91 -    /*printf("(%f,%f)\n",path->p[path->numPoints-1].x,path->p[path->numPoints-1].y);*/
    1.92 +    /*printf("(%f,%f)\n",path->p[path->numPoints-1].x,path->p[path->numPoints-1].y); */
    1.93      for (i = 1; i < path->numPoints; i++) {
    1.94          float d = (float)(SDL_sqrt((path->p[i-1].x-path->p[i].x)*(path->p[i-1].x-path->p[i].x)+
    1.95                                     (path->p[i-1].y-path->p[i].y)*(path->p[i-1].y-path->p[i].y)));
    1.96 -        /*printf("d = %f dist = %f/%f\n",d,dist,interval);*/
    1.97 +        /*printf("d = %f dist = %f/%f\n",d,dist,interval); */
    1.98          while (dist + d > interval) {
    1.99              points[numPoints].x = path->p[i-1].x +
   1.100                  ((interval-dist)/d)*(path->p[i].x-path->p[i-1].x);
   1.101 @@ -347,15 +347,15 @@
   1.102          SDL_SetError("ERROR: NumPoints = %i\n",numPoints);
   1.103          return 0;
   1.104      }
   1.105 -    /*copy the last point*/
   1.106 +    /*copy the last point */
   1.107      points[DOLLARNPOINTS-1] = path->p[path->numPoints-1];
   1.108      numPoints = DOLLARNPOINTS;
   1.109  
   1.110      centroid.x /= numPoints;
   1.111      centroid.y /= numPoints;
   1.112  
   1.113 -    /*printf("Centroid (%f,%f)",centroid.x,centroid.y);*/
   1.114 -    /*Rotate Points so point 0 is left of centroid and solve for the bounding box*/
   1.115 +    /*printf("Centroid (%f,%f)",centroid.x,centroid.y); */
   1.116 +    /*Rotate Points so point 0 is left of centroid and solve for the bounding box */
   1.117      xmin = centroid.x;
   1.118      xmax = centroid.x;
   1.119      ymin = centroid.y;
   1.120 @@ -379,7 +379,7 @@
   1.121          if (points[i].y > ymax) ymax = points[i].y;
   1.122      }
   1.123  
   1.124 -    /*Scale points to DOLLARSIZE, and translate to the origin*/
   1.125 +    /*Scale points to DOLLARSIZE, and translate to the origin */
   1.126      w = xmax-xmin;
   1.127      h = ymax-ymin;
   1.128  
   1.129 @@ -400,7 +400,7 @@
   1.130  
   1.131      dollarNormalize(path,points);
   1.132  
   1.133 -    /*PrintPath(points);*/
   1.134 +    /*PrintPath(points); */
   1.135      *bestTempl = -1;
   1.136      for (i = 0; i < touch->numDollarTemplates; i++) {
   1.137          float diff = bestDollarDifference(points,touch->dollarTemplate[i].path);
   1.138 @@ -436,7 +436,7 @@
   1.139  {
   1.140      int i;
   1.141      for (i = 0; i < SDL_numGestureTouches; i++) {
   1.142 -        /*printf("%i ?= %i\n",SDL_gestureTouch[i].id,id);*/
   1.143 +        /*printf("%i ?= %i\n",SDL_gestureTouch[i].id,id); */
   1.144          if (SDL_gestureTouch[i].id == id)
   1.145              return &SDL_gestureTouch[i];
   1.146      }
   1.147 @@ -466,7 +466,7 @@
   1.148      event.mgesture.y = touch->centroid.y;
   1.149      event.dgesture.gestureId = gestureId;
   1.150      event.dgesture.error = error;
   1.151 -    /*A finger came up to trigger this event.*/
   1.152 +    /*A finger came up to trigger this event. */
   1.153      event.dgesture.numFingers = touch->numDownFingers + 1;
   1.154      return SDL_PushEvent(&event) > 0;
   1.155  }
   1.156 @@ -501,13 +501,13 @@
   1.157          event->type == SDL_FINGERUP) {
   1.158          SDL_GestureTouch* inTouch = SDL_GetGestureTouch(event->tfinger.touchId);
   1.159  
   1.160 -        /*Shouldn't be possible*/
   1.161 +        /*Shouldn't be possible */
   1.162          if (inTouch == NULL) return;
   1.163  
   1.164          x = event->tfinger.x;
   1.165          y = event->tfinger.y;
   1.166  
   1.167 -        /*Finger Up*/
   1.168 +        /*Finger Up */
   1.169          if (event->type == SDL_FINGERUP) {
   1.170              inTouch->numDownFingers--;
   1.171  
   1.172 @@ -515,7 +515,7 @@
   1.173              if (inTouch->recording) {
   1.174                  inTouch->recording = SDL_FALSE;
   1.175                  dollarNormalize(&inTouch->dollarPath,path);
   1.176 -                /*PrintPath(path);*/
   1.177 +                /*PrintPath(path); */
   1.178                  if (recordAll) {
   1.179                      index = SDL_AddDollarGesture(NULL,path);
   1.180                      for (i = 0; i < SDL_numGestureTouches; i++)
   1.181 @@ -538,14 +538,14 @@
   1.182                  error = dollarRecognize(&inTouch->dollarPath,
   1.183                                          &bestTempl,inTouch);
   1.184                  if (bestTempl >= 0){
   1.185 -                    /*Send Event*/
   1.186 +                    /*Send Event */
   1.187                      unsigned long gestureId = inTouch->dollarTemplate[bestTempl].hash;
   1.188                      SDL_SendGestureDollar(inTouch,gestureId,error);
   1.189 -                    /*printf ("%s\n",);("Dollar error: %f\n",error);*/
   1.190 +                    /*printf ("%s\n",);("Dollar error: %f\n",error); */
   1.191                  }
   1.192              }
   1.193  #endif
   1.194 -            /*inTouch->gestureLast[j] = inTouch->gestureLast[inTouch->numDownFingers];*/
   1.195 +            /*inTouch->gestureLast[j] = inTouch->gestureLast[inTouch->numDownFingers]; */
   1.196              if (inTouch->numDownFingers > 0) {
   1.197                  inTouch->centroid.x = (inTouch->centroid.x*(inTouch->numDownFingers+1)-
   1.198                                         x)/inTouch->numDownFingers;
   1.199 @@ -575,22 +575,22 @@
   1.200  
   1.201              inTouch->centroid.x += dx/inTouch->numDownFingers;
   1.202              inTouch->centroid.y += dy/inTouch->numDownFingers;
   1.203 -            /*printf("Centrid : (%f,%f)\n",inTouch->centroid.x,inTouch->centroid.y);*/
   1.204 +            /*printf("Centrid : (%f,%f)\n",inTouch->centroid.x,inTouch->centroid.y); */
   1.205              if (inTouch->numDownFingers > 1) {
   1.206 -                SDL_FloatPoint lv; /*Vector from centroid to last x,y position*/
   1.207 -                SDL_FloatPoint v; /*Vector from centroid to current x,y position*/
   1.208 -                /*lv = inTouch->gestureLast[j].cv;*/
   1.209 +                SDL_FloatPoint lv; /*Vector from centroid to last x,y position */
   1.210 +                SDL_FloatPoint v; /*Vector from centroid to current x,y position */
   1.211 +                /*lv = inTouch->gestureLast[j].cv; */
   1.212                  lv.x = lastP.x - lastCentroid.x;
   1.213                  lv.y = lastP.y - lastCentroid.y;
   1.214                  lDist = (float)SDL_sqrt(lv.x*lv.x + lv.y*lv.y);
   1.215 -                /*printf("lDist = %f\n",lDist);*/
   1.216 +                /*printf("lDist = %f\n",lDist); */
   1.217                  v.x = x - inTouch->centroid.x;
   1.218                  v.y = y - inTouch->centroid.y;
   1.219 -                /*inTouch->gestureLast[j].cv = v;*/
   1.220 +                /*inTouch->gestureLast[j].cv = v; */
   1.221                  Dist = (float)SDL_sqrt(v.x*v.x+v.y*v.y);
   1.222 -                /* SDL_cos(dTheta) = (v . lv)/(|v| * |lv|)*/
   1.223 +                /* SDL_cos(dTheta) = (v . lv)/(|v| * |lv|) */
   1.224  
   1.225 -                /*Normalize Vectors to simplify angle calculation*/
   1.226 +                /*Normalize Vectors to simplify angle calculation */
   1.227                  lv.x/=lDist;
   1.228                  lv.y/=lDist;
   1.229                  v.x/=Dist;
   1.230 @@ -598,7 +598,7 @@
   1.231                  dtheta = (float)SDL_atan2(lv.x*v.y - lv.y*v.x,lv.x*v.x + lv.y*v.y);
   1.232  
   1.233                  dDist = (Dist - lDist);
   1.234 -                if (lDist == 0) {dDist = 0;dtheta = 0;} /*To avoid impossible values*/
   1.235 +                if (lDist == 0) {dDist = 0;dtheta = 0;} /*To avoid impossible values */
   1.236  
   1.237                  /*inTouch->gestureLast[j].dDist = dDist;
   1.238                  inTouch->gestureLast[j].dtheta = dtheta;
   1.239 @@ -609,19 +609,19 @@
   1.240                  knob.r += dDist/numDownFingers;
   1.241                  knob.ang += dtheta;
   1.242                  printf("thetaSum = %f, distSum = %f\n",gdtheta,gdDist);
   1.243 -                printf("id: %i dTheta = %f, dDist = %f\n",j,dtheta,dDist);*/
   1.244 +                printf("id: %i dTheta = %f, dDist = %f\n",j,dtheta,dDist); */
   1.245                  SDL_SendGestureMulti(inTouch,dtheta,dDist);
   1.246              }
   1.247              else {
   1.248                  /*inTouch->gestureLast[j].dDist = 0;
   1.249                  inTouch->gestureLast[j].dtheta = 0;
   1.250                  inTouch->gestureLast[j].cv.x = 0;
   1.251 -                inTouch->gestureLast[j].cv.y = 0;*/
   1.252 +                inTouch->gestureLast[j].cv.y = 0; */
   1.253              }
   1.254              /*inTouch->gestureLast[j].f.p.x = x;
   1.255              inTouch->gestureLast[j].f.p.y = y;
   1.256              break;
   1.257 -            pressure?*/
   1.258 +            pressure? */
   1.259          }
   1.260  
   1.261          if (event->type == SDL_FINGERDOWN) {
   1.262 @@ -632,7 +632,7 @@
   1.263              inTouch->centroid.y = (inTouch->centroid.y*(inTouch->numDownFingers - 1)+
   1.264                                     y)/inTouch->numDownFingers;
   1.265              /*printf("Finger Down: (%f,%f). Centroid: (%f,%f\n",x,y,
   1.266 -                 inTouch->centroid.x,inTouch->centroid.y);*/
   1.267 +                 inTouch->centroid.x,inTouch->centroid.y); */
   1.268  
   1.269  #ifdef ENABLE_DOLLAR
   1.270              inTouch->dollarPath.length = 0;