# HG changeset patch # User Jim Grandpre # Date 1276582336 14400 # Node ID 744b75ad18b8d946ad550c4e7dcf0050ae13ca4a # Parent 78f6e0b80d1e06cab61becd17923904a5eccc720 Started adding vectorization of touch data. diff -r 78f6e0b80d1e -r 744b75ad18b8 touchTest/gestureTest.c --- a/touchTest/gestureTest.c Mon Jun 14 01:46:08 2010 -0400 +++ b/touchTest/gestureTest.c Tue Jun 15 02:12:16 2010 -0400 @@ -39,10 +39,16 @@ int id; } Finger; +typedef struct { //dt + s + Point d,s; //direction, start + int points; +} Line; + Finger finger[MAXFINGERS]; Finger gestureLast[MAXFINGERS]; +Line gestureLine[MAXFINGERS]; void handler (int sig) { @@ -86,6 +92,11 @@ *pixmem32 = colour; } +void drawLine(SDL_Surface *screen,int x0,int y0,int x1,int y1,unsigned int col) { + float t; + for(t=0;t<1;t+=1.f/SDL_max(abs(x0-x1),abs(y0-y1))) + setpix(screen,x1+t*(x0-x1),y1+t*(y0-y1),col); +} void drawCircle(SDL_Surface* screen,int x,int y,int r,unsigned int c) { @@ -145,10 +156,13 @@ } } drawCircle(screen,mousx,mousy,-30,0xFFFFFF); - + drawLine(screen,0,0,screen->w,screen->h,0xFFFFFF); int i; //draw Touch History - for(i = 0;i < MAXFINGERS;i++) gestureLast[i].id = -1; + for(i = 0;i < MAXFINGERS;i++) { + gestureLast[i].id = -1; + gestureLine[i].points = 0; + } for(i = SDL_max(0,eventWrite - EVENT_BUF_SIZE);i != eventWrite;i++) { SDL_Event event = events[i&(EVENT_BUF_SIZE-1)]; int age = eventWrite - i - 1; @@ -164,10 +178,44 @@ for(j = 0;j 0) + drawLine(screen, + gestureLine[j].s.x*screen->w, + gestureLine[j].s.y*screen->h, + (gestureLine[j].s.x +50*gestureLine[j].d.x)*screen->w, + (gestureLine[j].s.y +50*gestureLine[j].d.y)*screen->h, + 0xFF00); + + gestureLine[j].points = 0; gestureLast[j].id = -1; break; } else { + if(gestureLine[j].points == 1) { + gestureLine[j].d.x = x - gestureLine[j].s.x; + gestureLine[j].d.y = y - gestureLine[j].s.y; + } + + gestureLine[j].s.x = gestureLine[j].s.x*gestureLine[j].points+x; + gestureLine[j].s.y = gestureLine[j].s.y*gestureLine[j].points+y; + + gestureLine[j].d.x = gestureLine[j].d.x*gestureLine[j].points+ + x - gestureLast[j].p.x; + gestureLine[j].d.y = gestureLine[j].d.y*gestureLine[j].points+ + y - gestureLast[j].p.y;; + + + gestureLine[j].points++; + + gestureLine[j].s.x /= gestureLine[j].points; + gestureLine[j].s.y /= gestureLine[j].points; + + gestureLine[j].d.x /= gestureLine[j].points; + gestureLine[j].d.y /= gestureLine[j].points; + + + + gestureLast[j].p.x = x; gestureLast[j].p.y = y; break; @@ -185,6 +233,10 @@ gestureLast[j].id = event.tfinger.fingerId; gestureLast[j].p.x = x; gestureLast[j].p.y = y; + + gestureLine[j].s.x = x; + gestureLine[j].s.y = y; + gestureLine[j].points = 1; } //draw the touch && each centroid: