Mercurial > sdl-ios-xcode
comparison src/events/SDL_gesture.c @ 4684:f47c2640c667
Re-enabled dollar gesture
author | Jim Grandpre <jim.tla@gmail.com> |
---|---|
date | Fri, 06 Aug 2010 01:55:38 -0400 |
parents | 15dfe42edbfd |
children | e0c3b09368a6 |
comparison
equal
deleted
inserted
replaced
4683:15dfe42edbfd | 4684:f47c2640c667 |
---|---|
32 #define MAXTEMPLATES 4 | 32 #define MAXTEMPLATES 4 |
33 #define MAXPATHSIZE 1024 | 33 #define MAXPATHSIZE 1024 |
34 | 34 |
35 #define DOLLARNPOINTS 64 | 35 #define DOLLARNPOINTS 64 |
36 #define DOLLARSIZE 256 | 36 #define DOLLARSIZE 256 |
37 | |
38 #define ENABLE_DOLLAR | |
37 | 39 |
38 //PHI = ((sqrt(5)-1)/2) | 40 //PHI = ((sqrt(5)-1)/2) |
39 #define PHI 0.618033989 | 41 #define PHI 0.618033989 |
40 | 42 |
41 typedef struct { | 43 typedef struct { |
55 | 57 |
56 int numPoints; | 58 int numPoints; |
57 Point p[MAXPATHSIZE]; | 59 Point p[MAXPATHSIZE]; |
58 } DollarPath; | 60 } DollarPath; |
59 | 61 |
60 | 62 /* |
61 typedef struct { | 63 typedef struct { |
62 Finger f; | 64 Finger f; |
63 Point cv; | 65 Point cv; |
64 float dtheta,dDist; | 66 float dtheta,dDist; |
65 DollarPath dollarPath; | 67 DollarPath dollarPath; |
66 } TouchPoint; | 68 } TouchPoint; |
67 | 69 */ |
68 typedef struct { | 70 typedef struct { |
69 Point path[DOLLARNPOINTS]; | 71 Point path[DOLLARNPOINTS]; |
70 unsigned long hash; | 72 unsigned long hash; |
71 } DollarTemplate; | 73 } DollarTemplate; |
72 | 74 |
73 typedef struct { | 75 typedef struct { |
74 SDL_GestureID id; | 76 SDL_GestureID id; |
75 Point res; | 77 Point res; |
76 Point centroid; | 78 Point centroid; |
77 TouchPoint gestureLast[MAXFINGERS]; | 79 //TouchPoint gestureLast[MAXFINGERS]; |
80 DollarPath dollarPath; | |
78 Uint16 numDownFingers; | 81 Uint16 numDownFingers; |
79 | 82 |
80 int numDollarTemplates; | 83 int numDollarTemplates; |
81 DollarTemplate dollarTemplate[MAXTEMPLATES]; | 84 DollarTemplate dollarTemplate[MAXTEMPLATES]; |
82 | 85 |
461 | 464 |
462 #ifdef ENABLE_DOLLAR | 465 #ifdef ENABLE_DOLLAR |
463 if(inTouch->recording) { | 466 if(inTouch->recording) { |
464 inTouch->recording = SDL_FALSE; | 467 inTouch->recording = SDL_FALSE; |
465 Point path[DOLLARNPOINTS]; | 468 Point path[DOLLARNPOINTS]; |
466 dollarNormalize(inTouch->gestureLast[j].dollarPath,path); | 469 dollarNormalize(inTouch->dollarPath,path); |
467 int index; | 470 int index; |
468 if(recordAll) { | 471 if(recordAll) { |
469 index = SDL_AddDollarGesture(NULL,path); | 472 index = SDL_AddDollarGesture(NULL,path); |
470 int i; | 473 int i; |
471 for(i = 0;i < numGestureTouches; i++) | 474 for(i = 0;i < numGestureTouches; i++) |
483 } | 486 } |
484 } | 487 } |
485 else { | 488 else { |
486 int bestTempl; | 489 int bestTempl; |
487 float error; | 490 float error; |
488 error = dollarRecognize(inTouch->gestureLast[j].dollarPath, | 491 error = dollarRecognize(inTouch->dollarPath, |
489 &bestTempl,inTouch); | 492 &bestTempl,inTouch); |
490 if(bestTempl >= 0){ | 493 if(bestTempl >= 0){ |
491 //Send Event | 494 //Send Event |
492 unsigned long gestureId = inTouch->dollarTemplate[bestTempl].hash; | 495 unsigned long gestureId = inTouch->dollarTemplate[bestTempl].hash; |
493 SDL_SendGestureDollar(inTouch,gestureId,error); | 496 SDL_SendGestureDollar(inTouch,gestureId,error); |
494 printf ("%s\n",);("Dollar error: %f\n",error); | 497 //printf ("%s\n",);("Dollar error: %f\n",error); |
495 } | 498 } |
496 } | 499 } |
497 #endif | 500 #endif |
498 //inTouch->gestureLast[j] = inTouch->gestureLast[inTouch->numDownFingers]; | 501 //inTouch->gestureLast[j] = inTouch->gestureLast[inTouch->numDownFingers]; |
499 if(inTouch->numDownFingers > 0) { | 502 if(inTouch->numDownFingers > 0) { |
506 else if(event->type == SDL_FINGERMOTION) { | 509 else if(event->type == SDL_FINGERMOTION) { |
507 float dx = ((float)event->tfinger.dx)/(float)inTouch->res.x; | 510 float dx = ((float)event->tfinger.dx)/(float)inTouch->res.x; |
508 float dy = ((float)event->tfinger.dy)/(float)inTouch->res.y; | 511 float dy = ((float)event->tfinger.dy)/(float)inTouch->res.y; |
509 //printf("dx,dy: (%f,%f)\n",dx,dy); | 512 //printf("dx,dy: (%f,%f)\n",dx,dy); |
510 #ifdef ENABLE_DOLLAR | 513 #ifdef ENABLE_DOLLAR |
511 DollarPath* path = &inTouch->gestureLast[j].dollarPath; | 514 DollarPath* path = &inTouch->dollarPath; |
512 if(path->numPoints < MAXPATHSIZE) { | 515 if(path->numPoints < MAXPATHSIZE) { |
513 path->p[path->numPoints].x = x; | 516 path->p[path->numPoints].x = inTouch->centroid.x; |
514 path->p[path->numPoints].y = y; | 517 path->p[path->numPoints].y = inTouch->centroid.y; |
515 path->length += sqrt(dx*dx + dy*dy); | 518 path->length += sqrt(dx*dx + dy*dy); |
516 path->numPoints++; | 519 path->numPoints++; |
517 } | 520 } |
518 #endif | 521 #endif |
519 Point lastP; | 522 Point lastP; |
586 inTouch->gestureLast[j].f.p.x = x; | 589 inTouch->gestureLast[j].f.p.x = x; |
587 inTouch->gestureLast[j].f.p.y = y; | 590 inTouch->gestureLast[j].f.p.y = y; |
588 inTouch->gestureLast[j].cv.x = 0; | 591 inTouch->gestureLast[j].cv.x = 0; |
589 inTouch->gestureLast[j].cv.y = 0; | 592 inTouch->gestureLast[j].cv.y = 0; |
590 */ | 593 */ |
591 #ifdef ENABlE_DOLLAR | 594 #ifdef ENABLE_DOLLAR |
592 inTouch->gestureLast[j].dollarPath.length = 0; | 595 inTouch->dollarPath.length = 0; |
593 inTouch->gestureLast[j].dollarPath.p[0].x = x; | 596 inTouch->dollarPath.p[0].x = x; |
594 inTouch->gestureLast[j].dollarPath.p[0].y = y; | 597 inTouch->dollarPath.p[0].y = y; |
595 inTouch->gestureLast[j].dollarPath.numPoints = 1; | 598 inTouch->dollarPath.numPoints = 1; |
596 #endif | 599 #endif |
597 } | 600 } |
598 } | 601 } |
599 } | 602 } |
600 | 603 |