changeset 4685:e0c3b09368a6

Fixed Dollar Recognition.
author Jim Grandpre <jim.tla@gmail.com>
date Sat, 07 Aug 2010 11:32:11 -0400
parents f47c2640c667
children 463cd74304b9
files src/events/SDL_gesture.c
diffstat 1 files changed, 32 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/events/SDL_gesture.c	Fri Aug 06 01:55:38 2010 -0400
+++ b/src/events/SDL_gesture.c	Sat Aug 07 11:32:11 2010 -0400
@@ -90,6 +90,15 @@
 int numGestureTouches = 0;
 SDL_bool recordAll;
 
+void SDL_PrintPath(Point *path) {
+  int i;
+  printf("Path:");
+  for(i=0;i<DOLLARNPOINTS;i++) {
+    printf(" (%f,%f)",path[i].x,path[i].y);
+  }
+  printf("\n");
+}
+
 int SDL_RecordGesture(SDL_TouchID touchId) {
   int i;
   if(touchId < 0) recordAll = SDL_TRUE;
@@ -283,6 +292,7 @@
 int dollarNormalize(DollarPath path,Point *points) {
   int i;
   //Calculate length if it hasn't already been done
+  printf("length: %f\n",path.length);
   if(path.length <= 0) {
     for(i=1;i<path.numPoints;i++) {
       float dx = path.p[i  ].x - 
@@ -292,14 +302,16 @@
       path.length += sqrt(dx*dx+dy*dy);
     }
   }
-
+  printf("New length: %f\n",path.length);
 
   //Resample
   float interval = path.length/(DOLLARNPOINTS - 1);
-  float dist = 0;
+  float dist = interval;
 
   int numPoints = 0;
-  Point centroid; centroid.x = 0;centroid.y = 0;
+  Point centroid; 
+  centroid.x = 0;centroid.y = 0;
+  
   //printf("(%f,%f)\n",path.p[path.numPoints-1].x,path.p[path.numPoints-1].y);
   for(i = 1;i < path.numPoints;i++) {
     float d = sqrt((path.p[i-1].x-path.p[i].x)*(path.p[i-1].x-path.p[i].x)+
@@ -318,7 +330,14 @@
     }
     dist += d;
   }
-  if(numPoints < 1) return 0;
+  if(numPoints < DOLLARNPOINTS-1) {
+    printf("ERROR: NumPoints = %i\n",numPoints); 
+    return 0;
+  }
+  //copy the last point
+  points[DOLLARNPOINTS-1] = path.p[path.numPoints-1];
+  numPoints = DOLLARNPOINTS;
+
   centroid.x /= numPoints;
   centroid.y /= numPoints;
  
@@ -363,6 +382,7 @@
 	
 	Point points[DOLLARNPOINTS];
 	int numPoints = dollarNormalize(path,points);
+	SDL_PrintPath(points);
 	int i;
 	
 	int bestDiff = 10000;
@@ -467,6 +487,7 @@
 	inTouch->recording = SDL_FALSE;
 	Point path[DOLLARNPOINTS];
 	dollarNormalize(inTouch->dollarPath,path);
+	SDL_PrintPath(path);
 	int index;
 	if(recordAll) {
 	  index = SDL_AddDollarGesture(NULL,path);
@@ -515,7 +536,11 @@
       if(path->numPoints < MAXPATHSIZE) {
 	path->p[path->numPoints].x = inTouch->centroid.x;
 	path->p[path->numPoints].y = inTouch->centroid.y;
-	path->length += sqrt(dx*dx + dy*dy);
+	float pathDx = 
+	  (path->p[path->numPoints].x-path->p[path->numPoints-1].x);
+	float pathDy = 
+	  (path->p[path->numPoints].y-path->p[path->numPoints-1].y);
+	path->length += sqrt(pathDx*pathDx + pathDy*pathDy);
 	path->numPoints++;
       }
 #endif
@@ -526,7 +551,8 @@
       lastCentroid = inTouch->centroid;
       
       inTouch->centroid.x += dx/inTouch->numDownFingers;
-      inTouch->centroid.y += dy/inTouch->numDownFingers;    
+      inTouch->centroid.y += dy/inTouch->numDownFingers;
+      //printf("Centrid : (%f,%f)\n",inTouch->centroid.x,inTouch->centroid.y);
       if(inTouch->numDownFingers > 1) {
 	Point lv; //Vector from centroid to last x,y position
 	Point v; //Vector from centroid to current x,y position