changeset 4659:063b9455bd1a

Added some files I had previosuly missed
author Jim Grandpre <jim.tla@gmail.com>
date Sun, 11 Jul 2010 01:15:39 -0400
parents 454385d76845
children b15e7017409b
files Makefile.in include/SDL_events.h include/SDL_gesture.h include/SDL_touch.h src/events/SDL_gesture.c src/events/SDL_gesture_c.h touchTest/gestureSDLTest.c touchTest/touchPong touchTest/touchSimp
diffstat 9 files changed, 316 insertions(+), 319 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile.in	Fri Jul 09 00:50:40 2010 -0700
+++ b/Makefile.in	Sun Jul 11 01:15:39 2010 -0400
@@ -44,7 +44,7 @@
 
 DIST = acinclude autogen.sh Borland.html Borland.zip BUGS build-scripts configure configure.in COPYING CREDITS include INSTALL Makefile.minimal Makefile.in README* sdl-config.in sdl.m4 sdl.pc.in SDL.spec SDL.spec.in src test TODO VisualC.html VisualC VisualCE Watcom-Win32.zip WhatsNew Xcode Xcode-iPhoneOS
 
-HDRS = SDL.h SDL_assert.h SDL_atomic.h SDL_audio.h SDL_compat.h SDL_cpuinfo.h SDL_endian.h SDL_error.h SDL_events.h SDL_haptic.h SDL_joystick.h SDL_keyboard.h SDL_keysym.h SDL_loadso.h SDL_main.h SDL_mouse.h SDL_mutex.h SDL_name.h SDL_opengl.h SDL_opengles.h SDL_pixels.h SDL_platform.h SDL_power.h SDL_quit.h SDL_rect.h SDL_revision.h SDL_rwops.h SDL_scancode.h SDL_stdinc.h SDL_surface.h SDL_syswm.h SDL_thread.h SDL_timer.h SDL_types.h SDL_version.h SDL_video.h begin_code.h close_code.h SDL_touch.h
+HDRS = SDL.h SDL_assert.h SDL_atomic.h SDL_audio.h SDL_compat.h SDL_cpuinfo.h SDL_endian.h SDL_error.h SDL_events.h SDL_haptic.h SDL_joystick.h SDL_keyboard.h SDL_keysym.h SDL_loadso.h SDL_main.h SDL_mouse.h SDL_mutex.h SDL_name.h SDL_opengl.h SDL_opengles.h SDL_pixels.h SDL_platform.h SDL_power.h SDL_quit.h SDL_rect.h SDL_revision.h SDL_rwops.h SDL_scancode.h SDL_stdinc.h SDL_surface.h SDL_syswm.h SDL_thread.h SDL_timer.h SDL_types.h SDL_version.h SDL_video.h begin_code.h close_code.h SDL_touch.h SDL_gesture.h
 
 LT_AGE      = @LT_AGE@
 LT_CURRENT  = @LT_CURRENT@
--- a/include/SDL_events.h	Fri Jul 09 00:50:40 2010 -0700
+++ b/include/SDL_events.h	Sun Jul 11 01:15:39 2010 -0400
@@ -36,6 +36,8 @@
 #include "SDL_mouse.h"
 #include "SDL_joystick.h"
 #include "SDL_quit.h"
+#include "SDL_gesture.h"
+#include "SDL_touch.h"
 
 #include "begin_code.h"
 /* Set up for C function definitions, even when using C++ */
@@ -95,6 +97,7 @@
 
     /*Gesture events*/
     SDL_DOLLARGESTURE     = 0x800,
+    SDL_DOLLARRECORD,
     SDL_MULTIGESTURE,
 
     /* Obsolete events */
@@ -359,9 +362,10 @@
     Uint32 type;        /**< ::SDL_DOLLARGESTURE */
     Uint32 windowID;    /**< The window with mouse focus, if any */
     Uint8 touchId;        /**< The touch device index */
-    Uint8 gestureId;
+    Uint8 padding1;
     Uint8 padding2;
     Uint8 padding3;
+    unsigned long gestureId;
     float error;
   /*
     //TODO: Enable to give location?
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/SDL_gesture.h	Sun Jul 11 01:15:39 2010 -0400
@@ -0,0 +1,90 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997-2010 Sam Lantinga
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+    Sam Lantinga
+    slouken@libsdl.org
+*/
+
+/**
+ *  \file SDL_gesture.h
+ *  
+ *  Include file for SDL gesture event handling.
+ */
+
+#ifndef _SDL_gesture_h
+#define _SDL_gesture_h
+
+#include "SDL_stdinc.h"
+#include "SDL_error.h"
+#include "SDL_video.h"
+
+#include "begin_code.h"
+/* Set up for C function definitions, even when using C++ */
+#ifdef __cplusplus
+/* *INDENT-OFF* */
+extern "C" {
+/* *INDENT-ON* */
+#endif
+
+
+/* Function prototypes */
+
+/**
+ *  \brief Begin Recording a gesture on the specified touch, or all touches (-1)
+ *
+ *
+ */
+  extern DECLSPEC int SDLCALL SDL_RecordGesture(int touchId);
+
+
+/**
+ *  \brief Save all currently loaded Dollar Gesture templates
+ *
+ *
+ */
+  extern DECLSPEC int SDLCALL SDL_SaveAllDollarTemplates(FILE *fp);
+
+/**
+ *  \brief Save a currently loaded Dollar Gesture template
+ *
+ *
+ */
+  extern DECLSPEC int 
+  SDLCALL SDL_SaveDollarTemplate(unsigned long gestureId,FILE *fp);
+
+
+/**
+ *  \brief Load Dollar Gesture templates from a file
+ *
+ *
+ */
+  extern DECLSPEC int SDLCALL SDL_LoadDollarTemplates(int touchId, FILE *fp);
+
+
+
+/* Ends C function definitions when using C++ */
+#ifdef __cplusplus
+/* *INDENT-OFF* */
+}
+/* *INDENT-ON* */
+#endif
+#include "close_code.h"
+
+#endif /* _SDL_gesture_h */
+
+/* vi: set ts=4 sw=4 expandtab: */
--- a/include/SDL_touch.h	Fri Jul 09 00:50:40 2010 -0700
+++ b/include/SDL_touch.h	Sun Jul 11 01:15:39 2010 -0400
@@ -23,7 +23,7 @@
 /**
  *  \file SDL_touch.h
  *  
- *  Include file for SDL mouse event handling.
+ *  Include file for SDL touch event handling.
  */
 
 #ifndef _SDL_touch_h
--- a/src/events/SDL_gesture.c	Fri Jul 09 00:50:40 2010 -0700
+++ b/src/events/SDL_gesture.c	Sun Jul 11 01:15:39 2010 -0400
@@ -13,8 +13,7 @@
     Lesser General Public License for more details.
 
     You should have received a copy of the GNU Lesser General Public
-    License along with this library; if not, write to the Free Software
-    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+    License along with this library; if not, write to the Free Software    Founation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
     Sam Lantinga
     slouken@libsdl.org
@@ -66,6 +65,10 @@
   DollarPath dollarPath;
 } TouchPoint;
 
+typedef struct {
+  Point path[DOLLARNPOINTS];
+  unsigned long hash;
+} DollarTemplate;
 
 typedef struct {
   int id;
@@ -75,11 +78,140 @@
   int numDownFingers;
 
   int numDollarTemplates;
-  Point dollarTemplate[MAXTEMPLATES][DOLLARNPOINTS];
+  DollarTemplate dollarTemplate[MAXTEMPLATES];
+
+  SDL_bool recording;
 } GestureTouch;
 
 GestureTouch gestureTouch[MAXTOUCHES];
 int numGestureTouches = 0;
+SDL_bool recordAll;
+
+int SDL_RecordGesture(int touchId) {
+  int i;
+  if(touchId < 0) recordAll = SDL_TRUE;
+  for(i = 0;i < numGestureTouches; i++) {
+    if((touchId < 0) || (gestureTouch[i].id == touchId)) {
+      gestureTouch[i].recording = SDL_TRUE;
+      if(touchId >= 0)
+	return 1;
+    }      
+  }
+  return (touchId < 0);
+}
+
+unsigned long SDL_HashDollar(Point* points) {
+  unsigned long hash = 5381;
+  int i;
+  for(i = 0;i < DOLLARNPOINTS; i++) { 
+    hash = ((hash<<5) + hash) + points[i].x;
+    hash = ((hash<<5) + hash) + points[i].y;
+  }
+  return hash;
+}
+
+int SaveTemplate(DollarTemplate *templ, FILE *fp) {
+  int i;
+  fprintf(fp,"%lu ",templ->hash);
+  for(i = 0;i < DOLLARNPOINTS;i++) {
+    fprintf(fp,"%i %i ",(int)templ->path[i].x,(int)templ->path[i].y);
+  }
+  fprintf(fp,"\n");
+}
+
+
+int SDL_SaveAllDollarTemplates(FILE *fp) {  
+  int i,j,rtrn = 0;
+  for(i = 0; i < numGestureTouches; i++) {
+    GestureTouch* touch = &gestureTouch[i];
+    for(j = 0;j < touch->numDollarTemplates; j++) {
+	rtrn += SaveTemplate(&touch->dollarTemplate[i],fp);
+    }
+  }
+  return rtrn;  
+}
+
+int SDL_SaveDollarTemplate(unsigned long gestureId, FILE *fp) {
+  int i,j;
+  for(i = 0; i < numGestureTouches; i++) {
+    GestureTouch* touch = &gestureTouch[i];
+    for(j = 0;j < touch->numDollarTemplates; j++) {
+      if(touch->dollarTemplate[i].hash == gestureId) {
+	return SaveTemplate(&touch->dollarTemplate[i],fp);
+      }
+    }
+  }
+}
+
+int SDL_LoadDollarTemplates(int touchId, FILE *fp) {
+  int i,loaded = 0;
+  GestureTouch *touch = NULL;
+  if(touchId >= 0) {
+    for(i = 0;i < numGestureTouches; i++)
+      if(gestureTouch[i].id == touchId)
+	touch = &gestureTouch[i];
+    if(touch == NULL) return -1;
+  }
+
+  while(!feof(fp)) {
+    DollarTemplate templ;
+    fscanf(fp,"%lu ",&templ.hash);
+    for(i = 0;i < DOLLARNPOINTS; i++) {		
+      int x,y;
+      if(fscanf(fp,"%i %i ",&x,&y) != 2) break;
+      templ.path[i].x = x;
+      templ.path[i].y = y;
+    }
+    fscanf(fp,"\n");
+
+    if(touchId >= 0) {
+      if(SDL_AddDollarGesture(touch,templ)) loaded++;
+    }
+    else {
+      for(i = 0;i < numGestureTouches; i++) {
+	if(gestureTouch[i].id == touchId) {
+	  touch = &gestureTouch[i];
+	  SDL_AddDollarGesture(touch,templ);
+	}
+      }
+      loaded++;
+    }
+  }
+
+  return 1; 
+}
+
+
+//path is an already sampled set of points
+//Returns the index of the gesture on success, or -1
+int SDL_AddDollarGesture(GestureTouch* inTouch,Point* path) {
+  if(inTouch == NULL) {
+    if(numGestureTouches == 0) return -1;
+    int i = 0;
+    for(i = 0;i < numGestureTouches; i++) {
+      inTouch = &gestureTouch[i];
+      if(inTouch->numDollarTemplates < MAXTEMPLATES) {
+	DollarTemplate *templ = 
+	  &inTouch->dollarTemplate[inTouch->numDollarTemplates];
+	memcpy(templ->path,path,DOLLARNPOINTS*sizeof(Point));
+	templ->hash = SDL_HashDollar(templ->path);
+	inTouch->numDollarTemplates++;
+      }
+    }
+    return inTouch->numDollarTemplates - 1;
+  }else if(inTouch->numDollarTemplates < MAXTEMPLATES) {
+    DollarTemplate *templ = 
+      &inTouch->dollarTemplate[inTouch->numDollarTemplates];
+    memcpy(templ->path,path,DOLLARNPOINTS*sizeof(Point));
+    templ->hash = SDL_HashDollar(templ->path);
+    inTouch->numDollarTemplates++;
+    return inTouch->numDollarTemplates - 1;
+  }
+  return -1;
+}
+
+
+
 
 float dollarDifference(Point* points,Point* templ,float ang) {
   //  Point p[DOLLARNPOINTS];
@@ -141,7 +273,7 @@
   int bestDiff = 10000;
   *bestTempl = -1;
   for(i = 0;i < touch->numDollarTemplates;i++) {
-    int diff = bestDollarDifference(points,touch->dollarTemplate[i]);
+    int diff = bestDollarDifference(points,touch->dollarTemplate[i].path);
     if(diff < bestDiff) {bestDiff = diff; *bestTempl = i;}
   }
   return bestDiff;
@@ -239,6 +371,8 @@
 
   gestureTouch[numGestureTouches].numDollarTemplates = 0;
 
+  gestureTouch[numGestureTouches].recording = SDL_FALSE;
+
   numGestureTouches++;
   return 0;
 }
@@ -277,6 +411,17 @@
   return SDL_PushEvent(&event) > 0;
 }
 
+
+int SDL_SendDollarRecord(GestureTouch* touch,int gestureId) {
+  SDL_Event event;
+  event.dgesture.type = SDL_DOLLARRECORD;
+  event.dgesture.touchId = touch->id;
+  event.dgesture.gestureId = gestureId;
+
+  return SDL_PushEvent(&event) > 0;
+}
+
+
 void SDL_GestureProcessEvent(SDL_Event* event)
 {
   if(event->type == SDL_FINGERMOTION || 
@@ -294,23 +439,44 @@
     
     for(j = 0;j<inTouch->numDownFingers;j++) {
       if(inTouch->gestureLast[j].f.id != event->tfinger.fingerId) continue;
-
+      //Finger Up
       if(event->type == SDL_FINGERUP) {
 	inTouch->numDownFingers--;
 
-	int bestTempl;
-	float error;
-	error = dollarRecognize(inTouch->gestureLast[j].dollarPath,
-				&bestTempl,inTouch);
-	if(bestTempl >= 0){
-	  //Send Event
-	  int gestureId = 0; //?
-	  SDL_SendGestureDollar(inTouch->id,gestureId,error);
-
-
-	  printf("Dollar error: %f\n",error);
+	if(inTouch->recording) {
+	  inTouch->recording = SDL_FALSE;
+	  Point path[DOLLARNPOINTS];
+	  dollarNormalize(inTouch->gestureLast[j].dollarPath,path);
+	  int index;
+	  if(recordAll) {
+	    index = SDL_AddDollarGesture(NULL,path);
+	    int i;
+	    for(i = 0;i < numGestureTouches; i++)
+	      gestureTouch[i].recording = SDL_FALSE;
+	  }
+	  else {
+	    index = SDL_AddDollarGesture(inTouch,path);
+	  }
+	  
+	  if(index >= 0) {
+	    SDL_SendDollarRecord(inTouch,inTouch->dollarTemplate[index].hash);
+	  }
+	  else {
+	    SDL_SendDollarRecord(inTouch,-1);
+	  }
 	}
-
+	else {	
+	  int bestTempl;
+	  float error;
+	  error = dollarRecognize(inTouch->gestureLast[j].dollarPath,
+				  &bestTempl,inTouch);
+	  if(bestTempl >= 0){
+	    //Send Event
+	    int gestureId = inTouch->dollarTemplate[bestTempl].hash;
+	    SDL_SendGestureDollar(inTouch,gestureId,error);
+	    printf("Dollar error: %f\n",error);
+	  }
+	} 
 	inTouch->gestureLast[j] = inTouch->gestureLast[inTouch->numDownFingers];
 	break;
       }
--- a/src/events/SDL_gesture_c.h	Fri Jul 09 00:50:40 2010 -0700
+++ b/src/events/SDL_gesture_c.h	Sun Jul 11 01:15:39 2010 -0400
@@ -26,6 +26,7 @@
 
 extern void SDL_GestureProcessEvent(SDL_Event* event);
 
+extern int SDL_RecordGesture(int touchId);
 
 #endif /* _SDL_gesture_c_h */
 
--- a/touchTest/gestureSDLTest.c	Fri Jul 09 00:50:40 2010 -0700
+++ b/touchTest/gestureSDLTest.c	Sun Jul 11 01:15:39 2010 -0400
@@ -2,6 +2,7 @@
 #include <SDL.h>
 #include <math.h>
 #include <SDL_touch.h>
+#include <SDL_gesture.h>
 
 #define PI 3.1415926535897
 #define PHI ((sqrt(5)-1)/2)
@@ -159,171 +160,6 @@
   
 }
 
-void drawDollarPath(SDL_Surface* screen,Point* points,int numPoints,
-		    int rad,unsigned int col){
-  int i;
-  for(i=0;i<numPoints;i++) {
-    drawCircle(screen,points[i].x+screen->w/2,
-	       points[i].y+screen->h/2,
-	       rad,col);
-  }
-}
-
-float dollarDifference(Point* points,Point* templ,float ang) {
-  //  Point p[DOLLARNPOINTS];
-  float dist = 0;
-  Point p;
-  int i;
-  for(i = 0; i < DOLLARNPOINTS; i++) {
-    p.x = points[i].x * cos(ang) - points[i].y * sin(ang);
-    p.y = points[i].x * sin(ang) + points[i].y * cos(ang);
-    dist += sqrt((p.x-templ[i].x)*(p.x-templ[i].x)+
-		 (p.y-templ[i].y)*(p.y-templ[i].y));
-  }
-  return dist/DOLLARNPOINTS;
-  
-}
-
-float bestDollarDifference(Point* points,Point* templ) {
-  //------------BEGIN DOLLAR BLACKBOX----------------//
-  //-TRANSLATED DIRECTLY FROM PSUDEO-CODE AVAILABLE AT-//
-  //-"http://depts.washington.edu/aimgroup/proj/dollar/"-//
-  float ta = -PI/4;
-  float tb = PI/4;
-  float dt = PI/90;
-  float x1 = PHI*ta + (1-PHI)*tb;
-  float f1 = dollarDifference(points,templ,x1);
-  float x2 = (1-PHI)*ta + PHI*tb;
-  float f2 = dollarDifference(points,templ,x2);
-  while(abs(ta-tb) > dt) {
-    if(f1 < f2) {
-      tb = x2;
-      x2 = x1;
-      f2 = f1;
-      x1 = PHI*ta + (1-PHI)*tb;
-      f1 = dollarDifference(points,templ,x1);
-    }
-    else {
-      ta = x1;
-      x1 = x2;
-      f1 = f2;
-      x2 = (1-PHI)*ta + PHI*tb;
-      f2 = dollarDifference(points,templ,x2);
-    }
-  }
-  /*
-  if(f1 <= f2)
-    printf("Min angle (x1): %f\n",x1);
-  else if(f1 >  f2)
-    printf("Min angle (x2): %f\n",x2);
-  */
-  return SDL_min(f1,f2);  
-}
-
-float dollarRecognize(SDL_Surface* screen, DollarPath path,int *bestTempl) {
-
-  Point points[DOLLARNPOINTS];
-  int numPoints = dollarNormalize(path,points);
-  int i;
-  
-  int k;
-  /*
-  for(k = 0;k<DOLLARNPOINTS;k++) {
-    printf("(%f,%f)\n",points[k].x,
-	   points[k].y);
-  }
-  */
-  drawDollarPath(screen,points,numPoints,-15,0xFF6600);
-
-  int bestDiff = 10000;
-  *bestTempl = -1;
-  for(i = 0;i < numDollarTemplates;i++) {
-    int diff = bestDollarDifference(points,dollarTemplate[i]);
-    if(diff < bestDiff) {bestDiff = diff; *bestTempl = i;}
-  }
-  return bestDiff;
-}
-
-//DollarPath contains raw points, plus (possibly) the calculated length
-int dollarNormalize(DollarPath path,Point *points) {
-  int i;
-  //Calculate length if it hasn't already been done
-  if(path.length <= 0) {
-    for(i=1;i<path.numPoints;i++) {
-      float dx = path.p[i  ].x - 
-	         path.p[i-1].x;
-      float dy = path.p[i  ].y - 
-	         path.p[i-1].y;
-      path.length += sqrt(dx*dx+dy*dy);
-    }
-  }
-
-
-  //Resample
-  float interval = path.length/(DOLLARNPOINTS - 1);
-  float dist = 0;
-
-  int numPoints = 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)+
-		   (path.p[i-1].y-path.p[i].y)*(path.p[i-1].y-path.p[i].y));
-    //printf("d = %f dist = %f/%f\n",d,dist,interval);
-    while(dist + d > interval) {
-      points[numPoints].x = path.p[i-1].x + 
-	((interval-dist)/d)*(path.p[i].x-path.p[i-1].x);
-      points[numPoints].y = path.p[i-1].y + 
-	((interval-dist)/d)*(path.p[i].y-path.p[i-1].y);
-      centroid.x += points[numPoints].x;
-      centroid.y += points[numPoints].y;
-      numPoints++;
-
-      dist -= interval;
-    }
-    dist += d;
-  }
-  if(numPoints < 1) return 0;
-  centroid.x /= numPoints;
-  centroid.y /= numPoints;
- 
-  //printf("Centroid (%f,%f)",centroid.x,centroid.y);
-  //Rotate Points so point 0 is left of centroid and solve for the bounding box
-  float xmin,xmax,ymin,ymax;
-  xmin = centroid.x;
-  xmax = centroid.x;
-  ymin = centroid.y;
-  ymax = centroid.y;
-  
-  float ang = atan2(centroid.y - points[0].y,
-		    centroid.x - points[0].x);
-
-  for(i = 0;i<numPoints;i++) {					       
-    float px = points[i].x;
-    float py = points[i].y;
-    points[i].x = (px - centroid.x)*cos(ang) - 
-                  (py - centroid.y)*sin(ang) + centroid.x;
-    points[i].y = (px - centroid.x)*sin(ang) + 
-                  (py - centroid.y)*cos(ang) + centroid.y;
-
-
-    if(points[i].x < xmin) xmin = points[i].x;
-    if(points[i].x > xmax) xmax = points[i].x; 
-    if(points[i].y < ymin) ymin = points[i].y;
-    if(points[i].y > ymax) ymax = points[i].y;
-  }
-
-  //Scale points to DOLLARSIZE, and translate to the origin
-  float w = xmax-xmin;
-  float h = ymax-ymin;
-
-  for(i=0;i<numPoints;i++) {
-    points[i].x = (points[i].x - centroid.x)*DOLLARSIZE/w;
-    points[i].y = (points[i].y - centroid.y)*DOLLARSIZE/h;
-  }  
-  return numPoints;
-}
-
 void DrawScreen(SDL_Surface* screen, int h)
 {
   int x, y, xm,ym,c;
@@ -369,138 +205,20 @@
       //SDL_Finger* inFinger = SDL_GetFinger(inTouch,event.tfinger.fingerId);
 	    
       float x = ((float)event.tfinger.x)/inTouch->xres;
-      float y = ((float)event.tfinger.y)/inTouch->yres;
-      int j,empty = -1;
-      
-      for(j = 0;j<MAXFINGERS;j++) {
-	if(gestureLast[j].f.id == event.tfinger.fingerId) {
-	  if(event.type == SDL_FINGERUP) {
-	    numDownFingers--;
-	    if(numDownFingers <= 1) {
-	      gdtheta = 0;
-	      gdDist = 0;
-	    }
-	    if(!keystat[32]){ //spacebar
-	      int bestTempl;
-	      float error = dollarRecognize(screen,dollarPath[j],&bestTempl);
-	      if(bestTempl >= 0){
-		drawDollarPath(screen,dollarTemplate[bestTempl]
-			       ,DOLLARNPOINTS,-15,0x0066FF);		
-		printf("Dollar error: %f\n",error);
-	      }
-	      
-	    }
-	    else if(numDollarTemplates < MAXTEMPLATES) {
-	      
-	      dollarNormalize(dollarPath[j],
-			      dollarTemplate[numDollarTemplates]);
-	      /*
-	      int k;	      
-	      for(k = 0;k<DOLLARNPOINTS;k++) {
-		printf("(%f,%f)\n",dollarTemplate[numDollarTemplates][i].x,
-		       dollarTemplate[numDollarTemplates][i].y);
-		       }*/
-	      numDollarTemplates++;	      
-	    }
-
-	    gestureLast[j].f.id = -1;
-	    break;
-	  }
-	  else {
-	    dollarPath[j].p[dollarPath[j].numPoints].x = x;
-	    dollarPath[j].p[dollarPath[j].numPoints].y = y;
-	    float dx = (dollarPath[j].p[dollarPath[j].numPoints  ].x-
-			dollarPath[j].p[dollarPath[j].numPoints-1].x);
-	    float dy = (dollarPath[j].p[dollarPath[j].numPoints  ].y-
-			dollarPath[j].p[dollarPath[j].numPoints-1].y);
-	    dollarPath[j].length += sqrt(dx*dx + dy*dy);
-
-	    dollarPath[j].numPoints++;
-
-	    centroid.x = centroid.x + dx/numDownFingers;
-	    centroid.y = centroid.y + dy/numDownFingers;    
-	    if(numDownFingers > 1) {
-	      Point lv; //Vector from centroid to last x,y position
-	      Point v; //Vector from centroid to current x,y position
-	      lv.x = gestureLast[j].cv.x;
-	      lv.y = gestureLast[j].cv.y;
-	      float lDist = sqrt(lv.x*lv.x + lv.y*lv.y);
-	      
-	      v.x = x - centroid.x;
-	      v.y = y - centroid.y;
-	      gestureLast[j].cv = v;
-	      float Dist = sqrt(v.x*v.x+v.y*v.y);
-	      // cos(dTheta) = (v . lv)/(|v| * |lv|)
-	      
-	      lv.x/=lDist;
-	      lv.y/=lDist;
-	      v.x/=Dist;
-	      v.y/=Dist;
-	      float dtheta = atan2(lv.x*v.y - lv.y*v.x,lv.x*v.x + lv.y*v.y);
-	      
-	      float dDist = (lDist - Dist);	      
-	      
-	      gestureLast[j].dDist = dDist;
-	      gestureLast[j].dtheta = dtheta;
-
-	      //gdtheta = gdtheta*.9 + dtheta*.1;
-	      //gdDist  =  gdDist*.9 +  dDist*.1
-	      gdtheta += dtheta;
-	      gdDist += dDist;
-
-	      //printf("thetaSum = %f, distSum = %f\n",gdtheta,gdDist);
-	      //printf("id: %i dTheta = %f, dDist = %f\n",j,dtheta,dDist);
-	    }
-	    else {
-	      gestureLast[j].dDist = 0;
-	      gestureLast[j].dtheta = 0;
-	      gestureLast[j].cv.x = 0;
-	      gestureLast[j].cv.y = 0;
-	    }
-	    gestureLast[j].f.p.x = x;
-	    gestureLast[j].f.p.y = y;
-	    break;
-	    //pressure?
-	  }	  
-	}
-	else if(gestureLast[j].f.id == -1 && empty == -1) {
-	  empty = j;
-	}
-      }
-      
-      if(j >= MAXFINGERS && empty >= 0) {
-	//	printf("Finger Down!!!\n");
-	numDownFingers++;
-	centroid.x = (centroid.x*(numDownFingers - 1) + x)/numDownFingers;
-	centroid.y = (centroid.y*(numDownFingers - 1) + y)/numDownFingers;
-	
-	j = empty;
-	gestureLast[j].f.id = event.tfinger.fingerId;
-	gestureLast[j].f.p.x  = x;
-	gestureLast[j].f.p.y  = y;
-	
-	
-	dollarPath[j].length = 0;
-	dollarPath[j].p[0].x = x;
-	dollarPath[j].p[0].y = y;
-	dollarPath[j].numPoints = 1;
-      }
+      float y = ((float)event.tfinger.y)/inTouch->yres;      
       
       //draw the touch:
       
-      if(gestureLast[j].f.id < 0) continue; //Finger up. Or some error...
-      
-      unsigned int c = colors[gestureLast[j].f.id%7]; 
+      unsigned int c = colors[event.tfinger.touchId%7]; 
       unsigned int col = 
 	((unsigned int)(c*(.1+.85))) |
 	((unsigned int)((0xFF*(1-((float)age)/EVENT_BUF_SIZE))) & 0xFF)<<24;
-      x = gestureLast[j].f.p.x;
-      y = gestureLast[j].f.p.y;
+
       if(event.type == SDL_FINGERMOTION)
 	drawCircle(screen,x*screen->w,y*screen->h,5,col);
       else if(event.type == SDL_FINGERDOWN)
 	drawCircle(screen,x*screen->w,y*screen->h,-10,col);     
-      
+      /*      
       //if there is a centroid, draw it
       if(numDownFingers > 1) {
 	unsigned int col = 
@@ -508,6 +226,7 @@
 	  ((unsigned int)((0xFF*(1-((float)age)/EVENT_BUF_SIZE))) & 0xFF)<<24;
 	drawCircle(screen,centroid.x*screen->w,centroid.y*screen->h,5,col);
       }
+      */
     }
   }
   
@@ -582,6 +301,22 @@
 	  case SDL_KEYDOWN:
 	    //printf("%i\n",event.key.keysym.sym);
 	    keystat[event.key.keysym.sym] = 1;
+	    if(event.key.keysym.sym == 32) {
+	      SDL_RecordGesture(-1);
+	    }
+	    else if(event.key.keysym.sym == 115) {
+	      FILE *fp;
+	      fp = fopen("gestureSave","w");
+	      SDL_SaveAllDollarTemplates(fp);
+	      fclose(fp);
+	    }
+	    else if(event.key.keysym.sym == 108) {
+	      FILE *fp;
+	      fp = fopen("gestureSave","r");
+	      printf("Loaded: %i\n",SDL_LoadDollarTemplates(-1,fp));
+	      fclose(fp);
+	    }
+	    
 	    //keypress = 1;
 	    break;
 	  case SDL_KEYUP:
@@ -665,20 +400,21 @@
 	    knob.p.y = event.mgesture.y;
 	    knob.ang += event.mgesture.dTheta;
 	    knob.r += event.mgesture.dDist;
+	    break;
+	  case SDL_DOLLARGESTURE:
+	    printf("Gesture %lu performed, error: %f\n",
+		   event.dgesture.gestureId,
+		   event.dgesture.error);
+	    break;
+	  case SDL_DOLLARRECORD:
+	    printf("Recorded gesture: %lu\n",event.dgesture.gestureId);
+	    break;
 	  }
-      
-    
-	
-	//And draw
-	
       }
-    DrawScreen(screen,h);
-    //printf("c: (%f,%f)\n",centroid.x,centroid.y);
-    //printf("numDownFingers: %i\n",numDownFingers);
-    //for(i=0;i<512;i++) 
-    // if(keystat[i]) printf("%i\n",i);
-      
-    
+    DrawScreen(screen,h);    
+    for(i = 0; i < 256; i++) 
+      if(keystat[i]) 
+	printf("Key %i down\n",i);
   }  
   SDL_Quit();
   
Binary file touchTest/touchPong has changed
Binary file touchTest/touchSimp has changed