Added multi-finger gestures
authorJim Grandpre
Tue, 06 Jul 2010 02:05:27 -0700
changeset 4656b5007b7995c6
parent 4655 4c94f2023d62
child 4657 eed063a0bf5b
Added multi-finger gestures
touchTest/gestureTest.c
     1.1 --- a/touchTest/gestureTest.c	Fri Jun 18 01:43:02 2010 -0400
     1.2 +++ b/touchTest/gestureTest.c	Tue Jul 06 02:05:27 2010 -0700
     1.3 @@ -40,6 +40,12 @@
     1.4    int id;
     1.5  } Finger;
     1.6  
     1.7 +typedef struct {
     1.8 +  Finger f;
     1.9 +  Point cv;
    1.10 +  float dtheta,dDist;
    1.11 +} TouchPoint;
    1.12 + 
    1.13  typedef struct { //dt + s
    1.14    Point d,s; //direction, start
    1.15    int points;
    1.16 @@ -53,10 +59,16 @@
    1.17    Point p[EVENT_BUF_SIZE]; //To be safe
    1.18  } DollarPath;
    1.19  
    1.20 +typedef struct {
    1.21 +  float ang,r;
    1.22 +  Point p;
    1.23 +} Knob;
    1.24 +
    1.25 +Knob knob;
    1.26  
    1.27  Finger finger[MAXFINGERS];
    1.28  
    1.29 -Finger gestureLast[MAXFINGERS];
    1.30 +
    1.31  DollarPath dollarPath[MAXFINGERS];
    1.32  
    1.33  #define MAXTEMPLATES 4
    1.34 @@ -119,22 +131,7 @@
    1.35  
    1.36    float a;
    1.37    int tx;
    1.38 -  /*
    1.39 -  for(a=0;a<PI/2;a+=1.f/(float)abs(r))
    1.40 -  {
    1.41 -    if(r > 0) { //r > 0 ==> filled circle
    1.42 -      for(tx=x-r*cos(a);tx<x+r*cos(a);tx++) {
    1.43 -	setpix(screen,tx,(int)(y+r*sin(a)),c);
    1.44 -	setpix(screen,tx,(int)(y-r*sin(a)),c);
    1.45 -      }
    1.46 -    }    else {
    1.47 -      //Draw Outline
    1.48 -      setpix(screen,(int)(x+r*cos(a)),(int)(y+r*sin(a)),c);
    1.49 -      setpix(screen,(int)(x-r*cos(a)),(int)(y+r*sin(a)),c);
    1.50 -      setpix(screen,(int)(x+r*cos(a)),(int)(y-r*sin(a)),c);
    1.51 -      setpix(screen,(int)(x-r*cos(a)),(int)(y-r*sin(a)),c);
    1.52 -    }
    1.53 -    }*/
    1.54 +  
    1.55    int ty;
    1.56    float xr;
    1.57    for(ty = -abs(r);ty <= abs(r);ty++) {
    1.58 @@ -151,6 +148,16 @@
    1.59    }
    1.60  }
    1.61  
    1.62 +void drawKnob(SDL_Surface* screen,Knob k) {
    1.63 +  printf("Knob: x = %f, y = %f, r = %f, a = %f\n",k.p.x,k.p.y,k.r,k.ang);
    1.64 + 
    1.65 +  drawCircle(screen,k.p.x*screen->w,k.p.y*screen->h,k.r*screen->w,0xFFFFFF);
    1.66 +  
    1.67 +  drawCircle(screen,(k.p.x+k.r/2*cos(k.ang))*screen->w,
    1.68 +  	            (k.p.y+k.r/2*sin(k.ang))*screen->h,k.r/4*screen->w,0);
    1.69 +  
    1.70 +}
    1.71 +
    1.72  void drawDollarPath(SDL_Surface* screen,Point* points,int numPoints,
    1.73  		    int rad,unsigned int col){
    1.74    int i;
    1.75 @@ -203,8 +210,13 @@
    1.76        f2 = dollarDifference(points,templ,x2);
    1.77      }
    1.78    }
    1.79 -  return SDL_min(f1,f2);
    1.80 -  
    1.81 +  /*
    1.82 +  if(f1 <= f2)
    1.83 +    printf("Min angle (x1): %f\n",x1);
    1.84 +  else if(f1 >  f2)
    1.85 +    printf("Min angle (x2): %f\n",x2);
    1.86 +  */
    1.87 +  return SDL_min(f1,f2);  
    1.88  }
    1.89  
    1.90  float dollarRecognize(SDL_Surface* screen, DollarPath path,int *bestTempl) {
    1.91 @@ -333,15 +345,20 @@
    1.92      }
    1.93    drawCircle(screen,mousx,mousy,-30,0xFFFFFF);
    1.94    drawLine(screen,0,0,screen->w,screen->h,0xFFFFFF);
    1.95 +
    1.96    int i;
    1.97  //draw Touch History
    1.98 +  TouchPoint gestureLast[MAXFINGERS];
    1.99 +  //printf("------------------Start History------------------\n");
   1.100    for(i = 0;i < MAXFINGERS;i++) {
   1.101 -    gestureLast[i].id = -1;
   1.102 -#ifdef DRAW_VECTOR_EST
   1.103 -    gestureLine[i].points = 0;
   1.104 -#endif
   1.105 +    gestureLast[i].f.id = -1;
   1.106    }
   1.107 -  for(i = SDL_max(0,eventWrite - EVENT_BUF_SIZE);i != eventWrite;i++) {
   1.108 +  int numDownFingers = 0;
   1.109 +  Point centroid;
   1.110 +  float gdtheta,gdDist;
   1.111 +
   1.112 +
   1.113 +  for(i = SDL_max(0,eventWrite - EVENT_BUF_SIZE);i < eventWrite;i++) {
   1.114      SDL_Event event = events[i&(EVENT_BUF_SIZE-1)];
   1.115      int age = eventWrite - i - 1;
   1.116      if(event.type == SDL_FINGERMOTION || 
   1.117 @@ -355,28 +372,20 @@
   1.118        int j,empty = -1;
   1.119        
   1.120        for(j = 0;j<MAXFINGERS;j++) {
   1.121 -	if(gestureLast[j].id == event.tfinger.fingerId) {
   1.122 +	if(gestureLast[j].f.id == event.tfinger.fingerId) {
   1.123  	  if(event.type == SDL_FINGERUP) {
   1.124 -#ifdef DRAW_VECTOR_EST
   1.125 -	    if(gestureLine[j].points > 0)
   1.126 -	      drawLine(screen,
   1.127 -		     gestureLine[j].s.x*screen->w,
   1.128 -		     gestureLine[j].s.y*screen->h,
   1.129 -		     (gestureLine[j].s.x +50*gestureLine[j].d.x)*screen->w,
   1.130 -		     (gestureLine[j].s.y +50*gestureLine[j].d.y)*screen->h,
   1.131 -		     0xFF00);
   1.132 -
   1.133 -	    gestureLine[j].points = 0;
   1.134 -#endif
   1.135 -
   1.136 +	    numDownFingers--;
   1.137 +	    if(numDownFingers <= 1) {
   1.138 +	      gdtheta = 0;
   1.139 +	      gdDist = 0;
   1.140 +	    }
   1.141  	    if(!keystat[32]){ //spacebar
   1.142  	      int bestTempl;
   1.143  	      float error = dollarRecognize(screen,dollarPath[j],&bestTempl);
   1.144  	      if(bestTempl >= 0){
   1.145  		drawDollarPath(screen,dollarTemplate[bestTempl]
   1.146 -			       ,DOLLARNPOINTS,-15,0x0066FF);
   1.147 -		
   1.148 -		printf("ERROR: %f\n",error);
   1.149 +			       ,DOLLARNPOINTS,-15,0x0066FF);		
   1.150 +		printf("Dollar error: %f\n",error);
   1.151  	      }
   1.152  	      
   1.153  	    }
   1.154 @@ -384,8 +393,8 @@
   1.155  	      
   1.156  	      dollarNormalize(dollarPath[j],
   1.157  			      dollarTemplate[numDollarTemplates]);
   1.158 -	      int k;
   1.159  	      /*
   1.160 +	      int k;	      
   1.161  	      for(k = 0;k<DOLLARNPOINTS;k++) {
   1.162  		printf("(%f,%f)\n",dollarTemplate[numDollarTemplates][i].x,
   1.163  		       dollarTemplate[numDollarTemplates][i].y);
   1.164 @@ -393,94 +402,111 @@
   1.165  	      numDollarTemplates++;	      
   1.166  	    }
   1.167  
   1.168 -	    gestureLast[j].id = -1;
   1.169 +	    gestureLast[j].f.id = -1;
   1.170  	    break;
   1.171  	  }
   1.172  	  else {
   1.173 -#ifdef DRAW_VECTOR_EST
   1.174 -	    if(gestureLine[j].points == 1) {
   1.175 -	      gestureLine[j].d.x = x - gestureLine[j].s.x;
   1.176 -	      gestureLine[j].d.y = y - gestureLine[j].s.y;
   1.177 -	    }
   1.178 -
   1.179 -	    gestureLine[j].s.x = gestureLine[j].s.x*gestureLine[j].points+x;
   1.180 -	    gestureLine[j].s.y = gestureLine[j].s.y*gestureLine[j].points+y;
   1.181 -
   1.182 -	    gestureLine[j].d.x = gestureLine[j].d.x*gestureLine[j].points+
   1.183 -	      x - gestureLast[j].p.x;
   1.184 -	    gestureLine[j].d.y = gestureLine[j].d.y*gestureLine[j].points+
   1.185 -	      y - gestureLast[j].p.y;;
   1.186 -
   1.187 -
   1.188 -	    gestureLine[j].points++;
   1.189 -	    
   1.190 -	    gestureLine[j].s.x /= gestureLine[j].points;
   1.191 -	    gestureLine[j].s.y /= gestureLine[j].points;
   1.192 -
   1.193 -	    gestureLine[j].d.x /= gestureLine[j].points;
   1.194 -	    gestureLine[j].d.y /= gestureLine[j].points;	    
   1.195 -#endif
   1.196 -
   1.197  	    dollarPath[j].p[dollarPath[j].numPoints].x = x;
   1.198  	    dollarPath[j].p[dollarPath[j].numPoints].y = y;
   1.199 -	    float dx = (dollarPath[j].p[dollarPath[j].numPoints-1].x-
   1.200 -		      dollarPath[j].p[dollarPath[j].numPoints  ].x);
   1.201 -	    float dy = (dollarPath[j].p[dollarPath[j].numPoints-1].y-
   1.202 -		      dollarPath[j].p[dollarPath[j].numPoints  ].y);
   1.203 +	    float dx = (dollarPath[j].p[dollarPath[j].numPoints  ].x-
   1.204 +			dollarPath[j].p[dollarPath[j].numPoints-1].x);
   1.205 +	    float dy = (dollarPath[j].p[dollarPath[j].numPoints  ].y-
   1.206 +			dollarPath[j].p[dollarPath[j].numPoints-1].y);
   1.207  	    dollarPath[j].length += sqrt(dx*dx + dy*dy);
   1.208  
   1.209  	    dollarPath[j].numPoints++;
   1.210 -	    
   1.211  
   1.212 -	    gestureLast[j].p.x = x;
   1.213 -	    gestureLast[j].p.y = y;
   1.214 +	    centroid.x = centroid.x + dx/numDownFingers;
   1.215 +	    centroid.y = centroid.y + dy/numDownFingers;    
   1.216 +	    if(numDownFingers > 1) {
   1.217 +	      Point lv; //Vector from centroid to last x,y position
   1.218 +	      Point v; //Vector from centroid to current x,y position
   1.219 +	      lv.x = gestureLast[j].cv.x;
   1.220 +	      lv.y = gestureLast[j].cv.y;
   1.221 +	      float lDist = sqrt(lv.x*lv.x + lv.y*lv.y);
   1.222 +	      
   1.223 +	      v.x = x - centroid.x;
   1.224 +	      v.y = y - centroid.y;
   1.225 +	      gestureLast[j].cv = v;
   1.226 +	      float Dist = sqrt(v.x*v.x+v.y*v.y);
   1.227 +	      // cos(dTheta) = (v . lv)/(|v| * |lv|)
   1.228 +	      
   1.229 +	      lv.x/=lDist;
   1.230 +	      lv.y/=lDist;
   1.231 +	      v.x/=Dist;
   1.232 +	      v.y/=Dist;
   1.233 +	      float dtheta = atan2(lv.x*v.y - lv.y*v.x,lv.x*v.x + lv.y*v.y);
   1.234 +	      
   1.235 +	      float dDist = (lDist - Dist);	      
   1.236 +	      
   1.237 +	      gestureLast[j].dDist = dDist;
   1.238 +	      gestureLast[j].dtheta = dtheta;
   1.239 +
   1.240 +	      //gdtheta = gdtheta*.9 + dtheta*.1;
   1.241 +	      //gdDist  =  gdDist*.9 +  dDist*.1
   1.242 +	      gdtheta += dtheta;
   1.243 +	      gdDist += dDist;
   1.244 +
   1.245 +	      //printf("thetaSum = %f, distSum = %f\n",gdtheta,gdDist);
   1.246 +	      //printf("id: %i dTheta = %f, dDist = %f\n",j,dtheta,dDist);
   1.247 +	    }
   1.248 +	    else {
   1.249 +	      gestureLast[j].dDist = 0;
   1.250 +	      gestureLast[j].dtheta = 0;
   1.251 +	      gestureLast[j].cv.x = 0;
   1.252 +	      gestureLast[j].cv.y = 0;
   1.253 +	    }
   1.254 +	    gestureLast[j].f.p.x = x;
   1.255 +	    gestureLast[j].f.p.y = y;
   1.256  	    break;
   1.257  	    //pressure?
   1.258  	  }	  
   1.259  	}
   1.260 -	else if(gestureLast[j].id == -1 && empty == -1) {
   1.261 +	else if(gestureLast[j].f.id == -1 && empty == -1) {
   1.262  	  empty = j;
   1.263  	}
   1.264        }
   1.265        
   1.266        if(j >= MAXFINGERS && empty >= 0) {
   1.267  	//	printf("Finger Down!!!\n");
   1.268 -	j = empty; //important that j is the index of the added finger
   1.269 -	gestureLast[j].id = event.tfinger.fingerId;
   1.270 -	gestureLast[j].p.x  = x;
   1.271 -	gestureLast[j].p.y  = y;
   1.272 -#ifdef DRAW_VECTOR_EST
   1.273 -	gestureLine[j].s.x = x;
   1.274 -	gestureLine[j].s.y = y;
   1.275 -	gestureLine[j].points = 1;
   1.276 -#endif
   1.277 -
   1.278 +	numDownFingers++;
   1.279 +	centroid.x = (centroid.x*(numDownFingers - 1) + x)/numDownFingers;
   1.280 +	centroid.y = (centroid.y*(numDownFingers - 1) + y)/numDownFingers;
   1.281 +	
   1.282 +	j = empty;
   1.283 +	gestureLast[j].f.id = event.tfinger.fingerId;
   1.284 +	gestureLast[j].f.p.x  = x;
   1.285 +	gestureLast[j].f.p.y  = y;
   1.286 +	
   1.287 +	
   1.288  	dollarPath[j].length = 0;
   1.289  	dollarPath[j].p[0].x = x;
   1.290  	dollarPath[j].p[0].y = y;
   1.291  	dollarPath[j].numPoints = 1;
   1.292        }
   1.293 -
   1.294 -      //draw the touch && each centroid:
   1.295 -
   1.296 -      if(gestureLast[j].id < 0) continue; //Finger up. Or some error...
   1.297 -      int k;
   1.298 -      for(k = 0; k < MAXFINGERS;k++) {
   1.299 -	if(gestureLast[k].id < 0) continue;
   1.300 -	//printf("k = %i, id: %i\n",k,gestureLast[k].id);
   1.301 -	//colors have no alpha, so shouldn't overflow
   1.302 -	unsigned int c = (colors[gestureLast[j].id%7] + 
   1.303 -			  colors[gestureLast[k].id%7])/2; 
   1.304 +      
   1.305 +      //draw the touch:
   1.306 +      
   1.307 +      if(gestureLast[j].f.id < 0) continue; //Finger up. Or some error...
   1.308 +      
   1.309 +      unsigned int c = colors[gestureLast[j].f.id%7]; 
   1.310 +      unsigned int col = 
   1.311 +	((unsigned int)(c*(.1+.85))) |
   1.312 +	((unsigned int)((0xFF*(1-((float)age)/EVENT_BUF_SIZE))) & 0xFF)<<24;
   1.313 +      x = gestureLast[j].f.p.x;
   1.314 +      y = gestureLast[j].f.p.y;
   1.315 +      if(event.type == SDL_FINGERMOTION)
   1.316 +	drawCircle(screen,x*screen->w,y*screen->h,5,col);
   1.317 +      else if(event.type == SDL_FINGERDOWN)
   1.318 +	drawCircle(screen,x*screen->w,y*screen->h,-10,col);     
   1.319 +      
   1.320 +      //if there is a centroid, draw it
   1.321 +      if(numDownFingers > 1) {
   1.322  	unsigned int col = 
   1.323 -	  ((unsigned int)(c*(.1+.85))) |
   1.324 +	  ((unsigned int)(0xFFFFFF)) |
   1.325  	  ((unsigned int)((0xFF*(1-((float)age)/EVENT_BUF_SIZE))) & 0xFF)<<24;
   1.326 -	x = (gestureLast[j].p.x + gestureLast[k].p.x)/2;
   1.327 -	y = (gestureLast[j].p.y + gestureLast[k].p.y)/2;
   1.328 -	if(event.type == SDL_FINGERMOTION)
   1.329 -	  drawCircle(screen,x*screen->w,y*screen->h,5,col);
   1.330 -	else if(event.type == SDL_FINGERDOWN)
   1.331 -	  drawCircle(screen,x*screen->w,y*screen->h,-10,col);
   1.332 -      }      
   1.333 +	drawCircle(screen,centroid.x*screen->w,centroid.y*screen->h,5,col);
   1.334 +      }
   1.335      }
   1.336    }
   1.337    
   1.338 @@ -494,9 +520,13 @@
   1.339  	drawCircle(screen,finger[i].p.x*screen->w,finger[i].p.y*screen->h
   1.340  		   ,20,0xFF);
   1.341  
   1.342 +
   1.343    
   1.344 -  keystat[32] = 0;	      
   1.345 -
   1.346 +  keystat[32] = 0;
   1.347 +  
   1.348 +  if(knob.p.x > 0)
   1.349 +    drawKnob(screen,knob);
   1.350 +  
   1.351    if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen);
   1.352    
   1.353    SDL_Flip(screen);
   1.354 @@ -516,6 +546,17 @@
   1.355    int keypress = 0;
   1.356    int h=0,s=1,i,j;
   1.357  
   1.358 +  //gesture variables
   1.359 +  int numDownFingers = 0;
   1.360 +  float gdtheta = 0,gdDist = 0;
   1.361 +  Point centroid;
   1.362 +  knob.r = .1;
   1.363 +  knob.ang = 0;
   1.364 +  TouchPoint gestureLast[MAXFINGERS];
   1.365 +  for(i = 0;i < MAXFINGERS;i++)
   1.366 +    gestureLast[i].f.id = -1;
   1.367 +
   1.368 +
   1.369    memset(keystat,0,512*sizeof(keystat[0]));
   1.370    if (SDL_Init(SDL_INIT_VIDEO) < 0 ) return 1;
   1.371    
   1.372 @@ -585,11 +626,12 @@
   1.373  	      
   1.374  	      finger[i].pressure = 
   1.375  		((float)event.tfinger.pressure)/inTouch->pressureres;
   1.376 -	      
   1.377 +	      /*
   1.378  	      printf("Finger: %i, Pressure: %f Pressureres: %i\n",
   1.379  		     event.tfinger.fingerId,
   1.380  		     finger[i].pressure,
   1.381  		     inTouch->pressureres);
   1.382 +	      */
   1.383  	      //printf("Finger: %i, pressure: %f\n",event.tfinger.fingerId,
   1.384  	      //   finger[event.tfinger.fingerId].pressure);
   1.385  	    }
   1.386 @@ -619,16 +661,113 @@
   1.387  	    finger[i].p.y = -1;
   1.388  	    break;
   1.389  	  }
   1.390 +      
   1.391 +    
   1.392 +	if(event.type == SDL_FINGERMOTION || 
   1.393 +	   event.type == SDL_FINGERDOWN ||
   1.394 +	   event.type == SDL_FINGERUP) {
   1.395 +	  SDL_Touch* inTouch = SDL_GetTouch(event.tfinger.touchId);
   1.396 +	  //SDL_Finger* inFinger = SDL_GetFinger(inTouch,event.tfinger.fingerId);
   1.397 +	  
   1.398 +	  float x = ((float)event.tfinger.x)/inTouch->xres;
   1.399 +	  float y = ((float)event.tfinger.y)/inTouch->yres;
   1.400 +	  int j,empty = -1;
   1.401 +	  
   1.402 +	  for(j = 0;j<MAXFINGERS;j++) {
   1.403 +	    if(gestureLast[j].f.id == event.tfinger.fingerId) {
   1.404 +	      if(event.type == SDL_FINGERUP) {
   1.405 +		numDownFingers--;
   1.406 +		if(numDownFingers <= 1) {
   1.407 +		  gdtheta = 0;
   1.408 +		  gdDist = 0;
   1.409 +		}
   1.410 +		gestureLast[j].f.id = -1;
   1.411 +		break;
   1.412 +	      }
   1.413 +	      else {	    
   1.414 +		float dx = x - gestureLast[j].f.p.x;
   1.415 +		float dy = y - gestureLast[j].f.p.y;
   1.416 +		centroid.x = centroid.x + dx/numDownFingers;
   1.417 +		centroid.y = centroid.y + dy/numDownFingers;    
   1.418 +		if(numDownFingers > 1) {
   1.419 +		  Point lv; //Vector from centroid to last x,y position
   1.420 +		  Point v; //Vector from centroid to current x,y position
   1.421 +		  lv = gestureLast[j].cv;
   1.422 +		  float lDist = sqrt(lv.x*lv.x + lv.y*lv.y);
   1.423 +		  printf("lDist = %f\n",lDist);
   1.424 +		  v.x = x - centroid.x;
   1.425 +		  v.y = y - centroid.y;
   1.426 +		  gestureLast[j].cv = v;
   1.427 +		  float Dist = sqrt(v.x*v.x+v.y*v.y);
   1.428 +		  // cos(dTheta) = (v . lv)/(|v| * |lv|)
   1.429 +		  
   1.430 +		  lv.x/=lDist;
   1.431 +		  lv.y/=lDist;
   1.432 +		  v.x/=Dist;
   1.433 +		  v.y/=Dist;
   1.434 +		  float dtheta = atan2(lv.x*v.y - lv.y*v.x,lv.x*v.x + lv.y*v.y);
   1.435 +		  
   1.436 +		  float dDist = (Dist - lDist);	      
   1.437 +		  if(lDist == 0) {dDist = 0;dtheta = 0;}
   1.438 +		  gestureLast[j].dDist = dDist;
   1.439 +		  gestureLast[j].dtheta = dtheta;
   1.440 +		  
   1.441 +		  printf("dDist = %f, dTheta = %f\n",dDist,dtheta);
   1.442 +		  //gdtheta = gdtheta*.9 + dtheta*.1;
   1.443 +		  //gdDist  =  gdDist*.9 +  dDist*.1
   1.444 +		  knob.r += dDist/numDownFingers;
   1.445 +		  knob.ang += dtheta;
   1.446 +		  //printf("thetaSum = %f, distSum = %f\n",gdtheta,gdDist);
   1.447 +		  //printf("id: %i dTheta = %f, dDist = %f\n",j,dtheta,dDist);
   1.448 +		}
   1.449 +		else {
   1.450 +		  gestureLast[j].dDist = 0;
   1.451 +		  gestureLast[j].dtheta = 0;
   1.452 +		  gestureLast[j].cv.x = 0;
   1.453 +		  gestureLast[j].cv.y = 0;
   1.454 +		}
   1.455 +		gestureLast[j].f.p.x = x;
   1.456 +		gestureLast[j].f.p.y = y;
   1.457 +		break;
   1.458 +		//pressure?
   1.459 +	      }	  
   1.460 +	    }
   1.461 +	    else if(gestureLast[j].f.id == -1 && empty == -1) {
   1.462 +	      empty = j;
   1.463 +	    }
   1.464 +	  }
   1.465 +	  
   1.466 +	  if(j >= MAXFINGERS && empty >= 0) {
   1.467 +	    printf("Finger Down!!!\n");
   1.468 +	    numDownFingers++;
   1.469 +	    centroid.x = (centroid.x*(numDownFingers - 1) + x)/numDownFingers;
   1.470 +	    centroid.y = (centroid.y*(numDownFingers - 1) + y)/numDownFingers;
   1.471 +	    
   1.472 +	    j = empty;
   1.473 +	    gestureLast[j].f.id = event.tfinger.fingerId;
   1.474 +	    gestureLast[j].f.p.x  = x;
   1.475 +	    gestureLast[j].f.p.y  = y;	
   1.476 +	    gestureLast[j].cv.x = 0;
   1.477 +	    gestureLast[j].cv.y = 0;
   1.478 +	  }
   1.479 +	  
   1.480 +	  //draw the touch:
   1.481 +	}
   1.482 +	//And draw
   1.483 +	if(numDownFingers > 1)
   1.484 +	  knob.p = centroid;
   1.485 +	else
   1.486 +	  knob.p.x = -1;
   1.487        }
   1.488 -    //And draw
   1.489      DrawScreen(screen,h);
   1.490 -    
   1.491 +    //printf("c: (%f,%f)\n",centroid.x,centroid.y);
   1.492 +    //printf("numDownFingers: %i\n",numDownFingers);
   1.493      //for(i=0;i<512;i++) 
   1.494      // if(keystat[i]) printf("%i\n",i);
   1.495      
   1.496      
   1.497    }  
   1.498    SDL_Quit();
   1.499 -      
   1.500 +  
   1.501    return 0;
   1.502  }