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