Started adding vectorization of touch data.
authorJim Grandpre <jim.tla@gmail.com>
Tue, 15 Jun 2010 02:12:16 -0400
changeset 4653744b75ad18b8
parent 4652 78f6e0b80d1e
child 4654 7dbcd71216df
Started adding vectorization of touch data.
touchTest/gestureTest.c
     1.1 --- a/touchTest/gestureTest.c	Mon Jun 14 01:46:08 2010 -0400
     1.2 +++ b/touchTest/gestureTest.c	Tue Jun 15 02:12:16 2010 -0400
     1.3 @@ -39,10 +39,16 @@
     1.4    int id;
     1.5  } Finger;
     1.6  
     1.7 +typedef struct { //dt + s
     1.8 +  Point d,s; //direction, start
     1.9 +  int points;
    1.10 +} Line;
    1.11 +
    1.12  
    1.13  Finger finger[MAXFINGERS];
    1.14  
    1.15  Finger gestureLast[MAXFINGERS];
    1.16 +Line gestureLine[MAXFINGERS];
    1.17  
    1.18  void handler (int sig)
    1.19  {
    1.20 @@ -86,6 +92,11 @@
    1.21    *pixmem32 = colour;
    1.22  }
    1.23  
    1.24 +void drawLine(SDL_Surface *screen,int x0,int y0,int x1,int y1,unsigned int col) {
    1.25 +  float t;
    1.26 +  for(t=0;t<1;t+=1.f/SDL_max(abs(x0-x1),abs(y0-y1)))
    1.27 +    setpix(screen,x1+t*(x0-x1),y1+t*(y0-y1),col);
    1.28 +}
    1.29  void drawCircle(SDL_Surface* screen,int x,int y,int r,unsigned int c)
    1.30  {
    1.31  
    1.32 @@ -145,10 +156,13 @@
    1.33          }
    1.34      }
    1.35    drawCircle(screen,mousx,mousy,-30,0xFFFFFF);
    1.36 -  
    1.37 +  drawLine(screen,0,0,screen->w,screen->h,0xFFFFFF);
    1.38    int i;
    1.39  //draw Touch History
    1.40 -  for(i = 0;i < MAXFINGERS;i++) gestureLast[i].id = -1;
    1.41 +  for(i = 0;i < MAXFINGERS;i++) {
    1.42 +    gestureLast[i].id = -1;
    1.43 +    gestureLine[i].points = 0;
    1.44 +  }
    1.45    for(i = SDL_max(0,eventWrite - EVENT_BUF_SIZE);i != eventWrite;i++) {
    1.46      SDL_Event event = events[i&(EVENT_BUF_SIZE-1)];
    1.47      int age = eventWrite - i - 1;
    1.48 @@ -164,10 +178,44 @@
    1.49        for(j = 0;j<MAXFINGERS;j++) {
    1.50  	if(gestureLast[j].id == event.tfinger.fingerId) {
    1.51  	  if(event.type == SDL_FINGERUP) {
    1.52 +	    if(gestureLine[j].points > 0)
    1.53 +	    drawLine(screen,
    1.54 +		     gestureLine[j].s.x*screen->w,
    1.55 +		     gestureLine[j].s.y*screen->h,
    1.56 +		     (gestureLine[j].s.x +50*gestureLine[j].d.x)*screen->w,
    1.57 +		     (gestureLine[j].s.y +50*gestureLine[j].d.y)*screen->h,
    1.58 +		     0xFF00);
    1.59 +
    1.60 +	    gestureLine[j].points = 0;
    1.61  	    gestureLast[j].id = -1;
    1.62  	    break;
    1.63  	  }
    1.64  	  else {
    1.65 +	    if(gestureLine[j].points == 1) {
    1.66 +	      gestureLine[j].d.x = x - gestureLine[j].s.x;
    1.67 +	      gestureLine[j].d.y = y - gestureLine[j].s.y;
    1.68 +	    }
    1.69 +
    1.70 +	    gestureLine[j].s.x = gestureLine[j].s.x*gestureLine[j].points+x;
    1.71 +	    gestureLine[j].s.y = gestureLine[j].s.y*gestureLine[j].points+y;
    1.72 +
    1.73 +	    gestureLine[j].d.x = gestureLine[j].d.x*gestureLine[j].points+
    1.74 +	      x - gestureLast[j].p.x;
    1.75 +	    gestureLine[j].d.y = gestureLine[j].d.y*gestureLine[j].points+
    1.76 +	      y - gestureLast[j].p.y;;
    1.77 +
    1.78 +
    1.79 +	    gestureLine[j].points++;
    1.80 +	    
    1.81 +	    gestureLine[j].s.x /= gestureLine[j].points;
    1.82 +	    gestureLine[j].s.y /= gestureLine[j].points;
    1.83 +
    1.84 +	    gestureLine[j].d.x /= gestureLine[j].points;
    1.85 +	    gestureLine[j].d.y /= gestureLine[j].points;
    1.86 +
    1.87 +	    
    1.88 +	    
    1.89 +
    1.90  	    gestureLast[j].p.x = x;
    1.91  	    gestureLast[j].p.y = y;
    1.92  	    break;
    1.93 @@ -185,6 +233,10 @@
    1.94  	gestureLast[j].id = event.tfinger.fingerId;
    1.95  	gestureLast[j].p.x  = x;
    1.96  	gestureLast[j].p.y  = y;
    1.97 +
    1.98 +	gestureLine[j].s.x = x;
    1.99 +	gestureLine[j].s.y = y;
   1.100 +	gestureLine[j].points = 1;
   1.101        }
   1.102  
   1.103        //draw the touch && each centroid: