Mercurial > sdl-ios-xcode
diff src/events/SDL_gesture.c @ 4663:56a2d70de945
Started trying to build gesture code for iPhone
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 15 Jul 2010 06:51:16 -0700 |
parents | 063b9455bd1a |
children | c2493813a2f4 |
line wrap: on
line diff
--- a/src/events/SDL_gesture.c Tue Jul 13 18:31:09 2010 -0400 +++ b/src/events/SDL_gesture.c Thu Jul 15 06:51:16 2010 -0700 @@ -110,13 +110,14 @@ return hash; } -int SaveTemplate(DollarTemplate *templ, FILE *fp) { +static 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"); + return 0; } @@ -141,6 +142,36 @@ } } } + SDL_SetError("Unknown gestureId"); + return -1; +} + +//path is an already sampled set of points +//Returns the index of the gesture on success, or -1 +static 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; } int SDL_LoadDollarTemplates(int touchId, FILE *fp) { @@ -182,37 +213,6 @@ } -//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]; float dist = 0; @@ -264,21 +264,6 @@ return SDL_min(f1,f2); } -float dollarRecognize(DollarPath path,int *bestTempl,GestureTouch* touch) { - - Point points[DOLLARNPOINTS]; - int numPoints = dollarNormalize(path,points); - int i; - - int bestDiff = 10000; - *bestTempl = -1; - for(i = 0;i < touch->numDollarTemplates;i++) { - int diff = bestDollarDifference(points,touch->dollarTemplate[i].path); - 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; @@ -359,6 +344,21 @@ return numPoints; } +float dollarRecognize(DollarPath path,int *bestTempl,GestureTouch* touch) { + + Point points[DOLLARNPOINTS]; + int numPoints = dollarNormalize(path,points); + int i; + + int bestDiff = 10000; + *bestTempl = -1; + for(i = 0;i < touch->numDollarTemplates;i++) { + int diff = bestDollarDifference(points,touch->dollarTemplate[i].path); + if(diff < bestDiff) {bestDiff = diff; *bestTempl = i;} + } + return bestDiff; +} + int SDL_GestureAddTouch(SDL_Touch* touch) { if(numGestureTouches >= MAXTOUCHES) return -1;