Commit 3c27fa1e authored by Kees Bakker's avatar Kees Bakker

Reformat SDL_gesture.c (part 2, space after keywords)

parent 428e61a4
...@@ -84,7 +84,7 @@ static void PrintPath(SDL_FloatPoint *path) ...@@ -84,7 +84,7 @@ static void PrintPath(SDL_FloatPoint *path)
{ {
int i; int i;
printf("Path:"); printf("Path:");
for(i=0;i<DOLLARNPOINTS;i++) { for (i=0; i<DOLLARNPOINTS; i++) {
printf(" (%f,%f)",path[i].x,path[i].y); printf(" (%f,%f)",path[i].x,path[i].y);
} }
printf("\n"); printf("\n");
...@@ -94,11 +94,11 @@ static void PrintPath(SDL_FloatPoint *path) ...@@ -94,11 +94,11 @@ static void PrintPath(SDL_FloatPoint *path)
int SDL_RecordGesture(SDL_TouchID touchId) int SDL_RecordGesture(SDL_TouchID touchId)
{ {
int i; int i;
if(touchId < 0) recordAll = SDL_TRUE; if (touchId < 0) recordAll = SDL_TRUE;
for(i = 0;i < SDL_numGestureTouches; i++) { for (i = 0; i < SDL_numGestureTouches; i++) {
if((touchId < 0) || (SDL_gestureTouch[i].id == touchId)) { if ((touchId < 0) || (SDL_gestureTouch[i].id == touchId)) {
SDL_gestureTouch[i].recording = SDL_TRUE; SDL_gestureTouch[i].recording = SDL_TRUE;
if(touchId >= 0) if (touchId >= 0)
return 1; return 1;
} }
} }
...@@ -109,7 +109,7 @@ unsigned long SDL_HashDollar(SDL_FloatPoint* points) ...@@ -109,7 +109,7 @@ unsigned long SDL_HashDollar(SDL_FloatPoint* points)
{ {
unsigned long hash = 5381; unsigned long hash = 5381;
int i; int i;
for(i = 0;i < DOLLARNPOINTS; i++) { for (i = 0; i < DOLLARNPOINTS; i++) {
hash = ((hash<<5) + hash) + (unsigned long)points[i].x; hash = ((hash<<5) + hash) + (unsigned long)points[i].x;
hash = ((hash<<5) + hash) + (unsigned long)points[i].y; hash = ((hash<<5) + hash) + (unsigned long)points[i].y;
} }
...@@ -119,14 +119,14 @@ unsigned long SDL_HashDollar(SDL_FloatPoint* points) ...@@ -119,14 +119,14 @@ unsigned long SDL_HashDollar(SDL_FloatPoint* points)
static int SaveTemplate(SDL_DollarTemplate *templ, SDL_RWops * src) static int SaveTemplate(SDL_DollarTemplate *templ, SDL_RWops * src)
{ {
if(src == NULL) return 0; if (src == NULL) return 0;
//No Longer storing the Hash, rehash on load //No Longer storing the Hash, rehash on load
//if(SDL_RWops.write(src,&(templ->hash),sizeof(templ->hash),1) != 1) return 0; //if(SDL_RWops.write(src,&(templ->hash),sizeof(templ->hash),1) != 1) return 0;
if(SDL_RWwrite(src,templ->path, if (SDL_RWwrite(src,templ->path,
sizeof(templ->path[0]),DOLLARNPOINTS) != DOLLARNPOINTS) sizeof(templ->path[0]),DOLLARNPOINTS) != DOLLARNPOINTS)
return 0; return 0;
return 1; return 1;
...@@ -136,9 +136,9 @@ static int SaveTemplate(SDL_DollarTemplate *templ, SDL_RWops * src) ...@@ -136,9 +136,9 @@ static int SaveTemplate(SDL_DollarTemplate *templ, SDL_RWops * src)
int SDL_SaveAllDollarTemplates(SDL_RWops *src) int SDL_SaveAllDollarTemplates(SDL_RWops *src)
{ {
int i,j,rtrn = 0; int i,j,rtrn = 0;
for(i = 0; i < SDL_numGestureTouches; i++) { for (i = 0; i < SDL_numGestureTouches; i++) {
SDL_GestureTouch* touch = &SDL_gestureTouch[i]; SDL_GestureTouch* touch = &SDL_gestureTouch[i];
for(j = 0;j < touch->numDollarTemplates; j++) { for (j = 0; j < touch->numDollarTemplates; j++) {
rtrn += SaveTemplate(&touch->dollarTemplate[i],src); rtrn += SaveTemplate(&touch->dollarTemplate[i],src);
} }
} }
...@@ -148,10 +148,10 @@ int SDL_SaveAllDollarTemplates(SDL_RWops *src) ...@@ -148,10 +148,10 @@ int SDL_SaveAllDollarTemplates(SDL_RWops *src)
int SDL_SaveDollarTemplate(SDL_GestureID gestureId, SDL_RWops *src) int SDL_SaveDollarTemplate(SDL_GestureID gestureId, SDL_RWops *src)
{ {
int i,j; int i,j;
for(i = 0; i < SDL_numGestureTouches; i++) { for (i = 0; i < SDL_numGestureTouches; i++) {
SDL_GestureTouch* touch = &SDL_gestureTouch[i]; SDL_GestureTouch* touch = &SDL_gestureTouch[i];
for(j = 0;j < touch->numDollarTemplates; j++) { for (j = 0; j < touch->numDollarTemplates; j++) {
if(touch->dollarTemplate[i].hash == gestureId) { if (touch->dollarTemplate[i].hash == gestureId) {
return SaveTemplate(&touch->dollarTemplate[i],src); return SaveTemplate(&touch->dollarTemplate[i],src);
} }
} }
...@@ -167,16 +167,16 @@ static int SDL_AddDollarGesture(SDL_GestureTouch* inTouch,SDL_FloatPoint* path) ...@@ -167,16 +167,16 @@ static int SDL_AddDollarGesture(SDL_GestureTouch* inTouch,SDL_FloatPoint* path)
SDL_DollarTemplate* dollarTemplate; SDL_DollarTemplate* dollarTemplate;
SDL_DollarTemplate *templ; SDL_DollarTemplate *templ;
int i = 0; int i = 0;
if(inTouch == NULL) { if (inTouch == NULL) {
if(SDL_numGestureTouches == 0) return -1; if (SDL_numGestureTouches == 0) return -1;
for(i = 0;i < SDL_numGestureTouches; i++) { for (i = 0; i < SDL_numGestureTouches; i++) {
inTouch = &SDL_gestureTouch[i]; inTouch = &SDL_gestureTouch[i];
dollarTemplate = dollarTemplate =
(SDL_DollarTemplate *)SDL_realloc(inTouch->dollarTemplate, (SDL_DollarTemplate *)SDL_realloc(inTouch->dollarTemplate,
(inTouch->numDollarTemplates + 1) * (inTouch->numDollarTemplates + 1) *
sizeof(SDL_DollarTemplate)); sizeof(SDL_DollarTemplate));
if(!dollarTemplate) { if (!dollarTemplate) {
SDL_OutOfMemory(); SDL_OutOfMemory();
return -1; return -1;
} }
...@@ -195,7 +195,7 @@ static int SDL_AddDollarGesture(SDL_GestureTouch* inTouch,SDL_FloatPoint* path) ...@@ -195,7 +195,7 @@ static int SDL_AddDollarGesture(SDL_GestureTouch* inTouch,SDL_FloatPoint* path)
( SDL_DollarTemplate *)SDL_realloc(inTouch->dollarTemplate, ( SDL_DollarTemplate *)SDL_realloc(inTouch->dollarTemplate,
(inTouch->numDollarTemplates + 1) * (inTouch->numDollarTemplates + 1) *
sizeof(SDL_DollarTemplate)); sizeof(SDL_DollarTemplate));
if(!dollarTemplate) { if (!dollarTemplate) {
SDL_OutOfMemory(); SDL_OutOfMemory();
return -1; return -1;
} }
...@@ -216,27 +216,27 @@ int SDL_LoadDollarTemplates(SDL_TouchID touchId, SDL_RWops *src) ...@@ -216,27 +216,27 @@ int SDL_LoadDollarTemplates(SDL_TouchID touchId, SDL_RWops *src)
{ {
int i,loaded = 0; int i,loaded = 0;
SDL_GestureTouch *touch = NULL; SDL_GestureTouch *touch = NULL;
if(src == NULL) return 0; if (src == NULL) return 0;
if(touchId >= 0) { if (touchId >= 0) {
for(i = 0;i < SDL_numGestureTouches; i++) for (i = 0; i < SDL_numGestureTouches; i++)
if(SDL_gestureTouch[i].id == touchId) if (SDL_gestureTouch[i].id == touchId)
touch = &SDL_gestureTouch[i]; touch = &SDL_gestureTouch[i];
if(touch == NULL) return -1; if (touch == NULL) return -1;
} }
while(1) { while (1) {
SDL_DollarTemplate templ; SDL_DollarTemplate templ;
if(SDL_RWread(src,templ.path,sizeof(templ.path[0]),DOLLARNPOINTS) < if (SDL_RWread(src,templ.path,sizeof(templ.path[0]),DOLLARNPOINTS) <
DOLLARNPOINTS) break; DOLLARNPOINTS) break;
if(touchId >= 0) { if (touchId >= 0) {
//printf("Adding loaded gesture to 1 touch\n"); //printf("Adding loaded gesture to 1 touch\n");
if(SDL_AddDollarGesture(touch,templ.path)) loaded++; if (SDL_AddDollarGesture(touch,templ.path)) loaded++;
} }
else { else {
//printf("Adding to: %i touches\n",SDL_numGestureTouches); //printf("Adding to: %i touches\n",SDL_numGestureTouches);
for(i = 0;i < SDL_numGestureTouches; i++) { for (i = 0; i < SDL_numGestureTouches; i++) {
touch = &SDL_gestureTouch[i]; touch = &SDL_gestureTouch[i];
//printf("Adding loaded gesture to + touches\n"); //printf("Adding loaded gesture to + touches\n");
//TODO: What if this fails? //TODO: What if this fails?
...@@ -256,7 +256,7 @@ float dollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ,float ang) ...@@ -256,7 +256,7 @@ float dollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ,float ang)
float dist = 0; float dist = 0;
SDL_FloatPoint p; SDL_FloatPoint p;
int i; int i;
for(i = 0; i < DOLLARNPOINTS; i++) { for (i = 0; i < DOLLARNPOINTS; i++) {
p.x = (float)(points[i].x * SDL_cos(ang) - points[i].y * SDL_sin(ang)); p.x = (float)(points[i].x * SDL_cos(ang) - points[i].y * SDL_sin(ang));
p.y = (float)(points[i].x * SDL_sin(ang) + points[i].y * SDL_cos(ang)); p.y = (float)(points[i].x * SDL_sin(ang) + points[i].y * SDL_cos(ang));
dist += (float)(SDL_sqrt((p.x-templ[i].x)*(p.x-templ[i].x)+ dist += (float)(SDL_sqrt((p.x-templ[i].x)*(p.x-templ[i].x)+
...@@ -278,8 +278,8 @@ float bestDollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ) ...@@ -278,8 +278,8 @@ float bestDollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ)
float f1 = dollarDifference(points,templ,x1); float f1 = dollarDifference(points,templ,x1);
float x2 = (float)((1-PHI)*ta + PHI*tb); float x2 = (float)((1-PHI)*ta + PHI*tb);
float f2 = dollarDifference(points,templ,x2); float f2 = dollarDifference(points,templ,x2);
while(SDL_fabs(ta-tb) > dt) { while (SDL_fabs(ta-tb) > dt) {
if(f1 < f2) { if (f1 < f2) {
tb = x2; tb = x2;
x2 = x1; x2 = x1;
f2 = f1; f2 = f1;
...@@ -295,10 +295,10 @@ float bestDollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ) ...@@ -295,10 +295,10 @@ float bestDollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ)
} }
} }
/* /*
if(f1 <= f2) if (f1 <= f2)
printf("Min angle (x1): %f\n",x1); printf("Min angle (x1): %f\n",x1);
else if(f1 > f2) else if (f1 > f2)
printf("Min angle (x2): %f\n",x2); printf("Min angle (x2): %f\n",x2);
*/ */
return SDL_min(f1,f2); return SDL_min(f1,f2);
} }
...@@ -317,12 +317,10 @@ int dollarNormalize(const SDL_DollarPath *path,SDL_FloatPoint *points) ...@@ -317,12 +317,10 @@ int dollarNormalize(const SDL_DollarPath *path,SDL_FloatPoint *points)
float length = path->length; float length = path->length;
//Calculate length if it hasn't already been done //Calculate length if it hasn't already been done
if(length <= 0) { if (length <= 0) {
for(i=1;i<path->numPoints;i++) { for (i=1;i < path->numPoints; i++) {
float dx = path->p[i ].x - float dx = path->p[i ].x - path->p[i-1].x;
path->p[i-1].x; float dy = path->p[i ].y - path->p[i-1].y;
float dy = path->p[i ].y -
path->p[i-1].y;
length += (float)(SDL_sqrt(dx*dx+dy*dy)); length += (float)(SDL_sqrt(dx*dx+dy*dy));
} }
} }
...@@ -334,11 +332,11 @@ int dollarNormalize(const SDL_DollarPath *path,SDL_FloatPoint *points) ...@@ -334,11 +332,11 @@ int dollarNormalize(const SDL_DollarPath *path,SDL_FloatPoint *points)
centroid.x = 0;centroid.y = 0; centroid.x = 0;centroid.y = 0;
//printf("(%f,%f)\n",path->p[path->numPoints-1].x,path->p[path->numPoints-1].y); //printf("(%f,%f)\n",path->p[path->numPoints-1].x,path->p[path->numPoints-1].y);
for(i = 1;i < path->numPoints;i++) { for (i = 1; i < path->numPoints; i++) {
float d = (float)(SDL_sqrt((path->p[i-1].x-path->p[i].x)*(path->p[i-1].x-path->p[i].x)+ float d = (float)(SDL_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))); (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); //printf("d = %f dist = %f/%f\n",d,dist,interval);
while(dist + d > interval) { while (dist + d > interval) {
points[numPoints].x = path->p[i-1].x + points[numPoints].x = path->p[i-1].x +
((interval-dist)/d)*(path->p[i].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 + points[numPoints].y = path->p[i-1].y +
...@@ -351,7 +349,7 @@ int dollarNormalize(const SDL_DollarPath *path,SDL_FloatPoint *points) ...@@ -351,7 +349,7 @@ int dollarNormalize(const SDL_DollarPath *path,SDL_FloatPoint *points)
} }
dist += d; dist += d;
} }
if(numPoints < DOLLARNPOINTS-1) { if (numPoints < DOLLARNPOINTS-1) {
SDL_SetError("ERROR: NumPoints = %i\n",numPoints); SDL_SetError("ERROR: NumPoints = %i\n",numPoints);
return 0; return 0;
} }
...@@ -372,7 +370,7 @@ int dollarNormalize(const SDL_DollarPath *path,SDL_FloatPoint *points) ...@@ -372,7 +370,7 @@ int dollarNormalize(const SDL_DollarPath *path,SDL_FloatPoint *points)
ang = (float)(SDL_atan2(centroid.y - points[0].y, ang = (float)(SDL_atan2(centroid.y - points[0].y,
centroid.x - points[0].x)); centroid.x - points[0].x));
for(i = 0;i<numPoints;i++) { for (i = 0; i<numPoints; i++) {
float px = points[i].x; float px = points[i].x;
float py = points[i].y; float py = points[i].y;
points[i].x = (float)((px - centroid.x)*SDL_cos(ang) - points[i].x = (float)((px - centroid.x)*SDL_cos(ang) -
...@@ -381,17 +379,17 @@ int dollarNormalize(const SDL_DollarPath *path,SDL_FloatPoint *points) ...@@ -381,17 +379,17 @@ int dollarNormalize(const SDL_DollarPath *path,SDL_FloatPoint *points)
(py - centroid.y)*SDL_cos(ang) + centroid.y); (py - centroid.y)*SDL_cos(ang) + centroid.y);
if(points[i].x < xmin) xmin = points[i].x; if (points[i].x < xmin) xmin = points[i].x;
if(points[i].x > xmax) xmax = 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 < ymin) ymin = points[i].y;
if(points[i].y > ymax) ymax = points[i].y; if (points[i].y > ymax) ymax = points[i].y;
} }
//Scale points to DOLLARSIZE, and translate to the origin //Scale points to DOLLARSIZE, and translate to the origin
w = xmax-xmin; w = xmax-xmin;
h = ymax-ymin; h = ymax-ymin;
for(i=0;i<numPoints;i++) { for (i=0; i<numPoints; i++) {
points[i].x = (points[i].x - centroid.x)*DOLLARSIZE/w; points[i].x = (points[i].x - centroid.x)*DOLLARSIZE/w;
points[i].y = (points[i].y - centroid.y)*DOLLARSIZE/h; points[i].y = (points[i].y - centroid.y)*DOLLARSIZE/h;
} }
...@@ -409,9 +407,9 @@ float dollarRecognize(const SDL_DollarPath *path,int *bestTempl,SDL_GestureTouch ...@@ -409,9 +407,9 @@ float dollarRecognize(const SDL_DollarPath *path,int *bestTempl,SDL_GestureTouch
//PrintPath(points); //PrintPath(points);
*bestTempl = -1; *bestTempl = -1;
for(i = 0;i < touch->numDollarTemplates;i++) { for (i = 0; i < touch->numDollarTemplates; i++) {
float diff = bestDollarDifference(points,touch->dollarTemplate[i].path); float diff = bestDollarDifference(points,touch->dollarTemplate[i].path);
if(diff < bestDiff) {bestDiff = diff; *bestTempl = i;} if (diff < bestDiff) {bestDiff = diff; *bestTempl = i;}
} }
return bestDiff; return bestDiff;
} }
...@@ -422,7 +420,7 @@ int SDL_GestureAddTouch(SDL_Touch* touch) ...@@ -422,7 +420,7 @@ int SDL_GestureAddTouch(SDL_Touch* touch)
(SDL_numGestureTouches + 1) * (SDL_numGestureTouches + 1) *
sizeof(SDL_GestureTouch)); sizeof(SDL_GestureTouch));
if(!gestureTouch) { if (!gestureTouch) {
SDL_OutOfMemory(); SDL_OutOfMemory();
return -1; return -1;
} }
...@@ -461,9 +459,10 @@ int SDL_GestureRemoveTouch(SDL_TouchID id) ...@@ -461,9 +459,10 @@ int SDL_GestureRemoveTouch(SDL_TouchID id)
SDL_GestureTouch * SDL_GetGestureTouch(SDL_TouchID id) SDL_GestureTouch * SDL_GetGestureTouch(SDL_TouchID id)
{ {
int i; int i;
for(i = 0;i < SDL_numGestureTouches; i++) { for (i = 0; i < SDL_numGestureTouches; i++) {
//printf("%i ?= %i\n",SDL_gestureTouch[i].id,id); //printf("%i ?= %i\n",SDL_gestureTouch[i].id,id);
if(SDL_gestureTouch[i].id == id) return &SDL_gestureTouch[i]; if (SDL_gestureTouch[i].id == id)
return &SDL_gestureTouch[i];
} }
return NULL; return NULL;
} }
...@@ -524,13 +523,13 @@ void SDL_GestureProcessEvent(SDL_Event* event) ...@@ -524,13 +523,13 @@ void SDL_GestureProcessEvent(SDL_Event* event)
float dtheta; float dtheta;
float dDist; float dDist;
if(event->type == SDL_FINGERMOTION || if (event->type == SDL_FINGERMOTION ||
event->type == SDL_FINGERDOWN || event->type == SDL_FINGERDOWN ||
event->type == SDL_FINGERUP) { event->type == SDL_FINGERUP) {
SDL_GestureTouch* inTouch = SDL_GetGestureTouch(event->tfinger.touchId); SDL_GestureTouch* inTouch = SDL_GetGestureTouch(event->tfinger.touchId);
//Shouldn't be possible //Shouldn't be possible
if(inTouch == NULL) return; if (inTouch == NULL) return;
//printf("@ (%i,%i) with res: (%i,%i)\n",(int)event->tfinger.x, //printf("@ (%i,%i) with res: (%i,%i)\n",(int)event->tfinger.x,
// (int)event->tfinger.y, // (int)event->tfinger.y,
...@@ -542,24 +541,24 @@ void SDL_GestureProcessEvent(SDL_Event* event) ...@@ -542,24 +541,24 @@ void SDL_GestureProcessEvent(SDL_Event* event)
//Finger Up //Finger Up
if(event->type == SDL_FINGERUP) { if (event->type == SDL_FINGERUP) {
inTouch->numDownFingers--; inTouch->numDownFingers--;
#ifdef ENABLE_DOLLAR #ifdef ENABLE_DOLLAR
if(inTouch->recording) { if (inTouch->recording) {
inTouch->recording = SDL_FALSE; inTouch->recording = SDL_FALSE;
dollarNormalize(&inTouch->dollarPath,path); dollarNormalize(&inTouch->dollarPath,path);
//PrintPath(path); //PrintPath(path);
if(recordAll) { if (recordAll) {
index = SDL_AddDollarGesture(NULL,path); index = SDL_AddDollarGesture(NULL,path);
for(i = 0;i < SDL_numGestureTouches; i++) for (i = 0; i < SDL_numGestureTouches; i++)
SDL_gestureTouch[i].recording = SDL_FALSE; SDL_gestureTouch[i].recording = SDL_FALSE;
} }
else { else {
index = SDL_AddDollarGesture(inTouch,path); index = SDL_AddDollarGesture(inTouch,path);
} }
if(index >= 0) { if (index >= 0) {
SDL_SendDollarRecord(inTouch,inTouch->dollarTemplate[index].hash); SDL_SendDollarRecord(inTouch,inTouch->dollarTemplate[index].hash);
} }
else { else {
...@@ -571,7 +570,7 @@ void SDL_GestureProcessEvent(SDL_Event* event) ...@@ -571,7 +570,7 @@ void SDL_GestureProcessEvent(SDL_Event* event)
float error; float error;
error = dollarRecognize(&inTouch->dollarPath, error = dollarRecognize(&inTouch->dollarPath,
&bestTempl,inTouch); &bestTempl,inTouch);
if(bestTempl >= 0){ if (bestTempl >= 0){
//Send Event //Send Event
unsigned long gestureId = inTouch->dollarTemplate[bestTempl].hash; unsigned long gestureId = inTouch->dollarTemplate[bestTempl].hash;
SDL_SendGestureDollar(inTouch,gestureId,error); SDL_SendGestureDollar(inTouch,gestureId,error);
...@@ -580,20 +579,20 @@ void SDL_GestureProcessEvent(SDL_Event* event) ...@@ -580,20 +579,20 @@ void SDL_GestureProcessEvent(SDL_Event* event)
} }
#endif #endif
//inTouch->gestureLast[j] = inTouch->gestureLast[inTouch->numDownFingers]; //inTouch->gestureLast[j] = inTouch->gestureLast[inTouch->numDownFingers];
if(inTouch->numDownFingers > 0) { if (inTouch->numDownFingers > 0) {
inTouch->centroid.x = (inTouch->centroid.x*(inTouch->numDownFingers+1)- inTouch->centroid.x = (inTouch->centroid.x*(inTouch->numDownFingers+1)-
x)/inTouch->numDownFingers; x)/inTouch->numDownFingers;
inTouch->centroid.y = (inTouch->centroid.y*(inTouch->numDownFingers+1)- inTouch->centroid.y = (inTouch->centroid.y*(inTouch->numDownFingers+1)-
y)/inTouch->numDownFingers; y)/inTouch->numDownFingers;
} }
} }
else if(event->type == SDL_FINGERMOTION) { else if (event->type == SDL_FINGERMOTION) {
float dx = ((float)event->tfinger.dx)/(float)inTouch->res.x; float dx = ((float)event->tfinger.dx)/(float)inTouch->res.x;
float dy = ((float)event->tfinger.dy)/(float)inTouch->res.y; float dy = ((float)event->tfinger.dy)/(float)inTouch->res.y;
//printf("dx,dy: (%f,%f)\n",dx,dy); //printf("dx,dy: (%f,%f)\n",dx,dy);
#ifdef ENABLE_DOLLAR #ifdef ENABLE_DOLLAR
SDL_DollarPath* path = &inTouch->dollarPath; SDL_DollarPath* path = &inTouch->dollarPath;
if(path->numPoints < MAXPATHSIZE) { if (path->numPoints < MAXPATHSIZE) {
path->p[path->numPoints].x = inTouch->centroid.x; path->p[path->numPoints].x = inTouch->centroid.x;
path->p[path->numPoints].y = inTouch->centroid.y; path->p[path->numPoints].y = inTouch->centroid.y;
pathDx = pathDx =
...@@ -611,7 +610,7 @@ void SDL_GestureProcessEvent(SDL_Event* event) ...@@ -611,7 +610,7 @@ void SDL_GestureProcessEvent(SDL_Event* event)
inTouch->centroid.x += dx/inTouch->numDownFingers; inTouch->centroid.x += dx/inTouch->numDownFingers;
inTouch->centroid.y += dy/inTouch->numDownFingers; inTouch->centroid.y += dy/inTouch->numDownFingers;
//printf("Centrid : (%f,%f)\n",inTouch->centroid.x,inTouch->centroid.y); //printf("Centrid : (%f,%f)\n",inTouch->centroid.x,inTouch->centroid.y);
if(inTouch->numDownFingers > 1) { if (inTouch->numDownFingers > 1) {
SDL_FloatPoint lv; //Vector from centroid to last x,y position SDL_FloatPoint lv; //Vector from centroid to last x,y position
SDL_FloatPoint v; //Vector from centroid to current x,y position SDL_FloatPoint v; //Vector from centroid to current x,y position
//lv = inTouch->gestureLast[j].cv; //lv = inTouch->gestureLast[j].cv;
...@@ -633,7 +632,7 @@ void SDL_GestureProcessEvent(SDL_Event* event) ...@@ -633,7 +632,7 @@ void SDL_GestureProcessEvent(SDL_Event* event)
dtheta = (float)SDL_atan2(lv.x*v.y - lv.y*v.x,lv.x*v.x + lv.y*v.y); dtheta = (float)SDL_atan2(lv.x*v.y - lv.y*v.x,lv.x*v.x + lv.y*v.y);
dDist = (Dist - lDist); dDist = (Dist - lDist);
if(lDist == 0) {dDist = 0;dtheta = 0;} //To avoid impossible values if (lDist == 0) {dDist = 0;dtheta = 0;} //To avoid impossible values
//inTouch->gestureLast[j].dDist = dDist; //inTouch->gestureLast[j].dDist = dDist;
//inTouch->gestureLast[j].dtheta = dtheta; //inTouch->gestureLast[j].dtheta = dtheta;
...@@ -659,7 +658,7 @@ void SDL_GestureProcessEvent(SDL_Event* event) ...@@ -659,7 +658,7 @@ void SDL_GestureProcessEvent(SDL_Event* event)
//pressure? //pressure?
} }
if(event->type == SDL_FINGERDOWN) { if (event->type == SDL_FINGERDOWN) {
inTouch->numDownFingers++; inTouch->numDownFingers++;
inTouch->centroid.x = (inTouch->centroid.x*(inTouch->numDownFingers - 1)+ inTouch->centroid.x = (inTouch->centroid.x*(inTouch->numDownFingers - 1)+
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment