22 #include "../SDL_internal.h"
37 #define MAXPATHSIZE 1024
39 #define DOLLARNPOINTS 64
40 #define DOLLARSIZE 256
44 #define PHI 0.618033989
84 printf(
" (%f,%f)",path[i].
x,path[i].
y);
95 if ((touchId < 0) || (SDL_gestureTouch[i].
id == touchId)) {
101 return (touchId < 0);
107 SDL_gestureTouch =
NULL;
112 unsigned long hash = 5381;
115 hash = ((hash<<5) + hash) + (
unsigned long)points[i].
x;
116 hash = ((hash<<5) + hash) + (
unsigned long)points[i].
y;
131 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
147 sizeof(copy.
path[0]),DOLLARNPOINTS) != DOLLARNPOINTS) {
196 if (!dollarTemplate) {
213 if (inTouch ==
NULL) {
216 inTouch = &SDL_gestureTouch[
i];
231 if (src ==
NULL)
return 0;
234 if (SDL_gestureTouch[i].
id == touchId) {
235 touch = &SDL_gestureTouch[
i];
248 return SDL_SetError(
"could not read any dollar gesture from rwops");
253 #if SDL_BYTEORDER != SDL_LIL_ENDIAN
269 touch = &SDL_gestureTouch[
i];
292 (p.
y-templ[i].
y)*(p.
y-templ[
i].
y)));
307 float x1 = (float)(
PHI*ta + (1-
PHI)*tb);
309 float x2 = (float)((1-
PHI)*ta +
PHI*tb);
316 x1 = (float)(
PHI*ta + (1-
PHI)*tb);
323 x2 = (float)((1-
PHI)*ta +
PHI*tb);
344 float xmin,xmax,ymin,ymax;
352 float dx = path->
p[
i ].
x - path->
p[i-1].
x;
353 float dy = path->
p[
i ].
y - path->
p[i-1].
y;
354 length += (float)(
SDL_sqrt(dx*dx+dy*dy));
362 centroid.
x = 0;centroid.
y = 0;
366 float d = (float)(
SDL_sqrt((path->
p[i-1].
x-path->
p[i].
x)*(path->
p[i-1].
x-path->
p[
i].
x)+
367 (path->
p[i-1].
y-path->
p[i].
y)*(path->
p[i-1].
y-path->
p[
i].
y)));
369 while (dist + d > interval) {
370 points[numPoints].
x = path->
p[i-1].
x +
371 ((interval-dist)/d)*(path->
p[
i].
x-path->
p[i-1].
x);
372 points[numPoints].
y = path->
p[i-1].
y +
373 ((interval-dist)/d)*(path->
p[
i].
y-path->
p[i-1].
y);
374 centroid.
x += points[numPoints].
x;
375 centroid.
y += points[numPoints].
y;
390 centroid.
x /= numPoints;
391 centroid.
y /= numPoints;
401 centroid.
x - points[0].
x));
403 for (i = 0; i<numPoints; i++) {
404 float px = points[
i].
x;
405 float py = points[
i].
y;
406 points[
i].
x = (float)((px - centroid.
x)*
SDL_cos(ang) -
407 (py - centroid.
y)*
SDL_sin(ang) + centroid.
x);
408 points[
i].
y = (float)((px - centroid.
x)*
SDL_sin(ang) +
409 (py - centroid.
y)*
SDL_cos(ang) + centroid.
y);
412 if (points[i].
x < xmin) xmin = points[
i].
x;
413 if (points[i].
x > xmax) xmax = points[
i].
x;
414 if (points[i].
y < ymin) ymin = points[
i].
y;
415 if (points[i].
y > ymax) ymax = points[
i].
y;
422 for (i=0; i<numPoints; i++) {
433 float bestDiff = 10000;
443 if (diff < bestDiff) {bestDiff = diff; *bestTempl =
i;}
458 SDL_gestureTouch = gestureTouch;
462 SDL_numGestureTouches++;
470 if (SDL_gestureTouch[i].
id == touchId) {
475 if (i == SDL_numGestureTouches) {
480 SDL_free(SDL_gestureTouch[i].dollarTemplate);
483 SDL_numGestureTouches--;
484 SDL_memcpy(&SDL_gestureTouch[i], &SDL_gestureTouch[SDL_numGestureTouches],
sizeof(SDL_gestureTouch[i]));
493 if (SDL_gestureTouch[i].
id ==
id)
494 return &SDL_gestureTouch[
i];
503 event.mgesture.touchId = touch->
id;
506 event.mgesture.dTheta = dTheta;
507 event.mgesture.dDist = dDist;
517 event.dgesture.touchId = touch->
id;
520 event.dgesture.gestureId = gestureId;
521 event.dgesture.error = error;
532 event.dgesture.touchId = touch->
id;
533 event.dgesture.gestureId = gestureId;
543 float pathDx, pathDy;
557 if (inTouch ==
NULL)
return;
559 x =
event->tfinger.x;
560 y =
event->tfinger.y;
576 SDL_gestureTouch[i].recording =
SDL_FALSE;
611 float dx =
event->tfinger.dx;
612 float dy =
event->tfinger.dy;
637 lv.
x = lastP.
x - lastCentroid.
x;
638 lv.
y = lastP.
y - lastCentroid.
y;
654 dDist = (Dist - lDist);
655 if (lDist == 0) {dDist = 0;dtheta = 0;}