Mercurial > sdl-ios-xcode
annotate src/events/SDL_gesture.c @ 4689:f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
author | Jim Grandpre <jim.tla@gmail.com> |
---|---|
date | Sun, 15 Aug 2010 00:36:28 -0400 |
parents | 494f71f57a80 |
children | fff50e86c891 27c458e4ae31 |
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 |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
30 |
4658
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
31 #define MAXPATHSIZE 1024 |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
32 |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
33 |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
34 |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
35 |
4658
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
36 #define DOLLARNPOINTS 64 |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
37 #define DOLLARSIZE 256 |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
38 |
4684
f47c2640c667
Re-enabled dollar gesture
Jim Grandpre <jim.tla@gmail.com>
parents:
4683
diff
changeset
|
39 #define ENABLE_DOLLAR |
f47c2640c667
Re-enabled dollar gesture
Jim Grandpre <jim.tla@gmail.com>
parents:
4683
diff
changeset
|
40 |
4658
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
41 //PHI = ((sqrt(5)-1)/2) |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
42 #define PHI 0.618033989 |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
43 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
44 typedef struct { |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
45 float x,y; |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
46 } SDL_FloatPoint; |
4658
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
47 |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
48 typedef struct { |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
49 float length; |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
50 |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
51 int numPoints; |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
52 SDL_FloatPoint p[MAXPATHSIZE]; |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
53 } SDL_DollarPath; |
4658
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
54 |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
55 typedef struct { |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
56 SDL_FloatPoint path[DOLLARNPOINTS]; |
4659
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
57 unsigned long hash; |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
58 } SDL_DollarTemplate; |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
59 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
60 typedef struct { |
4678
f8431f66613d
Added SDL_TouchID, SDL_FingerID, SDL_GestureID types. Converted to integer cioordinates (<- not working).
jimtla
parents:
4665
diff
changeset
|
61 SDL_GestureID id; |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
62 SDL_FloatPoint res; |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
63 SDL_FloatPoint centroid; |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
64 SDL_DollarPath dollarPath; |
4683
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
65 Uint16 numDownFingers; |
4658
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
66 |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
67 int numDollarTemplates; |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
68 SDL_DollarTemplate *dollarTemplate; |
4659
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
69 |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
70 SDL_bool recording; |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
71 } SDL_GestureTouch; |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
72 |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
73 SDL_GestureTouch *SDL_gestureTouch; |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
74 int SDL_numGestureTouches = 0; |
4659
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
75 SDL_bool recordAll; |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
76 |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
77 void SDL_PrintPath(SDL_FloatPoint *path) { |
4685
e0c3b09368a6
Fixed Dollar Recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4684
diff
changeset
|
78 int i; |
e0c3b09368a6
Fixed Dollar Recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4684
diff
changeset
|
79 printf("Path:"); |
e0c3b09368a6
Fixed Dollar Recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4684
diff
changeset
|
80 for(i=0;i<DOLLARNPOINTS;i++) { |
e0c3b09368a6
Fixed Dollar Recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4684
diff
changeset
|
81 printf(" (%f,%f)",path[i].x,path[i].y); |
e0c3b09368a6
Fixed Dollar Recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4684
diff
changeset
|
82 } |
e0c3b09368a6
Fixed Dollar Recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4684
diff
changeset
|
83 printf("\n"); |
e0c3b09368a6
Fixed Dollar Recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4684
diff
changeset
|
84 } |
e0c3b09368a6
Fixed Dollar Recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4684
diff
changeset
|
85 |
4678
f8431f66613d
Added SDL_TouchID, SDL_FingerID, SDL_GestureID types. Converted to integer cioordinates (<- not working).
jimtla
parents:
4665
diff
changeset
|
86 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
|
87 int i; |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
88 if(touchId < 0) recordAll = SDL_TRUE; |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
89 for(i = 0;i < SDL_numGestureTouches; i++) { |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
90 if((touchId < 0) || (SDL_gestureTouch[i].id == touchId)) { |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
91 SDL_gestureTouch[i].recording = SDL_TRUE; |
4659
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
92 if(touchId >= 0) |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
93 return 1; |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
94 } |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
95 } |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
96 return (touchId < 0); |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
97 } |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
98 |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
99 unsigned long SDL_HashDollar(SDL_FloatPoint* points) { |
4659
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
100 unsigned long hash = 5381; |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
101 int i; |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
102 for(i = 0;i < DOLLARNPOINTS; i++) { |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
103 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
|
104 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
|
105 } |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
106 return hash; |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
107 } |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
108 |
4665 | 109 |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
110 static int SaveTemplate(SDL_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
|
111 if(src == NULL) return 0; |
4665 | 112 |
4659
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
113 int i; |
4664
317a151b79ad
Bug fixes, now using RWops instead of File pointers.
Jim Grandpre <jim.tla@gmail.com>
parents:
4659
diff
changeset
|
114 |
317a151b79ad
Bug fixes, now using RWops instead of File pointers.
Jim Grandpre <jim.tla@gmail.com>
parents:
4659
diff
changeset
|
115 //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
|
116 //if(SDL_RWops.write(src,&(templ->hash),sizeof(templ->hash),1) != 1) return 0; |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
117 |
4682
4ba1048a324c
Minimized functionality of gestureSDLTest.
Jim Grandpre <jim.tla@gmail.com>
parents:
4681
diff
changeset
|
118 if(SDL_RWwrite(src,templ->path, |
4ba1048a324c
Minimized functionality of gestureSDLTest.
Jim Grandpre <jim.tla@gmail.com>
parents:
4681
diff
changeset
|
119 sizeof(templ->path[0]),DOLLARNPOINTS) != DOLLARNPOINTS) |
4ba1048a324c
Minimized functionality of gestureSDLTest.
Jim Grandpre <jim.tla@gmail.com>
parents:
4681
diff
changeset
|
120 return 0; |
4ba1048a324c
Minimized functionality of gestureSDLTest.
Jim Grandpre <jim.tla@gmail.com>
parents:
4681
diff
changeset
|
121 |
4664
317a151b79ad
Bug fixes, now using RWops instead of File pointers.
Jim Grandpre <jim.tla@gmail.com>
parents:
4659
diff
changeset
|
122 return 1; |
4659
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
123 } |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
124 |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
125 |
4664
317a151b79ad
Bug fixes, now using RWops instead of File pointers.
Jim Grandpre <jim.tla@gmail.com>
parents:
4659
diff
changeset
|
126 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
|
127 int i,j,rtrn = 0; |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
128 for(i = 0; i < SDL_numGestureTouches; i++) { |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
129 SDL_GestureTouch* touch = &SDL_gestureTouch[i]; |
4659
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
130 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
|
131 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
|
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 return rtrn; |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
135 } |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
136 |
4678
f8431f66613d
Added SDL_TouchID, SDL_FingerID, SDL_GestureID types. Converted to integer cioordinates (<- not working).
jimtla
parents:
4665
diff
changeset
|
137 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
|
138 int i,j; |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
139 for(i = 0; i < SDL_numGestureTouches; i++) { |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
140 SDL_GestureTouch* touch = &SDL_gestureTouch[i]; |
4659
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
141 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
|
142 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
|
143 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
|
144 } |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
145 } |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
146 } |
4663
56a2d70de945
Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
4659
diff
changeset
|
147 SDL_SetError("Unknown gestureId"); |
56a2d70de945
Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
4659
diff
changeset
|
148 return -1; |
56a2d70de945
Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
4659
diff
changeset
|
149 } |
56a2d70de945
Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
4659
diff
changeset
|
150 |
56a2d70de945
Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
4659
diff
changeset
|
151 //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
|
152 //Returns the index of the gesture on success, or -1 |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
153 static int SDL_AddDollarGesture(SDL_GestureTouch* inTouch,SDL_FloatPoint* path) { |
4663
56a2d70de945
Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
4659
diff
changeset
|
154 if(inTouch == NULL) { |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
155 if(SDL_numGestureTouches == 0) return -1; |
4663
56a2d70de945
Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
4659
diff
changeset
|
156 int i = 0; |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
157 for(i = 0;i < SDL_numGestureTouches; i++) { |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
158 inTouch = &SDL_gestureTouch[i]; |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
159 |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
160 SDL_DollarTemplate* dollarTemplate = |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
161 SDL_realloc(inTouch->dollarTemplate, |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
162 (inTouch->numDollarTemplates + 1) * |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
163 sizeof(SDL_DollarTemplate)); |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
164 if(!dollarTemplate) { |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
165 SDL_OutOfMemory(); |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
166 return -1; |
4663
56a2d70de945
Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
4659
diff
changeset
|
167 } |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
168 |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
169 inTouch->dollarTemplate = dollarTemplate; |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
170 |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
171 SDL_DollarTemplate *templ = |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
172 &inTouch->dollarTemplate[inTouch->numDollarTemplates]; |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
173 memcpy(templ->path,path,DOLLARNPOINTS*sizeof(SDL_FloatPoint)); |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
174 templ->hash = SDL_HashDollar(templ->path); |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
175 inTouch->numDollarTemplates++; |
4663
56a2d70de945
Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
4659
diff
changeset
|
176 } |
56a2d70de945
Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
4659
diff
changeset
|
177 return inTouch->numDollarTemplates - 1; |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
178 } else { |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
179 SDL_DollarTemplate* dollarTemplate = |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
180 SDL_realloc(inTouch->dollarTemplate, |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
181 (inTouch->numDollarTemplates + 1) * |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
182 sizeof(SDL_DollarTemplate)); |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
183 if(!dollarTemplate) { |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
184 SDL_OutOfMemory(); |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
185 return -1; |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
186 } |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
187 |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
188 inTouch->dollarTemplate = dollarTemplate; |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
189 |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
190 SDL_DollarTemplate *templ = |
4663
56a2d70de945
Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
4659
diff
changeset
|
191 &inTouch->dollarTemplate[inTouch->numDollarTemplates]; |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
192 memcpy(templ->path,path,DOLLARNPOINTS*sizeof(SDL_FloatPoint)); |
4663
56a2d70de945
Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
4659
diff
changeset
|
193 templ->hash = SDL_HashDollar(templ->path); |
56a2d70de945
Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
4659
diff
changeset
|
194 inTouch->numDollarTemplates++; |
56a2d70de945
Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
4659
diff
changeset
|
195 return inTouch->numDollarTemplates - 1; |
56a2d70de945
Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
4659
diff
changeset
|
196 } |
56a2d70de945
Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
4659
diff
changeset
|
197 return -1; |
4659
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
198 } |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
199 |
4678
f8431f66613d
Added SDL_TouchID, SDL_FingerID, SDL_GestureID types. Converted to integer cioordinates (<- not working).
jimtla
parents:
4665
diff
changeset
|
200 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
|
201 if(src == NULL) return 0; |
4659
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
202 int i,loaded = 0; |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
203 SDL_GestureTouch *touch = NULL; |
4659
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
204 if(touchId >= 0) { |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
205 for(i = 0;i < SDL_numGestureTouches; i++) |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
206 if(SDL_gestureTouch[i].id == touchId) |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
207 touch = &SDL_gestureTouch[i]; |
4659
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
208 if(touch == NULL) return -1; |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
209 } |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
210 |
4664
317a151b79ad
Bug fixes, now using RWops instead of File pointers.
Jim Grandpre <jim.tla@gmail.com>
parents:
4659
diff
changeset
|
211 while(1) { |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
212 SDL_DollarTemplate templ; |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
213 |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
214 if(SDL_RWread(src,templ.path,sizeof(templ.path[0]),DOLLARNPOINTS) < |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
215 DOLLARNPOINTS) break; |
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 if(touchId >= 0) { |
4664
317a151b79ad
Bug fixes, now using RWops instead of File pointers.
Jim Grandpre <jim.tla@gmail.com>
parents:
4659
diff
changeset
|
218 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
|
219 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
|
220 } |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
221 else { |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
222 printf("Adding to: %i touches\n",SDL_numGestureTouches); |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
223 for(i = 0;i < SDL_numGestureTouches; i++) { |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
224 touch = &SDL_gestureTouch[i]; |
4664
317a151b79ad
Bug fixes, now using RWops instead of File pointers.
Jim Grandpre <jim.tla@gmail.com>
parents:
4659
diff
changeset
|
225 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
|
226 //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
|
227 SDL_AddDollarGesture(touch,templ.path); |
4659
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
228 } |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
229 loaded++; |
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 |
4664
317a151b79ad
Bug fixes, now using RWops instead of File pointers.
Jim Grandpre <jim.tla@gmail.com>
parents:
4659
diff
changeset
|
233 return loaded; |
4659
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
234 } |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
235 |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
236 |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
237 float dollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ,float ang) { |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
238 // SDL_FloatPoint p[DOLLARNPOINTS]; |
4658
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
239 float dist = 0; |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
240 SDL_FloatPoint p; |
4658
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
241 int i; |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
242 for(i = 0; i < DOLLARNPOINTS; i++) { |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
243 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
|
244 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
|
245 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
|
246 (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
|
247 } |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
248 return dist/DOLLARNPOINTS; |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
249 |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
250 } |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
251 |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
252 float bestDollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ) { |
4658
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
253 //------------BEGIN DOLLAR BLACKBOX----------------// |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
254 //-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
|
255 //-"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
|
256 float ta = -M_PI/4; |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
257 float tb = M_PI/4; |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
258 float dt = M_PI/90; |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
259 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
|
260 float f1 = dollarDifference(points,templ,x1); |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
261 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
|
262 float f2 = dollarDifference(points,templ,x2); |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
263 while(abs(ta-tb) > dt) { |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
264 if(f1 < f2) { |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
265 tb = x2; |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
266 x2 = x1; |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
267 f2 = f1; |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
268 x1 = PHI*ta + (1-PHI)*tb; |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
269 f1 = dollarDifference(points,templ,x1); |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
270 } |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
271 else { |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
272 ta = x1; |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
273 x1 = x2; |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
274 f1 = f2; |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
275 x2 = (1-PHI)*ta + PHI*tb; |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
276 f2 = dollarDifference(points,templ,x2); |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
277 } |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
278 } |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
279 /* |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
280 if(f1 <= f2) |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
281 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
|
282 else if(f1 > f2) |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
283 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
|
284 */ |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
285 return SDL_min(f1,f2); |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
286 } |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
287 |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
288 //DollarPath contains raw points, plus (possibly) the calculated length |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
289 int dollarNormalize(SDL_DollarPath path,SDL_FloatPoint *points) { |
4658
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
290 int i; |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
291 //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
|
292 if(path.length <= 0) { |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
293 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
|
294 float dx = path.p[i ].x - |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
295 path.p[i-1].x; |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
296 float dy = path.p[i ].y - |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
297 path.p[i-1].y; |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
298 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
|
299 } |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
300 } |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
301 |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
302 //Resample |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
303 float interval = path.length/(DOLLARNPOINTS - 1); |
4685
e0c3b09368a6
Fixed Dollar Recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4684
diff
changeset
|
304 float dist = interval; |
4658
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
305 |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
306 int numPoints = 0; |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
307 SDL_FloatPoint centroid; |
4685
e0c3b09368a6
Fixed Dollar Recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4684
diff
changeset
|
308 centroid.x = 0;centroid.y = 0; |
e0c3b09368a6
Fixed Dollar Recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4684
diff
changeset
|
309 |
4658
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
310 //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
|
311 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
|
312 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
|
313 (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
|
314 //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
|
315 while(dist + d > interval) { |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
316 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
|
317 ((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
|
318 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
|
319 ((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
|
320 centroid.x += points[numPoints].x; |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
321 centroid.y += points[numPoints].y; |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
322 numPoints++; |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
323 |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
324 dist -= interval; |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
325 } |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
326 dist += d; |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
327 } |
4685
e0c3b09368a6
Fixed Dollar Recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4684
diff
changeset
|
328 if(numPoints < DOLLARNPOINTS-1) { |
e0c3b09368a6
Fixed Dollar Recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4684
diff
changeset
|
329 printf("ERROR: NumPoints = %i\n",numPoints); |
e0c3b09368a6
Fixed Dollar Recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4684
diff
changeset
|
330 return 0; |
e0c3b09368a6
Fixed Dollar Recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4684
diff
changeset
|
331 } |
e0c3b09368a6
Fixed Dollar Recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4684
diff
changeset
|
332 //copy the last point |
e0c3b09368a6
Fixed Dollar Recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4684
diff
changeset
|
333 points[DOLLARNPOINTS-1] = path.p[path.numPoints-1]; |
e0c3b09368a6
Fixed Dollar Recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4684
diff
changeset
|
334 numPoints = DOLLARNPOINTS; |
e0c3b09368a6
Fixed Dollar Recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4684
diff
changeset
|
335 |
4658
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
336 centroid.x /= numPoints; |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
337 centroid.y /= numPoints; |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
338 |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
339 //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
|
340 //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
|
341 float xmin,xmax,ymin,ymax; |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
342 xmin = centroid.x; |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
343 xmax = centroid.x; |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
344 ymin = centroid.y; |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
345 ymax = centroid.y; |
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 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
|
348 centroid.x - points[0].x); |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
349 |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
350 for(i = 0;i<numPoints;i++) { |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
351 float px = points[i].x; |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
352 float py = points[i].y; |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
353 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
|
354 (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
|
355 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
|
356 (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
|
357 |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
358 |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
359 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
|
360 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
|
361 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
|
362 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
|
363 } |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
364 |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
365 //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
|
366 float w = xmax-xmin; |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
367 float h = ymax-ymin; |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
368 |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
369 for(i=0;i<numPoints;i++) { |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
370 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
|
371 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
|
372 } |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
373 return numPoints; |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
374 } |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
375 |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
376 float dollarRecognize(SDL_DollarPath path,int *bestTempl,SDL_GestureTouch* touch) { |
4663
56a2d70de945
Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
4659
diff
changeset
|
377 |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
378 SDL_FloatPoint points[DOLLARNPOINTS]; |
4663
56a2d70de945
Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
4659
diff
changeset
|
379 int numPoints = dollarNormalize(path,points); |
4686
463cd74304b9
Removed some debug prints.
Jim Grandpre <jim.tla@gmail.com>
parents:
4685
diff
changeset
|
380 //SDL_PrintPath(points); |
4663
56a2d70de945
Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
4659
diff
changeset
|
381 int i; |
56a2d70de945
Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
4659
diff
changeset
|
382 |
56a2d70de945
Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
4659
diff
changeset
|
383 int bestDiff = 10000; |
56a2d70de945
Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
4659
diff
changeset
|
384 *bestTempl = -1; |
56a2d70de945
Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
4659
diff
changeset
|
385 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
|
386 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
|
387 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
|
388 } |
56a2d70de945
Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
4659
diff
changeset
|
389 return bestDiff; |
56a2d70de945
Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
4659
diff
changeset
|
390 } |
56a2d70de945
Started trying to build gesture code for iPhone
Sam Lantinga <slouken@libsdl.org>
parents:
4659
diff
changeset
|
391 |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
392 int SDL_GestureAddTouch(SDL_Touch* touch) { |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
393 SDL_GestureTouch *gestureTouch = SDL_realloc(SDL_gestureTouch, |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
394 (SDL_numGestureTouches + 1) * |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
395 sizeof(SDL_GestureTouch)); |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
396 |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
397 if(!gestureTouch) { |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
398 SDL_OutOfMemory(); |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
399 return -1; |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
400 } |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
401 |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
402 SDL_gestureTouch = gestureTouch; |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
403 |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
404 SDL_gestureTouch[SDL_numGestureTouches].res.x = touch->xres; |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
405 SDL_gestureTouch[SDL_numGestureTouches].res.y = touch->yres; |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
406 SDL_gestureTouch[SDL_numGestureTouches].numDownFingers = 0; |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
407 |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
408 SDL_gestureTouch[SDL_numGestureTouches].res.x = touch->xres; |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
409 SDL_gestureTouch[SDL_numGestureTouches].id = touch->id; |
4658
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
410 |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
411 SDL_gestureTouch[SDL_numGestureTouches].numDollarTemplates = 0; |
4659
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
412 |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
413 SDL_gestureTouch[SDL_numGestureTouches].recording = SDL_FALSE; |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
414 |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
415 SDL_numGestureTouches++; |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
416 return 0; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
417 } |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
418 |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
419 int SDL_GestureRemoveTouch(SDL_TouchID id) { |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
420 int i; |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
421 for(i = 0;i < SDL_numGestureTouches; i++) { |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
422 if(SDL_gestureTouch[i].id == id) { |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
423 SDL_numGestureTouches--; |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
424 SDL_gestureTouch[i] = SDL_gestureTouch[SDL_numGestureTouches]; |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
425 return 1; |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
426 } |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
427 } |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
428 return -1; |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
429 } |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
430 |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
431 |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
432 SDL_GestureTouch * SDL_GetGestureTouch(SDL_TouchID id) { |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
433 int i; |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
434 for(i = 0;i < SDL_numGestureTouches; i++) { |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
435 //printf("%i ?= %i\n",SDL_gestureTouch[i].id,id); |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
436 if(SDL_gestureTouch[i].id == id) return &SDL_gestureTouch[i]; |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
437 } |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
438 return NULL; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
439 } |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
440 |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
441 int SDL_SendGestureMulti(SDL_GestureTouch* touch,float dTheta,float dDist) { |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
442 SDL_Event event; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
443 event.mgesture.type = SDL_MULTIGESTURE; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
444 event.mgesture.touchId = touch->id; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
445 event.mgesture.x = touch->centroid.x; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
446 event.mgesture.y = touch->centroid.y; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
447 event.mgesture.dTheta = dTheta; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
448 event.mgesture.dDist = dDist; |
4683
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
449 event.mgesture.numFingers = touch->numDownFingers; |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
450 return SDL_PushEvent(&event) > 0; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
451 } |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
452 |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
453 int SDL_SendGestureDollar(SDL_GestureTouch* touch, |
4678
f8431f66613d
Added SDL_TouchID, SDL_FingerID, SDL_GestureID types. Converted to integer cioordinates (<- not working).
jimtla
parents:
4665
diff
changeset
|
454 SDL_GestureID gestureId,float error) { |
4658
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
455 SDL_Event event; |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
456 event.dgesture.type = SDL_DOLLARGESTURE; |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
457 event.dgesture.touchId = touch->id; |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
458 /* |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
459 //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
|
460 event.mgesture.x = touch->centroid.x; |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
461 event.mgesture.y = touch->centroid.y; |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
462 */ |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
463 event.dgesture.gestureId = gestureId; |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
464 event.dgesture.error = error; |
4689
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
4688
diff
changeset
|
465 //A finger came up to trigger this event. |
f9ab8df6d45a
Added README.touch and README.gesture. Moved touchtest/gestureSDLTest to test/testgesture
Jim Grandpre <jim.tla@gmail.com>
parents:
4688
diff
changeset
|
466 event.dgesture.numFingers = touch->numDownFingers + 1; |
4658
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
467 return SDL_PushEvent(&event) > 0; |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
468 } |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
469 |
4659
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
470 |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
471 int SDL_SendDollarRecord(SDL_GestureTouch* touch,SDL_GestureID gestureId) { |
4659
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
472 SDL_Event event; |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
473 event.dgesture.type = SDL_DOLLARRECORD; |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
474 event.dgesture.touchId = touch->id; |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
475 event.dgesture.gestureId = gestureId; |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4658
diff
changeset
|
476 return SDL_PushEvent(&event) > 0; |
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 |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
480 void SDL_GestureProcessEvent(SDL_Event* event) |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
481 { |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
482 if(event->type == SDL_FINGERMOTION || |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
483 event->type == SDL_FINGERDOWN || |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
484 event->type == SDL_FINGERUP) { |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
485 SDL_GestureTouch* inTouch = SDL_GetGestureTouch(event->tfinger.touchId); |
4683
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
486 |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
487 //Shouldn't be possible |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
488 if(inTouch == NULL) return; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
489 |
4683
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
490 //printf("@ (%i,%i) with res: (%i,%i)\n",(int)event->tfinger.x, |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
491 // (int)event->tfinger.y, |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
492 // (int)inTouch->res.x,(int)inTouch->res.y); |
4658
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
493 |
4683
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
494 |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
495 float x = ((float)event->tfinger.x)/(float)inTouch->res.x; |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
496 float y = ((float)event->tfinger.y)/(float)inTouch->res.y; |
4658
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
497 |
454385d76845
Moved $1 Gestures into the SDL Library
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
498 |
4683
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
499 //Finger Up |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
500 if(event->type == SDL_FINGERUP) { |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
501 inTouch->numDownFingers--; |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
502 |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
503 #ifdef ENABLE_DOLLAR |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
504 if(inTouch->recording) { |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
505 inTouch->recording = SDL_FALSE; |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
506 SDL_FloatPoint path[DOLLARNPOINTS]; |
4684
f47c2640c667
Re-enabled dollar gesture
Jim Grandpre <jim.tla@gmail.com>
parents:
4683
diff
changeset
|
507 dollarNormalize(inTouch->dollarPath,path); |
4686
463cd74304b9
Removed some debug prints.
Jim Grandpre <jim.tla@gmail.com>
parents:
4685
diff
changeset
|
508 //SDL_PrintPath(path); |
4683
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
509 int index; |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
510 if(recordAll) { |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
511 index = SDL_AddDollarGesture(NULL,path); |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
512 int i; |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
513 for(i = 0;i < SDL_numGestureTouches; i++) |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
514 SDL_gestureTouch[i].recording = SDL_FALSE; |
4683
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
515 } |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
516 else { |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
517 index = SDL_AddDollarGesture(inTouch,path); |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
518 } |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
519 |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
520 if(index >= 0) { |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
521 SDL_SendDollarRecord(inTouch,inTouch->dollarTemplate[index].hash); |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
522 } |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
523 else { |
4683
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
524 SDL_SendDollarRecord(inTouch,-1); |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
525 } |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
526 } |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
527 else { |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
528 int bestTempl; |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
529 float error; |
4684
f47c2640c667
Re-enabled dollar gesture
Jim Grandpre <jim.tla@gmail.com>
parents:
4683
diff
changeset
|
530 error = dollarRecognize(inTouch->dollarPath, |
4683
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
531 &bestTempl,inTouch); |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
532 if(bestTempl >= 0){ |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
533 //Send Event |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
534 unsigned long gestureId = inTouch->dollarTemplate[bestTempl].hash; |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
535 SDL_SendGestureDollar(inTouch,gestureId,error); |
4684
f47c2640c667
Re-enabled dollar gesture
Jim Grandpre <jim.tla@gmail.com>
parents:
4683
diff
changeset
|
536 //printf ("%s\n",);("Dollar error: %f\n",error); |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
537 } |
4683
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
538 } |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
539 #endif |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
540 //inTouch->gestureLast[j] = inTouch->gestureLast[inTouch->numDownFingers]; |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
541 if(inTouch->numDownFingers > 0) { |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
542 inTouch->centroid.x = (inTouch->centroid.x*(inTouch->numDownFingers+1)- |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
543 x)/inTouch->numDownFingers; |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
544 inTouch->centroid.y = (inTouch->centroid.y*(inTouch->numDownFingers+1)- |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
545 y)/inTouch->numDownFingers; |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
546 } |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
547 } |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
548 else if(event->type == SDL_FINGERMOTION) { |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
549 float dx = ((float)event->tfinger.dx)/(float)inTouch->res.x; |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
550 float dy = ((float)event->tfinger.dy)/(float)inTouch->res.y; |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
551 //printf("dx,dy: (%f,%f)\n",dx,dy); |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
552 #ifdef ENABLE_DOLLAR |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
553 SDL_DollarPath* path = &inTouch->dollarPath; |
4683
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
554 if(path->numPoints < MAXPATHSIZE) { |
4684
f47c2640c667
Re-enabled dollar gesture
Jim Grandpre <jim.tla@gmail.com>
parents:
4683
diff
changeset
|
555 path->p[path->numPoints].x = inTouch->centroid.x; |
f47c2640c667
Re-enabled dollar gesture
Jim Grandpre <jim.tla@gmail.com>
parents:
4683
diff
changeset
|
556 path->p[path->numPoints].y = inTouch->centroid.y; |
4685
e0c3b09368a6
Fixed Dollar Recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4684
diff
changeset
|
557 float pathDx = |
e0c3b09368a6
Fixed Dollar Recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4684
diff
changeset
|
558 (path->p[path->numPoints].x-path->p[path->numPoints-1].x); |
e0c3b09368a6
Fixed Dollar Recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4684
diff
changeset
|
559 float pathDy = |
e0c3b09368a6
Fixed Dollar Recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4684
diff
changeset
|
560 (path->p[path->numPoints].y-path->p[path->numPoints-1].y); |
e0c3b09368a6
Fixed Dollar Recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4684
diff
changeset
|
561 path->length += sqrt(pathDx*pathDx + pathDy*pathDy); |
4683
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
562 path->numPoints++; |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
563 } |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
564 #endif |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
565 SDL_FloatPoint lastP; |
4683
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
566 lastP.x = x - dx; |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
567 lastP.y = y - dy; |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
568 SDL_FloatPoint lastCentroid; |
4683
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
569 lastCentroid = inTouch->centroid; |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
570 |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
571 inTouch->centroid.x += dx/inTouch->numDownFingers; |
4685
e0c3b09368a6
Fixed Dollar Recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4684
diff
changeset
|
572 inTouch->centroid.y += dy/inTouch->numDownFingers; |
e0c3b09368a6
Fixed Dollar Recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4684
diff
changeset
|
573 //printf("Centrid : (%f,%f)\n",inTouch->centroid.x,inTouch->centroid.y); |
4683
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
574 if(inTouch->numDownFingers > 1) { |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
575 SDL_FloatPoint lv; //Vector from centroid to last x,y position |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
576 SDL_FloatPoint v; //Vector from centroid to current x,y position |
4683
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
577 //lv = inTouch->gestureLast[j].cv; |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
578 lv.x = lastP.x - lastCentroid.x; |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
579 lv.y = lastP.y - lastCentroid.y; |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
580 float lDist = sqrt(lv.x*lv.x + lv.y*lv.y); |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
581 //printf("lDist = %f\n",lDist); |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
582 v.x = x - inTouch->centroid.x; |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
583 v.y = y - inTouch->centroid.y; |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
584 //inTouch->gestureLast[j].cv = v; |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
585 float Dist = sqrt(v.x*v.x+v.y*v.y); |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
586 // cos(dTheta) = (v . lv)/(|v| * |lv|) |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
587 |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
588 //Normalize Vectors to simplify angle calculation |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
589 lv.x/=lDist; |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
590 lv.y/=lDist; |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
591 v.x/=Dist; |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
592 v.y/=Dist; |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
593 float dtheta = atan2(lv.x*v.y - lv.y*v.x,lv.x*v.x + lv.y*v.y); |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
594 |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
595 float dDist = (Dist - lDist); |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
596 if(lDist == 0) {dDist = 0;dtheta = 0;} //To avoid impossible values |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
597 |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
598 //inTouch->gestureLast[j].dDist = dDist; |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
599 //inTouch->gestureLast[j].dtheta = dtheta; |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
600 |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
601 //printf("dDist = %f, dTheta = %f\n",dDist,dtheta); |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
602 //gdtheta = gdtheta*.9 + dtheta*.1; |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
603 //gdDist = gdDist*.9 + dDist*.1 |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
604 //knob.r += dDist/numDownFingers; |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
605 //knob.ang += dtheta; |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
606 //printf("thetaSum = %f, distSum = %f\n",gdtheta,gdDist); |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
607 //printf("id: %i dTheta = %f, dDist = %f\n",j,dtheta,dDist); |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
608 SDL_SendGestureMulti(inTouch,dtheta,dDist); |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
609 } |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
610 else { |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
611 //inTouch->gestureLast[j].dDist = 0; |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
612 //inTouch->gestureLast[j].dtheta = 0; |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
613 //inTouch->gestureLast[j].cv.x = 0; |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
614 //inTouch->gestureLast[j].cv.y = 0; |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
615 } |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
616 //inTouch->gestureLast[j].f.p.x = x; |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
617 //inTouch->gestureLast[j].f.p.y = y; |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
618 //break; |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
619 //pressure? |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
620 } |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
621 |
4683
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
622 if(event->type == SDL_FINGERDOWN) { |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
623 |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
624 inTouch->numDownFingers++; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
625 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
|
626 x)/inTouch->numDownFingers; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
627 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
|
628 y)/inTouch->numDownFingers; |
4688
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
629 //printf("Finger Down: (%f,%f). Centroid: (%f,%f\n",x,y, |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
630 // inTouch->centroid.x,inTouch->centroid.y); |
494f71f57a80
Fixed bugs related to keyboard handling in gestureSDLTest. Fixed gesture code (dynamic memory allocation). Cleaned up gesture and test code.
Jim Grandpre <jim.tla@gmail.com>
parents:
4686
diff
changeset
|
631 |
4684
f47c2640c667
Re-enabled dollar gesture
Jim Grandpre <jim.tla@gmail.com>
parents:
4683
diff
changeset
|
632 #ifdef ENABLE_DOLLAR |
f47c2640c667
Re-enabled dollar gesture
Jim Grandpre <jim.tla@gmail.com>
parents:
4683
diff
changeset
|
633 inTouch->dollarPath.length = 0; |
f47c2640c667
Re-enabled dollar gesture
Jim Grandpre <jim.tla@gmail.com>
parents:
4683
diff
changeset
|
634 inTouch->dollarPath.p[0].x = x; |
f47c2640c667
Re-enabled dollar gesture
Jim Grandpre <jim.tla@gmail.com>
parents:
4683
diff
changeset
|
635 inTouch->dollarPath.p[0].y = y; |
f47c2640c667
Re-enabled dollar gesture
Jim Grandpre <jim.tla@gmail.com>
parents:
4683
diff
changeset
|
636 inTouch->dollarPath.numPoints = 1; |
4683
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
637 #endif |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
638 } |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
639 } |
4683
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
640 } |
15dfe42edbfd
Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents:
4682
diff
changeset
|
641 |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
642 /* 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
|
643 |