Skip to content

Latest commit

 

History

History
647 lines (553 loc) · 20.3 KB

SDL_gesture.c

File metadata and controls

647 lines (553 loc) · 20.3 KB
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
Simple DirectMedia Layer
Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL_config.h"
/* General mouse handling code for SDL */
#include "SDL_events.h"
#include "SDL_events_c.h"
#include "SDL_gesture_c.h"
#if !defined(__PSP__)
#include <memory.h>
#endif
#include <string.h>
#include <stdio.h>
#include <math.h>
/* TODO: Replace with malloc */
#define MAXPATHSIZE 1024
#define DOLLARNPOINTS 64
#define DOLLARSIZE 256
#define ENABLE_DOLLAR
#define PHI 0.618033989
typedef struct {
float x,y;
} SDL_FloatPoint;
typedef struct {
float length;
int numPoints;
SDL_FloatPoint p[MAXPATHSIZE];
} SDL_DollarPath;
typedef struct {
SDL_FloatPoint path[DOLLARNPOINTS];
unsigned long hash;
} SDL_DollarTemplate;
typedef struct {
SDL_TouchID id;
SDL_FloatPoint centroid;
SDL_DollarPath dollarPath;
Uint16 numDownFingers;
int numDollarTemplates;
SDL_DollarTemplate *dollarTemplate;
SDL_bool recording;
} SDL_GestureTouch;
SDL_GestureTouch *SDL_gestureTouch;
int SDL_numGestureTouches = 0;
SDL_bool recordAll;
#if 0
static void PrintPath(SDL_FloatPoint *path)
{
int i;
printf("Path:");
for (i=0; i<DOLLARNPOINTS; i++) {
printf(" (%f,%f)",path[i].x,path[i].y);
}
printf("\n");
}
#endif
int SDL_RecordGesture(SDL_TouchID touchId)
{
int i;
if (touchId < 0) recordAll = SDL_TRUE;
for (i = 0; i < SDL_numGestureTouches; i++) {
if ((touchId < 0) || (SDL_gestureTouch[i].id == touchId)) {
SDL_gestureTouch[i].recording = SDL_TRUE;
if (touchId >= 0)
return 1;
}
}
return (touchId < 0);
}
static unsigned long SDL_HashDollar(SDL_FloatPoint* points)
{
unsigned long hash = 5381;
int i;
for (i = 0; i < DOLLARNPOINTS; i++) {
hash = ((hash<<5) + hash) + (unsigned long)points[i].x;
hash = ((hash<<5) + hash) + (unsigned long)points[i].y;
}
return hash;
}
static int SaveTemplate(SDL_DollarTemplate *templ, SDL_RWops * src)
{
if (src == NULL) return 0;
Aug 21, 2013
Aug 21, 2013
124
125
/* No Longer storing the Hash, rehash on load */
/* if(SDL_RWops.write(src,&(templ->hash),sizeof(templ->hash),1) != 1) return 0; */
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
if (SDL_RWwrite(src,templ->path,
sizeof(templ->path[0]),DOLLARNPOINTS) != DOLLARNPOINTS)
return 0;
return 1;
}
int SDL_SaveAllDollarTemplates(SDL_RWops *src)
{
int i,j,rtrn = 0;
for (i = 0; i < SDL_numGestureTouches; i++) {
SDL_GestureTouch* touch = &SDL_gestureTouch[i];
for (j = 0; j < touch->numDollarTemplates; j++) {
rtrn += SaveTemplate(&touch->dollarTemplate[i],src);
}
}
return rtrn;
}
int SDL_SaveDollarTemplate(SDL_GestureID gestureId, SDL_RWops *src)
{
int i,j;
for (i = 0; i < SDL_numGestureTouches; i++) {
SDL_GestureTouch* touch = &SDL_gestureTouch[i];
for (j = 0; j < touch->numDollarTemplates; j++) {
if (touch->dollarTemplate[i].hash == gestureId) {
return SaveTemplate(&touch->dollarTemplate[i],src);
}
}
}
return SDL_SetError("Unknown gestureId");
}
Aug 21, 2013
Aug 21, 2013
161
/* path is an already sampled set of points
Aug 21, 2013
Aug 21, 2013
162
Returns the index of the gesture on success, or -1 */
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
static int SDL_AddDollarGesture_one(SDL_GestureTouch* inTouch, SDL_FloatPoint* path)
{
SDL_DollarTemplate* dollarTemplate;
SDL_DollarTemplate *templ;
int index;
index = inTouch->numDollarTemplates;
dollarTemplate =
(SDL_DollarTemplate *)SDL_realloc(inTouch->dollarTemplate,
(index + 1) *
sizeof(SDL_DollarTemplate));
if (!dollarTemplate) {
return SDL_OutOfMemory();
}
inTouch->dollarTemplate = dollarTemplate;
templ = &inTouch->dollarTemplate[index];
SDL_memcpy(templ->path, path, DOLLARNPOINTS*sizeof(SDL_FloatPoint));
templ->hash = SDL_HashDollar(templ->path);
inTouch->numDollarTemplates++;
return index;
}
static int SDL_AddDollarGesture(SDL_GestureTouch* inTouch, SDL_FloatPoint* path)
{
int index = -1;
int i = 0;
if (inTouch == NULL) {
if (SDL_numGestureTouches == 0) return -1;
for (i = 0; i < SDL_numGestureTouches; i++) {
inTouch = &SDL_gestureTouch[i];
index = SDL_AddDollarGesture_one(inTouch, path);
if (index < 0)
return -1;
}
Aug 21, 2013
Aug 21, 2013
199
/* Use the index of the last one added. */
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
return index;
} else {
return SDL_AddDollarGesture_one(inTouch, path);
}
return -1;
}
int SDL_LoadDollarTemplates(SDL_TouchID touchId, SDL_RWops *src)
{
int i,loaded = 0;
SDL_GestureTouch *touch = NULL;
if (src == NULL) return 0;
if (touchId >= 0) {
for (i = 0; i < SDL_numGestureTouches; i++)
if (SDL_gestureTouch[i].id == touchId)
touch = &SDL_gestureTouch[i];
if (touch == NULL) return -1;
}
while (1) {
SDL_DollarTemplate templ;
if (SDL_RWread(src,templ.path,sizeof(templ.path[0]),DOLLARNPOINTS) <
DOLLARNPOINTS) break;
if (touchId >= 0) {
Aug 21, 2013
Aug 21, 2013
226
/* printf("Adding loaded gesture to 1 touch\n"); */
227
228
229
230
if (SDL_AddDollarGesture(touch, templ.path) >= 0)
loaded++;
}
else {
Aug 21, 2013
Aug 21, 2013
231
/* printf("Adding to: %i touches\n",SDL_numGestureTouches); */
232
233
for (i = 0; i < SDL_numGestureTouches; i++) {
touch = &SDL_gestureTouch[i];
Aug 21, 2013
Aug 21, 2013
234
235
/* printf("Adding loaded gesture to + touches\n"); */
/* TODO: What if this fails? */
236
237
238
239
240
241
242
243
244
245
246
247
SDL_AddDollarGesture(touch,templ.path);
}
loaded++;
}
}
return loaded;
}
static float dollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ,float ang)
{
Aug 21, 2013
Aug 21, 2013
248
/* SDL_FloatPoint p[DOLLARNPOINTS]; */
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
float dist = 0;
SDL_FloatPoint p;
int i;
for (i = 0; i < DOLLARNPOINTS; i++) {
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));
dist += (float)(SDL_sqrt((p.x-templ[i].x)*(p.x-templ[i].x)+
(p.y-templ[i].y)*(p.y-templ[i].y)));
}
return dist/DOLLARNPOINTS;
}
static float bestDollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ)
{
Aug 20, 2013
Aug 20, 2013
264
265
266
267
/*------------BEGIN DOLLAR BLACKBOX------------------
-TRANSLATED DIRECTLY FROM PSUDEO-CODE AVAILABLE AT-
-"http://depts.washington.edu/aimgroup/proj/dollar/"
*/
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
double ta = -M_PI/4;
double tb = M_PI/4;
double dt = M_PI/90;
float x1 = (float)(PHI*ta + (1-PHI)*tb);
float f1 = dollarDifference(points,templ,x1);
float x2 = (float)((1-PHI)*ta + PHI*tb);
float f2 = dollarDifference(points,templ,x2);
while (SDL_fabs(ta-tb) > dt) {
if (f1 < f2) {
tb = x2;
x2 = x1;
f2 = f1;
x1 = (float)(PHI*ta + (1-PHI)*tb);
f1 = dollarDifference(points,templ,x1);
}
else {
ta = x1;
x1 = x2;
f1 = f2;
x2 = (float)((1-PHI)*ta + PHI*tb);
f2 = dollarDifference(points,templ,x2);
}
}
/*
if (f1 <= f2)
printf("Min angle (x1): %f\n",x1);
else if (f1 > f2)
printf("Min angle (x2): %f\n",x2);
*/
return SDL_min(f1,f2);
}
Aug 21, 2013
Aug 21, 2013
300
/* DollarPath contains raw points, plus (possibly) the calculated length */
301
302
303
304
305
306
307
308
309
310
311
312
static int dollarNormalize(const SDL_DollarPath *path,SDL_FloatPoint *points)
{
int i;
float interval;
float dist;
int numPoints = 0;
SDL_FloatPoint centroid;
float xmin,xmax,ymin,ymax;
float ang;
float w,h;
float length = path->length;
Aug 21, 2013
Aug 21, 2013
313
/* Calculate length if it hasn't already been done */
314
315
316
317
318
319
320
321
if (length <= 0) {
for (i=1;i < path->numPoints; i++) {
float dx = path->p[i ].x - path->p[i-1].x;
float dy = path->p[i ].y - path->p[i-1].y;
length += (float)(SDL_sqrt(dx*dx+dy*dy));
}
}
Aug 21, 2013
Aug 21, 2013
322
/* Resample */
323
324
325
326
327
interval = length/(DOLLARNPOINTS - 1);
dist = interval;
centroid.x = 0;centroid.y = 0;
Aug 21, 2013
Aug 21, 2013
328
/* printf("(%f,%f)\n",path->p[path->numPoints-1].x,path->p[path->numPoints-1].y); */
329
330
331
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)+
(path->p[i-1].y-path->p[i].y)*(path->p[i-1].y-path->p[i].y)));
Aug 21, 2013
Aug 21, 2013
332
/* printf("d = %f dist = %f/%f\n",d,dist,interval); */
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
while (dist + d > interval) {
points[numPoints].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 +
((interval-dist)/d)*(path->p[i].y-path->p[i-1].y);
centroid.x += points[numPoints].x;
centroid.y += points[numPoints].y;
numPoints++;
dist -= interval;
}
dist += d;
}
if (numPoints < DOLLARNPOINTS-1) {
SDL_SetError("ERROR: NumPoints = %i\n",numPoints);
return 0;
}
Aug 21, 2013
Aug 21, 2013
350
/* copy the last point */
351
352
353
354
355
356
points[DOLLARNPOINTS-1] = path->p[path->numPoints-1];
numPoints = DOLLARNPOINTS;
centroid.x /= numPoints;
centroid.y /= numPoints;
Aug 21, 2013
Aug 21, 2013
357
358
/* printf("Centroid (%f,%f)",centroid.x,centroid.y); */
/* Rotate Points so point 0 is left of centroid and solve for the bounding box */
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
xmin = centroid.x;
xmax = centroid.x;
ymin = centroid.y;
ymax = centroid.y;
ang = (float)(SDL_atan2(centroid.y - points[0].y,
centroid.x - points[0].x));
for (i = 0; i<numPoints; i++) {
float px = points[i].x;
float py = points[i].y;
points[i].x = (float)((px - centroid.x)*SDL_cos(ang) -
(py - centroid.y)*SDL_sin(ang) + centroid.x);
points[i].y = (float)((px - centroid.x)*SDL_sin(ang) +
(py - centroid.y)*SDL_cos(ang) + centroid.y);
if (points[i].x < xmin) xmin = 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 > ymax) ymax = points[i].y;
}
Aug 21, 2013
Aug 21, 2013
382
/* Scale points to DOLLARSIZE, and translate to the origin */
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
w = xmax-xmin;
h = ymax-ymin;
for (i=0; i<numPoints; i++) {
points[i].x = (points[i].x - centroid.x)*DOLLARSIZE/w;
points[i].y = (points[i].y - centroid.y)*DOLLARSIZE/h;
}
return numPoints;
}
static float dollarRecognize(const SDL_DollarPath *path,int *bestTempl,SDL_GestureTouch* touch)
{
SDL_FloatPoint points[DOLLARNPOINTS];
int i;
float bestDiff = 10000;
SDL_memset(points, 0, sizeof(points));
dollarNormalize(path,points);
Aug 21, 2013
Aug 21, 2013
403
/* PrintPath(points); */
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
*bestTempl = -1;
for (i = 0; i < touch->numDollarTemplates; i++) {
float diff = bestDollarDifference(points,touch->dollarTemplate[i].path);
if (diff < bestDiff) {bestDiff = diff; *bestTempl = i;}
}
return bestDiff;
}
int SDL_GestureAddTouch(SDL_TouchID touchId)
{
SDL_GestureTouch *gestureTouch = (SDL_GestureTouch *)SDL_realloc(SDL_gestureTouch,
(SDL_numGestureTouches + 1) *
sizeof(SDL_GestureTouch));
if (!gestureTouch) {
return SDL_OutOfMemory();
}
SDL_gestureTouch = gestureTouch;
SDL_gestureTouch[SDL_numGestureTouches].numDownFingers = 0;
SDL_gestureTouch[SDL_numGestureTouches].id = touchId;
SDL_gestureTouch[SDL_numGestureTouches].numDollarTemplates = 0;
SDL_gestureTouch[SDL_numGestureTouches].recording = SDL_FALSE;
SDL_numGestureTouches++;
return 0;
}
static SDL_GestureTouch * SDL_GetGestureTouch(SDL_TouchID id)
{
int i;
for (i = 0; i < SDL_numGestureTouches; i++) {
Aug 21, 2013
Aug 21, 2013
439
/* printf("%i ?= %i\n",SDL_gestureTouch[i].id,id); */
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
if (SDL_gestureTouch[i].id == id)
return &SDL_gestureTouch[i];
}
return NULL;
}
int SDL_SendGestureMulti(SDL_GestureTouch* touch,float dTheta,float dDist)
{
SDL_Event event;
event.mgesture.type = SDL_MULTIGESTURE;
event.mgesture.touchId = touch->id;
event.mgesture.x = touch->centroid.x;
event.mgesture.y = touch->centroid.y;
event.mgesture.dTheta = dTheta;
event.mgesture.dDist = dDist;
event.mgesture.numFingers = touch->numDownFingers;
return SDL_PushEvent(&event) > 0;
}
static int SDL_SendGestureDollar(SDL_GestureTouch* touch,
SDL_GestureID gestureId,float error)
{
SDL_Event event;
event.dgesture.type = SDL_DOLLARGESTURE;
event.dgesture.touchId = touch->id;
event.mgesture.x = touch->centroid.x;
event.mgesture.y = touch->centroid.y;
event.dgesture.gestureId = gestureId;
event.dgesture.error = error;
Aug 21, 2013
Aug 21, 2013
469
/* A finger came up to trigger this event. */
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
event.dgesture.numFingers = touch->numDownFingers + 1;
return SDL_PushEvent(&event) > 0;
}
static int SDL_SendDollarRecord(SDL_GestureTouch* touch,SDL_GestureID gestureId)
{
SDL_Event event;
event.dgesture.type = SDL_DOLLARRECORD;
event.dgesture.touchId = touch->id;
event.dgesture.gestureId = gestureId;
return SDL_PushEvent(&event) > 0;
}
void SDL_GestureProcessEvent(SDL_Event* event)
{
float x,y;
SDL_FloatPoint path[DOLLARNPOINTS];
int index;
int i;
float pathDx, pathDy;
SDL_FloatPoint lastP;
SDL_FloatPoint lastCentroid;
float lDist;
float Dist;
float dtheta;
float dDist;
if (event->type == SDL_FINGERMOTION ||
event->type == SDL_FINGERDOWN ||
event->type == SDL_FINGERUP) {
SDL_GestureTouch* inTouch = SDL_GetGestureTouch(event->tfinger.touchId);
Aug 21, 2013
Aug 21, 2013
504
/* Shouldn't be possible */
505
506
507
508
509
if (inTouch == NULL) return;
x = event->tfinger.x;
y = event->tfinger.y;
Aug 21, 2013
Aug 21, 2013
510
/* Finger Up */
511
512
513
514
515
516
517
if (event->type == SDL_FINGERUP) {
inTouch->numDownFingers--;
#ifdef ENABLE_DOLLAR
if (inTouch->recording) {
inTouch->recording = SDL_FALSE;
dollarNormalize(&inTouch->dollarPath,path);
Aug 21, 2013
Aug 21, 2013
518
/* PrintPath(path); */
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
if (recordAll) {
index = SDL_AddDollarGesture(NULL,path);
for (i = 0; i < SDL_numGestureTouches; i++)
SDL_gestureTouch[i].recording = SDL_FALSE;
}
else {
index = SDL_AddDollarGesture(inTouch,path);
}
if (index >= 0) {
SDL_SendDollarRecord(inTouch,inTouch->dollarTemplate[index].hash);
}
else {
SDL_SendDollarRecord(inTouch,-1);
}
}
else {
int bestTempl;
float error;
error = dollarRecognize(&inTouch->dollarPath,
&bestTempl,inTouch);
if (bestTempl >= 0){
Aug 21, 2013
Aug 21, 2013
541
/* Send Event */
542
543
unsigned long gestureId = inTouch->dollarTemplate[bestTempl].hash;
SDL_SendGestureDollar(inTouch,gestureId,error);
Aug 21, 2013
Aug 21, 2013
544
/* printf ("%s\n",);("Dollar error: %f\n",error); */
545
546
547
}
}
#endif
Aug 21, 2013
Aug 21, 2013
548
/* inTouch->gestureLast[j] = inTouch->gestureLast[inTouch->numDownFingers]; */
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
if (inTouch->numDownFingers > 0) {
inTouch->centroid.x = (inTouch->centroid.x*(inTouch->numDownFingers+1)-
x)/inTouch->numDownFingers;
inTouch->centroid.y = (inTouch->centroid.y*(inTouch->numDownFingers+1)-
y)/inTouch->numDownFingers;
}
}
else if (event->type == SDL_FINGERMOTION) {
float dx = event->tfinger.dx;
float dy = event->tfinger.dy;
#ifdef ENABLE_DOLLAR
SDL_DollarPath* path = &inTouch->dollarPath;
if (path->numPoints < MAXPATHSIZE) {
path->p[path->numPoints].x = inTouch->centroid.x;
path->p[path->numPoints].y = inTouch->centroid.y;
pathDx =
(path->p[path->numPoints].x-path->p[path->numPoints-1].x);
pathDy =
(path->p[path->numPoints].y-path->p[path->numPoints-1].y);
path->length += (float)SDL_sqrt(pathDx*pathDx + pathDy*pathDy);
path->numPoints++;
}
#endif
lastP.x = x - dx;
lastP.y = y - dy;
lastCentroid = inTouch->centroid;
inTouch->centroid.x += dx/inTouch->numDownFingers;
inTouch->centroid.y += dy/inTouch->numDownFingers;
Aug 21, 2013
Aug 21, 2013
578
/* printf("Centrid : (%f,%f)\n",inTouch->centroid.x,inTouch->centroid.y); */
579
if (inTouch->numDownFingers > 1) {
Aug 21, 2013
Aug 21, 2013
580
581
582
SDL_FloatPoint lv; /* Vector from centroid to last x,y position */
SDL_FloatPoint v; /* Vector from centroid to current x,y position */
/* lv = inTouch->gestureLast[j].cv; */
583
584
585
lv.x = lastP.x - lastCentroid.x;
lv.y = lastP.y - lastCentroid.y;
lDist = (float)SDL_sqrt(lv.x*lv.x + lv.y*lv.y);
Aug 21, 2013
Aug 21, 2013
586
/* printf("lDist = %f\n",lDist); */
587
588
v.x = x - inTouch->centroid.x;
v.y = y - inTouch->centroid.y;
Aug 21, 2013
Aug 21, 2013
589
/* inTouch->gestureLast[j].cv = v; */
590
Dist = (float)SDL_sqrt(v.x*v.x+v.y*v.y);
Aug 21, 2013
Aug 21, 2013
591
/* SDL_cos(dTheta) = (v . lv)/(|v| * |lv|) */
Aug 21, 2013
Aug 21, 2013
593
/* Normalize Vectors to simplify angle calculation */
594
595
596
597
598
599
600
lv.x/=lDist;
lv.y/=lDist;
v.x/=Dist;
v.y/=Dist;
dtheta = (float)SDL_atan2(lv.x*v.y - lv.y*v.x,lv.x*v.x + lv.y*v.y);
dDist = (Dist - lDist);
Aug 21, 2013
Aug 21, 2013
601
if (lDist == 0) {dDist = 0;dtheta = 0;} /* To avoid impossible values */
Aug 20, 2013
Aug 20, 2013
602
Aug 21, 2013
Aug 21, 2013
603
/* inTouch->gestureLast[j].dDist = dDist;
Aug 20, 2013
Aug 20, 2013
604
605
606
607
608
609
610
611
inTouch->gestureLast[j].dtheta = dtheta;
printf("dDist = %f, dTheta = %f\n",dDist,dtheta);
gdtheta = gdtheta*.9 + dtheta*.1;
gdDist = gdDist*.9 + dDist*.1
knob.r += dDist/numDownFingers;
knob.ang += dtheta;
printf("thetaSum = %f, distSum = %f\n",gdtheta,gdDist);
Aug 21, 2013
Aug 21, 2013
612
printf("id: %i dTheta = %f, dDist = %f\n",j,dtheta,dDist); */
613
614
615
SDL_SendGestureMulti(inTouch,dtheta,dDist);
}
else {
Aug 21, 2013
Aug 21, 2013
616
/* inTouch->gestureLast[j].dDist = 0;
Aug 20, 2013
Aug 20, 2013
617
618
inTouch->gestureLast[j].dtheta = 0;
inTouch->gestureLast[j].cv.x = 0;
Aug 21, 2013
Aug 21, 2013
619
inTouch->gestureLast[j].cv.y = 0; */
Aug 21, 2013
Aug 21, 2013
621
/* inTouch->gestureLast[j].f.p.x = x;
Aug 20, 2013
Aug 20, 2013
622
623
inTouch->gestureLast[j].f.p.y = y;
break;
Aug 21, 2013
Aug 21, 2013
624
pressure? */
625
626
627
628
629
630
631
632
633
}
if (event->type == SDL_FINGERDOWN) {
inTouch->numDownFingers++;
inTouch->centroid.x = (inTouch->centroid.x*(inTouch->numDownFingers - 1)+
x)/inTouch->numDownFingers;
inTouch->centroid.y = (inTouch->centroid.y*(inTouch->numDownFingers - 1)+
y)/inTouch->numDownFingers;
Aug 21, 2013
Aug 21, 2013
634
/* printf("Finger Down: (%f,%f). Centroid: (%f,%f\n",x,y,
Aug 21, 2013
Aug 21, 2013
635
inTouch->centroid.x,inTouch->centroid.y); */
636
637
638
639
640
641
642
643
644
645
646
647
#ifdef ENABLE_DOLLAR
inTouch->dollarPath.length = 0;
inTouch->dollarPath.p[0].x = x;
inTouch->dollarPath.p[0].y = y;
inTouch->dollarPath.numPoints = 1;
#endif
}
}
}
/* vi: set ts=4 sw=4 expandtab: */