annotate src/events/SDL_gesture.c @ 4680:229529693289

Fixed sending motion and finger up events
author Sam Lantinga <slouken@libsdl.org>
date Sat, 31 Jul 2010 20:55:33 -0700
parents f8431f66613d
children 5378f2d0754f
rev   line source
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
1 /*
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
3 Copyright (C) 1997-2010 Sam Lantinga
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
4
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
9
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
13 Lesser General Public License for more details.
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
14
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
16 License along with this library; if not, write to the Free Software Founation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
17
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
18 Sam Lantinga
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
19 slouken@libsdl.org
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
20 */
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
21 #include "SDL_config.h"
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
22
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
23 /* General mouse handling code for SDL */
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
24
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
25 #include "SDL_events.h"
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
26 #include "SDL_events_c.h"
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
27 #include "SDL_gesture_c.h"
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
28
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
29 //TODO: Replace with malloc
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
30 #define MAXFINGERS 3
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
31 #define MAXTOUCHES 2
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
32 #define MAXTEMPLATES 4
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
33 #define MAXPATHSIZE 1024
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
34
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
35 #define DOLLARNPOINTS 64
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
36 #define DOLLARSIZE 256
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
37
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
38 //PHI = ((sqrt(5)-1)/2)
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
39 #define PHI 0.618033989
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
40
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
41 typedef struct {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
42 float x,y;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
43 } Point;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
44
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
45
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
46 typedef struct {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
47 Point p;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
48 float pressure;
4678
f8431f66613d Added SDL_TouchID, SDL_FingerID, SDL_GestureID types. Converted to integer cioordinates (<- not working).
jimtla
parents: 4665
diff changeset
49 SDL_FingerID id;
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
50 } Finger;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
51
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
52
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
53 typedef struct {
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
54 float length;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
55
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
56 int numPoints;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
57 Point p[MAXPATHSIZE];
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
58 } DollarPath;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
59
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
60
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
61 typedef struct {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
62 Finger f;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
63 Point cv;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
64 float dtheta,dDist;
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
65 DollarPath dollarPath;
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
66 } TouchPoint;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
67
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
68 typedef struct {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
69 Point path[DOLLARNPOINTS];
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
70 unsigned long hash;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
71 } DollarTemplate;
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
72
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
73 typedef struct {
4678
f8431f66613d Added SDL_TouchID, SDL_FingerID, SDL_GestureID types. Converted to integer cioordinates (<- not working).
jimtla
parents: 4665
diff changeset
74 SDL_GestureID id;
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
75 Point res;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
76 Point centroid;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
77 TouchPoint gestureLast[MAXFINGERS];
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
78 int numDownFingers;
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
79
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
80 int numDollarTemplates;
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
81 DollarTemplate dollarTemplate[MAXTEMPLATES];
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
82
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
83 SDL_bool recording;
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
84 } GestureTouch;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
85
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
86 GestureTouch gestureTouch[MAXTOUCHES];
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
87 int numGestureTouches = 0;
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
88 SDL_bool recordAll;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
89
4678
f8431f66613d Added SDL_TouchID, SDL_FingerID, SDL_GestureID types. Converted to integer cioordinates (<- not working).
jimtla
parents: 4665
diff changeset
90 int SDL_RecordGesture(SDL_TouchID touchId) {
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
91 int i;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
92 if(touchId < 0) recordAll = SDL_TRUE;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
93 for(i = 0;i < numGestureTouches; i++) {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
94 if((touchId < 0) || (gestureTouch[i].id == touchId)) {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
95 gestureTouch[i].recording = SDL_TRUE;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
96 if(touchId >= 0)
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
97 return 1;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
98 }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
99 }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
100 return (touchId < 0);
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
101 }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
102
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
103 unsigned long SDL_HashDollar(Point* points) {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
104 unsigned long hash = 5381;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
105 int i;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
106 for(i = 0;i < DOLLARNPOINTS; i++) {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
107 hash = ((hash<<5) + hash) + points[i].x;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
108 hash = ((hash<<5) + hash) + points[i].y;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
109 }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
110 return hash;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
111 }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
112
4665
c2493813a2f4 Merged changes
Jim Grandpre <jim.tla@gmail.com>
parents: 4664 4663
diff changeset
113
c2493813a2f4 Merged changes
Jim Grandpre <jim.tla@gmail.com>
parents: 4664 4663
diff changeset
114 static int SaveTemplate(DollarTemplate *templ, SDL_RWops * src) {
4664
317a151b79ad Bug fixes, now using RWops instead of File pointers.
Jim Grandpre <jim.tla@gmail.com>
parents: 4659
diff changeset
115 if(src == NULL) return 0;
4665
c2493813a2f4 Merged changes
Jim Grandpre <jim.tla@gmail.com>
parents: 4664 4663
diff changeset
116
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
117 int i;
4664
317a151b79ad Bug fixes, now using RWops instead of File pointers.
Jim Grandpre <jim.tla@gmail.com>
parents: 4659
diff changeset
118
317a151b79ad Bug fixes, now using RWops instead of File pointers.
Jim Grandpre <jim.tla@gmail.com>
parents: 4659
diff changeset
119 //No Longer storing the Hash, rehash on load
317a151b79ad Bug fixes, now using RWops instead of File pointers.
Jim Grandpre <jim.tla@gmail.com>
parents: 4659
diff changeset
120 //fprintf(fp,"%lu ",templ->hash);
317a151b79ad Bug fixes, now using RWops instead of File pointers.
Jim Grandpre <jim.tla@gmail.com>
parents: 4659
diff changeset
121 //if(SDL_RWops.write(src,&(templ->hash),sizeof(templ->hash),1) != 1) return 0;
317a151b79ad Bug fixes, now using RWops instead of File pointers.
Jim Grandpre <jim.tla@gmail.com>
parents: 4659
diff changeset
122
317a151b79ad Bug fixes, now using RWops instead of File pointers.
Jim Grandpre <jim.tla@gmail.com>
parents: 4659
diff changeset
123 /*
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
124 for(i = 0;i < DOLLARNPOINTS;i++) {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
125 fprintf(fp,"%i %i ",(int)templ->path[i].x,(int)templ->path[i].y);
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
126 }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
127 fprintf(fp,"\n");
4665
c2493813a2f4 Merged changes
Jim Grandpre <jim.tla@gmail.com>
parents: 4664 4663
diff changeset
128
4664
317a151b79ad Bug fixes, now using RWops instead of File pointers.
Jim Grandpre <jim.tla@gmail.com>
parents: 4659
diff changeset
129 */
317a151b79ad Bug fixes, now using RWops instead of File pointers.
Jim Grandpre <jim.tla@gmail.com>
parents: 4659
diff changeset
130 if(SDL_RWwrite(src,templ->path,sizeof(templ->path[0]),DOLLARNPOINTS) != DOLLARNPOINTS) return 0;
317a151b79ad Bug fixes, now using RWops instead of File pointers.
Jim Grandpre <jim.tla@gmail.com>
parents: 4659
diff changeset
131 return 1;
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
132 }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
133
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
134
4664
317a151b79ad Bug fixes, now using RWops instead of File pointers.
Jim Grandpre <jim.tla@gmail.com>
parents: 4659
diff changeset
135 int SDL_SaveAllDollarTemplates(SDL_RWops *src) {
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
136 int i,j,rtrn = 0;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
137 for(i = 0; i < numGestureTouches; i++) {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
138 GestureTouch* touch = &gestureTouch[i];
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
139 for(j = 0;j < touch->numDollarTemplates; j++) {
4664
317a151b79ad Bug fixes, now using RWops instead of File pointers.
Jim Grandpre <jim.tla@gmail.com>
parents: 4659
diff changeset
140 rtrn += SaveTemplate(&touch->dollarTemplate[i],src);
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
141 }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
142 }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
143 return rtrn;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
144 }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
145
4678
f8431f66613d Added SDL_TouchID, SDL_FingerID, SDL_GestureID types. Converted to integer cioordinates (<- not working).
jimtla
parents: 4665
diff changeset
146 int SDL_SaveDollarTemplate(SDL_GestureID gestureId, SDL_RWops *src) {
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
147 int i,j;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
148 for(i = 0; i < numGestureTouches; i++) {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
149 GestureTouch* touch = &gestureTouch[i];
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
150 for(j = 0;j < touch->numDollarTemplates; j++) {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
151 if(touch->dollarTemplate[i].hash == gestureId) {
4664
317a151b79ad Bug fixes, now using RWops instead of File pointers.
Jim Grandpre <jim.tla@gmail.com>
parents: 4659
diff changeset
152 return SaveTemplate(&touch->dollarTemplate[i],src);
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
153 }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
154 }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
155 }
4663
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
156 SDL_SetError("Unknown gestureId");
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
157 return -1;
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
158 }
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
159
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
160 //path is an already sampled set of points
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
161 //Returns the index of the gesture on success, or -1
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
162 static int SDL_AddDollarGesture(GestureTouch* inTouch,Point* path) {
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
163 if(inTouch == NULL) {
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
164 if(numGestureTouches == 0) return -1;
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
165 int i = 0;
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
166 for(i = 0;i < numGestureTouches; i++) {
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
167 inTouch = &gestureTouch[i];
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
168 if(inTouch->numDollarTemplates < MAXTEMPLATES) {
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
169 DollarTemplate *templ =
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
170 &inTouch->dollarTemplate[inTouch->numDollarTemplates];
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
171 memcpy(templ->path,path,DOLLARNPOINTS*sizeof(Point));
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
172 templ->hash = SDL_HashDollar(templ->path);
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
173 inTouch->numDollarTemplates++;
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
174 }
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
175 }
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
176 return inTouch->numDollarTemplates - 1;
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
177 }else if(inTouch->numDollarTemplates < MAXTEMPLATES) {
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
178 DollarTemplate *templ =
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
179 &inTouch->dollarTemplate[inTouch->numDollarTemplates];
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
180 memcpy(templ->path,path,DOLLARNPOINTS*sizeof(Point));
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
181 templ->hash = SDL_HashDollar(templ->path);
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
182 inTouch->numDollarTemplates++;
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
183 return inTouch->numDollarTemplates - 1;
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
184 }
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
185 return -1;
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
186 }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
187
4678
f8431f66613d Added SDL_TouchID, SDL_FingerID, SDL_GestureID types. Converted to integer cioordinates (<- not working).
jimtla
parents: 4665
diff changeset
188 int SDL_LoadDollarTemplates(SDL_TouchID touchId, SDL_RWops *src) {
4664
317a151b79ad Bug fixes, now using RWops instead of File pointers.
Jim Grandpre <jim.tla@gmail.com>
parents: 4659
diff changeset
189 if(src == NULL) return 0;
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
190 int i,loaded = 0;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
191 GestureTouch *touch = NULL;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
192 if(touchId >= 0) {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
193 for(i = 0;i < numGestureTouches; i++)
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
194 if(gestureTouch[i].id == touchId)
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
195 touch = &gestureTouch[i];
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
196 if(touch == NULL) return -1;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
197 }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
198
4664
317a151b79ad Bug fixes, now using RWops instead of File pointers.
Jim Grandpre <jim.tla@gmail.com>
parents: 4659
diff changeset
199 while(1) {
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
200 DollarTemplate templ;
4664
317a151b79ad Bug fixes, now using RWops instead of File pointers.
Jim Grandpre <jim.tla@gmail.com>
parents: 4659
diff changeset
201 //fscanf(fp,"%lu ",&templ.hash);
317a151b79ad Bug fixes, now using RWops instead of File pointers.
Jim Grandpre <jim.tla@gmail.com>
parents: 4659
diff changeset
202 /*
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
203 for(i = 0;i < DOLLARNPOINTS; i++) {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
204 int x,y;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
205 if(fscanf(fp,"%i %i ",&x,&y) != 2) break;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
206 templ.path[i].x = x;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
207 templ.path[i].y = y;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
208 }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
209 fscanf(fp,"\n");
4664
317a151b79ad Bug fixes, now using RWops instead of File pointers.
Jim Grandpre <jim.tla@gmail.com>
parents: 4659
diff changeset
210 */
317a151b79ad Bug fixes, now using RWops instead of File pointers.
Jim Grandpre <jim.tla@gmail.com>
parents: 4659
diff changeset
211 if(SDL_RWread(src,templ.path,sizeof(templ.path[0]),DOLLARNPOINTS) < DOLLARNPOINTS) break;
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
212
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
213 if(touchId >= 0) {
4664
317a151b79ad Bug fixes, now using RWops instead of File pointers.
Jim Grandpre <jim.tla@gmail.com>
parents: 4659
diff changeset
214 printf("Adding loaded gesture to 1 touch\n");
317a151b79ad Bug fixes, now using RWops instead of File pointers.
Jim Grandpre <jim.tla@gmail.com>
parents: 4659
diff changeset
215 if(SDL_AddDollarGesture(touch,templ.path)) loaded++;
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
216 }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
217 else {
4664
317a151b79ad Bug fixes, now using RWops instead of File pointers.
Jim Grandpre <jim.tla@gmail.com>
parents: 4659
diff changeset
218 printf("Adding to: %i touches\n",numGestureTouches);
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
219 for(i = 0;i < numGestureTouches; i++) {
4664
317a151b79ad Bug fixes, now using RWops instead of File pointers.
Jim Grandpre <jim.tla@gmail.com>
parents: 4659
diff changeset
220 touch = &gestureTouch[i];
317a151b79ad Bug fixes, now using RWops instead of File pointers.
Jim Grandpre <jim.tla@gmail.com>
parents: 4659
diff changeset
221 printf("Adding loaded gesture to + touches\n");
317a151b79ad Bug fixes, now using RWops instead of File pointers.
Jim Grandpre <jim.tla@gmail.com>
parents: 4659
diff changeset
222 //TODO: What if this fails?
317a151b79ad Bug fixes, now using RWops instead of File pointers.
Jim Grandpre <jim.tla@gmail.com>
parents: 4659
diff changeset
223 SDL_AddDollarGesture(touch,templ.path);
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
224 }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
225 loaded++;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
226 }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
227 }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
228
4664
317a151b79ad Bug fixes, now using RWops instead of File pointers.
Jim Grandpre <jim.tla@gmail.com>
parents: 4659
diff changeset
229 return loaded;
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
230 }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
231
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
232
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
233 float dollarDifference(Point* points,Point* templ,float ang) {
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
234 // Point p[DOLLARNPOINTS];
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
235 float dist = 0;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
236 Point p;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
237 int i;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
238 for(i = 0; i < DOLLARNPOINTS; i++) {
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
239 p.x = points[i].x * cos(ang) - points[i].y * sin(ang);
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
240 p.y = points[i].x * sin(ang) + points[i].y * cos(ang);
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
241 dist += sqrt((p.x-templ[i].x)*(p.x-templ[i].x)+
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
242 (p.y-templ[i].y)*(p.y-templ[i].y));
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
243 }
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
244 return dist/DOLLARNPOINTS;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
245
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
246 }
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
247
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
248 float bestDollarDifference(Point* points,Point* templ) {
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
249 //------------BEGIN DOLLAR BLACKBOX----------------//
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
250 //-TRANSLATED DIRECTLY FROM PSUDEO-CODE AVAILABLE AT-//
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
251 //-"http://depts.washington.edu/aimgroup/proj/dollar/"-//
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
252 float ta = -M_PI/4;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
253 float tb = M_PI/4;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
254 float dt = M_PI/90;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
255 float x1 = PHI*ta + (1-PHI)*tb;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
256 float f1 = dollarDifference(points,templ,x1);
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
257 float x2 = (1-PHI)*ta + PHI*tb;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
258 float f2 = dollarDifference(points,templ,x2);
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
259 while(abs(ta-tb) > dt) {
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
260 if(f1 < f2) {
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
261 tb = x2;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
262 x2 = x1;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
263 f2 = f1;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
264 x1 = PHI*ta + (1-PHI)*tb;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
265 f1 = dollarDifference(points,templ,x1);
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
266 }
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
267 else {
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
268 ta = x1;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
269 x1 = x2;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
270 f1 = f2;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
271 x2 = (1-PHI)*ta + PHI*tb;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
272 f2 = dollarDifference(points,templ,x2);
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
273 }
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
274 }
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
275 /*
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
276 if(f1 <= f2)
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
277 printf("Min angle (x1): %f\n",x1);
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
278 else if(f1 > f2)
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
279 printf("Min angle (x2): %f\n",x2);
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
280 */
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
281 return SDL_min(f1,f2);
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
282 }
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
283
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
284 //DollarPath contains raw points, plus (possibly) the calculated length
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
285 int dollarNormalize(DollarPath path,Point *points) {
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
286 int i;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
287 //Calculate length if it hasn't already been done
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
288 if(path.length <= 0) {
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
289 for(i=1;i<path.numPoints;i++) {
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
290 float dx = path.p[i ].x -
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
291 path.p[i-1].x;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
292 float dy = path.p[i ].y -
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
293 path.p[i-1].y;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
294 path.length += sqrt(dx*dx+dy*dy);
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
295 }
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
296 }
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
297
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
298
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
299 //Resample
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
300 float interval = path.length/(DOLLARNPOINTS - 1);
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
301 float dist = 0;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
302
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
303 int numPoints = 0;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
304 Point centroid; centroid.x = 0;centroid.y = 0;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
305 //printf("(%f,%f)\n",path.p[path.numPoints-1].x,path.p[path.numPoints-1].y);
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
306 for(i = 1;i < path.numPoints;i++) {
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
307 float d = sqrt((path.p[i-1].x-path.p[i].x)*(path.p[i-1].x-path.p[i].x)+
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
308 (path.p[i-1].y-path.p[i].y)*(path.p[i-1].y-path.p[i].y));
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
309 //printf("d = %f dist = %f/%f\n",d,dist,interval);
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
310 while(dist + d > interval) {
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
311 points[numPoints].x = path.p[i-1].x +
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
312 ((interval-dist)/d)*(path.p[i].x-path.p[i-1].x);
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
313 points[numPoints].y = path.p[i-1].y +
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
314 ((interval-dist)/d)*(path.p[i].y-path.p[i-1].y);
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
315 centroid.x += points[numPoints].x;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
316 centroid.y += points[numPoints].y;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
317 numPoints++;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
318
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
319 dist -= interval;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
320 }
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
321 dist += d;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
322 }
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
323 if(numPoints < 1) return 0;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
324 centroid.x /= numPoints;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
325 centroid.y /= numPoints;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
326
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
327 //printf("Centroid (%f,%f)",centroid.x,centroid.y);
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
328 //Rotate Points so point 0 is left of centroid and solve for the bounding box
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
329 float xmin,xmax,ymin,ymax;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
330 xmin = centroid.x;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
331 xmax = centroid.x;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
332 ymin = centroid.y;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
333 ymax = centroid.y;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
334
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
335 float ang = atan2(centroid.y - points[0].y,
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
336 centroid.x - points[0].x);
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
337
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
338 for(i = 0;i<numPoints;i++) {
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
339 float px = points[i].x;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
340 float py = points[i].y;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
341 points[i].x = (px - centroid.x)*cos(ang) -
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
342 (py - centroid.y)*sin(ang) + centroid.x;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
343 points[i].y = (px - centroid.x)*sin(ang) +
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
344 (py - centroid.y)*cos(ang) + centroid.y;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
345
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
346
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
347 if(points[i].x < xmin) xmin = points[i].x;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
348 if(points[i].x > xmax) xmax = points[i].x;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
349 if(points[i].y < ymin) ymin = points[i].y;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
350 if(points[i].y > ymax) ymax = points[i].y;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
351 }
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
352
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
353 //Scale points to DOLLARSIZE, and translate to the origin
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
354 float w = xmax-xmin;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
355 float h = ymax-ymin;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
356
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
357 for(i=0;i<numPoints;i++) {
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
358 points[i].x = (points[i].x - centroid.x)*DOLLARSIZE/w;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
359 points[i].y = (points[i].y - centroid.y)*DOLLARSIZE/h;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
360 }
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
361 return numPoints;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
362 }
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
363
4663
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
364 float dollarRecognize(DollarPath path,int *bestTempl,GestureTouch* touch) {
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
365
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
366 Point points[DOLLARNPOINTS];
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
367 int numPoints = dollarNormalize(path,points);
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
368 int i;
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
369
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
370 int bestDiff = 10000;
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
371 *bestTempl = -1;
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
372 for(i = 0;i < touch->numDollarTemplates;i++) {
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
373 int diff = bestDollarDifference(points,touch->dollarTemplate[i].path);
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
374 if(diff < bestDiff) {bestDiff = diff; *bestTempl = i;}
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
375 }
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
376 return bestDiff;
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
377 }
56a2d70de945 Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents: 4659
diff changeset
378
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
379 int SDL_GestureAddTouch(SDL_Touch* touch) {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
380 if(numGestureTouches >= MAXTOUCHES) return -1;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
381
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
382 gestureTouch[numGestureTouches].res.x = touch->xres;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
383 gestureTouch[numGestureTouches].res.y = touch->yres;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
384 gestureTouch[numGestureTouches].numDownFingers = 0;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
385
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
386 gestureTouch[numGestureTouches].res.x = touch->xres;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
387 gestureTouch[numGestureTouches].id = touch->id;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
388
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
389 gestureTouch[numGestureTouches].numDollarTemplates = 0;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
390
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
391 gestureTouch[numGestureTouches].recording = SDL_FALSE;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
392
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
393 numGestureTouches++;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
394 return 0;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
395 }
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
396
4678
f8431f66613d Added SDL_TouchID, SDL_FingerID, SDL_GestureID types. Converted to integer cioordinates (<- not working).
jimtla
parents: 4665
diff changeset
397 GestureTouch * SDL_GetGestureTouch(SDL_TouchID id) {
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
398 int i;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
399 for(i = 0;i < numGestureTouches; i++) {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
400 //printf("%i ?= %i\n",gestureTouch[i].id,id);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
401 if(gestureTouch[i].id == id) return &gestureTouch[i];
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
402 }
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
403 return NULL;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
404 }
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
405
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
406 int SDL_SendGestureMulti(GestureTouch* touch,float dTheta,float dDist) {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
407 SDL_Event event;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
408 event.mgesture.type = SDL_MULTIGESTURE;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
409 event.mgesture.touchId = touch->id;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
410 event.mgesture.x = touch->centroid.x;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
411 event.mgesture.y = touch->centroid.y;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
412 event.mgesture.dTheta = dTheta;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
413 event.mgesture.dDist = dDist;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
414 return SDL_PushEvent(&event) > 0;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
415 }
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
416
4678
f8431f66613d Added SDL_TouchID, SDL_FingerID, SDL_GestureID types. Converted to integer cioordinates (<- not working).
jimtla
parents: 4665
diff changeset
417 int SDL_SendGestureDollar(GestureTouch* touch,
f8431f66613d Added SDL_TouchID, SDL_FingerID, SDL_GestureID types. Converted to integer cioordinates (<- not working).
jimtla
parents: 4665
diff changeset
418 SDL_GestureID gestureId,float error) {
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
419 SDL_Event event;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
420 event.dgesture.type = SDL_DOLLARGESTURE;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
421 event.dgesture.touchId = touch->id;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
422 /*
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
423 //TODO: Add this to give location of gesture?
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
424 event.mgesture.x = touch->centroid.x;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
425 event.mgesture.y = touch->centroid.y;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
426 */
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
427 event.dgesture.gestureId = gestureId;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
428 event.dgesture.error = error;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
429 return SDL_PushEvent(&event) > 0;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
430 }
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
431
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
432
4678
f8431f66613d Added SDL_TouchID, SDL_FingerID, SDL_GestureID types. Converted to integer cioordinates (<- not working).
jimtla
parents: 4665
diff changeset
433 int SDL_SendDollarRecord(GestureTouch* touch,SDL_GestureID gestureId) {
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
434 SDL_Event event;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
435 event.dgesture.type = SDL_DOLLARRECORD;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
436 event.dgesture.touchId = touch->id;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
437 event.dgesture.gestureId = gestureId;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
438
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
439 return SDL_PushEvent(&event) > 0;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
440 }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
441
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
442
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
443 void SDL_GestureProcessEvent(SDL_Event* event)
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
444 {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
445 if(event->type == SDL_FINGERMOTION ||
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
446 event->type == SDL_FINGERDOWN ||
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
447 event->type == SDL_FINGERUP) {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
448 GestureTouch* inTouch = SDL_GetGestureTouch(event->tfinger.touchId);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
449
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
450 //Shouldn't be possible
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
451 if(inTouch == NULL) return;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
452
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
453
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
454 float x = ((float)event->tfinger.x)/inTouch->res.x;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
455 float y = ((float)event->tfinger.y)/inTouch->res.y;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
456 int j,empty = -1;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
457
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
458 for(j = 0;j<inTouch->numDownFingers;j++) {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
459 if(inTouch->gestureLast[j].f.id != event->tfinger.fingerId) continue;
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
460 //Finger Up
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
461 if(event->type == SDL_FINGERUP) {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
462 inTouch->numDownFingers--;
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
463
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
464 if(inTouch->recording) {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
465 inTouch->recording = SDL_FALSE;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
466 Point path[DOLLARNPOINTS];
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
467 dollarNormalize(inTouch->gestureLast[j].dollarPath,path);
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
468 int index;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
469 if(recordAll) {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
470 index = SDL_AddDollarGesture(NULL,path);
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
471 int i;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
472 for(i = 0;i < numGestureTouches; i++)
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
473 gestureTouch[i].recording = SDL_FALSE;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
474 }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
475 else {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
476 index = SDL_AddDollarGesture(inTouch,path);
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
477 }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
478
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
479 if(index >= 0) {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
480 SDL_SendDollarRecord(inTouch,inTouch->dollarTemplate[index].hash);
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
481 }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
482 else {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
483 SDL_SendDollarRecord(inTouch,-1);
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
484 }
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
485 }
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
486 else {
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
487 int bestTempl;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
488 float error;
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
489 error = dollarRecognize(inTouch->gestureLast[j].dollarPath,
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
490 &bestTempl,inTouch);
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
491 if(bestTempl >= 0){
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
492 //Send Event
4678
f8431f66613d Added SDL_TouchID, SDL_FingerID, SDL_GestureID types. Converted to integer cioordinates (<- not working).
jimtla
parents: 4665
diff changeset
493 unsigned long gestureId = inTouch->dollarTemplate[bestTempl].hash;
4659
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
494 SDL_SendGestureDollar(inTouch,gestureId,error);
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
495 printf("Dollar error: %f\n",error);
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
496 }
063b9455bd1a Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents: 4658
diff changeset
497 }
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
498 inTouch->gestureLast[j] = inTouch->gestureLast[inTouch->numDownFingers];
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
499 break;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
500 }
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
501 else {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
502 float dx = x - inTouch->gestureLast[j].f.p.x;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
503 float dy = y - inTouch->gestureLast[j].f.p.y;
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
504 DollarPath* path = &inTouch->gestureLast[j].dollarPath;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
505 if(path->numPoints < MAXPATHSIZE) {
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
506 path->p[path->numPoints].x = x;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
507 path->p[path->numPoints].y = y;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
508 path->length += sqrt(dx*dx + dy*dy);
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
509 path->numPoints++;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
510 }
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
511
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
512
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
513 inTouch->centroid.x += dx/inTouch->numDownFingers;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
514 inTouch->centroid.y += dy/inTouch->numDownFingers;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
515 if(inTouch->numDownFingers > 1) {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
516 Point lv; //Vector from centroid to last x,y position
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
517 Point v; //Vector from centroid to current x,y position
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
518 lv = inTouch->gestureLast[j].cv;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
519 float lDist = sqrt(lv.x*lv.x + lv.y*lv.y);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
520 //printf("lDist = %f\n",lDist);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
521 v.x = x - inTouch->centroid.x;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
522 v.y = y - inTouch->centroid.y;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
523 inTouch->gestureLast[j].cv = v;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
524 float Dist = sqrt(v.x*v.x+v.y*v.y);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
525 // cos(dTheta) = (v . lv)/(|v| * |lv|)
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
526
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
527 //Normalize Vectors to simplify angle calculation
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
528 lv.x/=lDist;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
529 lv.y/=lDist;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
530 v.x/=Dist;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
531 v.y/=Dist;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
532 float dtheta = atan2(lv.x*v.y - lv.y*v.x,lv.x*v.x + lv.y*v.y);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
533
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
534 float dDist = (Dist - lDist);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
535 if(lDist == 0) {dDist = 0;dtheta = 0;} //To avoid impossible values
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
536 inTouch->gestureLast[j].dDist = dDist;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
537 inTouch->gestureLast[j].dtheta = dtheta;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
538
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
539 //printf("dDist = %f, dTheta = %f\n",dDist,dtheta);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
540 //gdtheta = gdtheta*.9 + dtheta*.1;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
541 //gdDist = gdDist*.9 + dDist*.1
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
542 //knob.r += dDist/numDownFingers;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
543 //knob.ang += dtheta;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
544 //printf("thetaSum = %f, distSum = %f\n",gdtheta,gdDist);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
545 //printf("id: %i dTheta = %f, dDist = %f\n",j,dtheta,dDist);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
546 SDL_SendGestureMulti(inTouch,dtheta,dDist);
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
547 }
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
548 else {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
549 inTouch->gestureLast[j].dDist = 0;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
550 inTouch->gestureLast[j].dtheta = 0;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
551 inTouch->gestureLast[j].cv.x = 0;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
552 inTouch->gestureLast[j].cv.y = 0;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
553 }
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
554 inTouch->gestureLast[j].f.p.x = x;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
555 inTouch->gestureLast[j].f.p.y = y;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
556 break;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
557 //pressure?
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
558 }
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
559 }
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
560
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
561 if(j == inTouch->numDownFingers) {
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
562 //printf("Finger Down!!!\n");
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
563 inTouch->numDownFingers++;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
564 inTouch->centroid.x = (inTouch->centroid.x*(inTouch->numDownFingers - 1)+
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
565 x)/inTouch->numDownFingers;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
566 inTouch->centroid.y = (inTouch->centroid.y*(inTouch->numDownFingers - 1)+
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
567 y)/inTouch->numDownFingers;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
568
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
569 inTouch->gestureLast[j].f.id = event->tfinger.fingerId;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
570 inTouch->gestureLast[j].f.p.x = x;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
571 inTouch->gestureLast[j].f.p.y = y;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
572 inTouch->gestureLast[j].cv.x = 0;
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
573 inTouch->gestureLast[j].cv.y = 0;
4658
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
574
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
575 inTouch->gestureLast[j].dollarPath.length = 0;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
576 inTouch->gestureLast[j].dollarPath.p[0].x = x;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
577 inTouch->gestureLast[j].dollarPath.p[0].y = y;
454385d76845 Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents: 4657
diff changeset
578 inTouch->gestureLast[j].dollarPath.numPoints = 1;
4657
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
579 }
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
580 }
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
581 }
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
582
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
583 /* vi: set ts=4 sw=4 expandtab: */
eed063a0bf5b Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
584