Mercurial > sdl-ios-xcode
annotate touchTest/gestureTest.c @ 4658:454385d76845
Moved $1 Gestures into the SDL Library
author | Jim Grandpre <jim.tla@gmail.com> |
---|---|
date | Fri, 09 Jul 2010 00:50:40 -0700 |
parents | b5007b7995c6 |
children |
rev | line source |
---|---|
4651
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
1 #include <stdio.h> |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
2 #include <SDL.h> |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
3 #include <math.h> |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
4 #include <SDL_touch.h> |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
5 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
6 #define PI 3.1415926535897 |
4654
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
7 #define PHI ((sqrt(5)-1)/2) |
4651
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
8 #define WIDTH 640 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
9 #define HEIGHT 480 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
10 #define BPP 4 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
11 #define DEPTH 32 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
12 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
13 #define MAXFINGERS 3 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
14 |
4654
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
15 #define DOLLARNPOINTS 64 |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
16 #define DOLLARSIZE 256 |
4651
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
17 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
18 //MUST BE A POWER OF 2! |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
19 #define EVENT_BUF_SIZE 256 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
20 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
21 SDL_Event events[EVENT_BUF_SIZE]; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
22 int eventWrite; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
23 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
24 int mousx,mousy; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
25 int keystat[512]; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
26 int bstatus; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
27 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
28 int colors[7] = {0xFF,0xFF00,0xFF0000,0xFFFF00,0x00FFFF,0xFF00FF,0xFFFFFF}; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
29 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
30 int index2fingerid[MAXFINGERS]; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
31 int fingersDown; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
32 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
33 typedef struct { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
34 float x,y; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
35 } Point; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
36 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
37 typedef struct { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
38 Point p; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
39 float pressure; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
40 int id; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
41 } Finger; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
42 |
4656
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
43 typedef struct { |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
44 Finger f; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
45 Point cv; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
46 float dtheta,dDist; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
47 } TouchPoint; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
48 |
4653
744b75ad18b8
Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents:
4651
diff
changeset
|
49 typedef struct { //dt + s |
744b75ad18b8
Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents:
4651
diff
changeset
|
50 Point d,s; //direction, start |
744b75ad18b8
Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents:
4651
diff
changeset
|
51 int points; |
744b75ad18b8
Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents:
4651
diff
changeset
|
52 } Line; |
744b75ad18b8
Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents:
4651
diff
changeset
|
53 |
4651
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
54 |
4654
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
55 typedef struct { |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
56 float length; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
57 |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
58 int numPoints; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
59 Point p[EVENT_BUF_SIZE]; //To be safe |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
60 } DollarPath; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
61 |
4656
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
62 typedef struct { |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
63 float ang,r; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
64 Point p; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
65 } Knob; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
66 |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
67 Knob knob; |
4654
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
68 |
4651
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
69 Finger finger[MAXFINGERS]; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
70 |
4656
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
71 |
4654
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
72 DollarPath dollarPath[MAXFINGERS]; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
73 |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
74 #define MAXTEMPLATES 4 |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
75 |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
76 Point dollarTemplate[MAXTEMPLATES][DOLLARNPOINTS]; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
77 int numDollarTemplates = 0; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
78 #ifdef DRAW_VECTOR_EST |
4653
744b75ad18b8
Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents:
4651
diff
changeset
|
79 Line gestureLine[MAXFINGERS]; |
4654
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
80 #endif |
4651
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
81 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
82 void handler (int sig) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
83 { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
84 printf ("\exiting...(%d)\n", sig); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
85 exit (0); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
86 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
87 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
88 void perror_exit (char *error) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
89 { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
90 perror (error); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
91 handler (9); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
92 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
93 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
94 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
95 void setpix(SDL_Surface *screen, int x, int y, unsigned int col) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
96 { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
97 Uint32 *pixmem32; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
98 Uint32 colour; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
99 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
100 if((unsigned)x > screen->w) return; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
101 if((unsigned)y > screen->h) return; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
102 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
103 pixmem32 = (Uint32*) screen->pixels + y*screen->pitch/BPP + x; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
104 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
105 Uint8 r,g,b; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
106 float a; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
107 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
108 memcpy(&colour,pixmem32,screen->format->BytesPerPixel); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
109 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
110 SDL_GetRGB(colour,screen->format,&r,&g,&b); //Always returns 0xFFFFFF? |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
111 //r = 0;g = 0; b = 0; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
112 a = (col>>24)&0xFF; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
113 if(a == 0) a = 0xFF; //Hack, to make things easier. |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
114 a /= 0xFF; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
115 r = r*(1-a) + ((col>>16)&0xFF)*(a); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
116 g = g*(1-a) + ((col>> 8)&0xFF)*(a); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
117 b = b*(1-a) + ((col>> 0)&0xFF)*(a); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
118 colour = SDL_MapRGB( screen->format,r, g, b); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
119 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
120 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
121 *pixmem32 = colour; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
122 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
123 |
4653
744b75ad18b8
Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents:
4651
diff
changeset
|
124 void drawLine(SDL_Surface *screen,int x0,int y0,int x1,int y1,unsigned int col) { |
744b75ad18b8
Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents:
4651
diff
changeset
|
125 float t; |
744b75ad18b8
Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents:
4651
diff
changeset
|
126 for(t=0;t<1;t+=1.f/SDL_max(abs(x0-x1),abs(y0-y1))) |
744b75ad18b8
Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents:
4651
diff
changeset
|
127 setpix(screen,x1+t*(x0-x1),y1+t*(y0-y1),col); |
744b75ad18b8
Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents:
4651
diff
changeset
|
128 } |
4651
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
129 void drawCircle(SDL_Surface* screen,int x,int y,int r,unsigned int c) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
130 { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
131 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
132 float a; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
133 int tx; |
4656
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
134 |
4651
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
135 int ty; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
136 float xr; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
137 for(ty = -abs(r);ty <= abs(r);ty++) { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
138 xr = sqrt(r*r - ty*ty); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
139 if(r > 0) { //r > 0 ==> filled circle |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
140 for(tx=-xr+.5;tx<=xr-.5;tx++) { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
141 setpix(screen,x+tx,y+ty,c); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
142 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
143 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
144 else { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
145 setpix(screen,x-xr+.5,y+ty,c); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
146 setpix(screen,x+xr-.5,y+ty,c); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
147 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
148 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
149 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
150 |
4656
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
151 void drawKnob(SDL_Surface* screen,Knob k) { |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
152 printf("Knob: x = %f, y = %f, r = %f, a = %f\n",k.p.x,k.p.y,k.r,k.ang); |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
153 |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
154 drawCircle(screen,k.p.x*screen->w,k.p.y*screen->h,k.r*screen->w,0xFFFFFF); |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
155 |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
156 drawCircle(screen,(k.p.x+k.r/2*cos(k.ang))*screen->w, |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
157 (k.p.y+k.r/2*sin(k.ang))*screen->h,k.r/4*screen->w,0); |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
158 |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
159 } |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
160 |
4654
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
161 void drawDollarPath(SDL_Surface* screen,Point* points,int numPoints, |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
162 int rad,unsigned int col){ |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
163 int i; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
164 for(i=0;i<numPoints;i++) { |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
165 drawCircle(screen,points[i].x+screen->w/2, |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
166 points[i].y+screen->h/2, |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
167 rad,col); |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
168 } |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
169 } |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
170 |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
171 float dollarDifference(Point* points,Point* templ,float ang) { |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
172 // Point p[DOLLARNPOINTS]; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
173 float dist = 0; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
174 Point p; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
175 int i; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
176 for(i = 0; i < DOLLARNPOINTS; i++) { |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
177 p.x = points[i].x * cos(ang) - points[i].y * sin(ang); |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
178 p.y = points[i].x * sin(ang) + points[i].y * cos(ang); |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
179 dist += sqrt((p.x-templ[i].x)*(p.x-templ[i].x)+ |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
180 (p.y-templ[i].y)*(p.y-templ[i].y)); |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
181 } |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
182 return dist/DOLLARNPOINTS; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
183 |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
184 } |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
185 |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
186 float bestDollarDifference(Point* points,Point* templ) { |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
187 //------------BEGIN DOLLAR BLACKBOX----------------// |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
188 //-TRANSLATED DIRECTLY FROM PSUDEO-CODE AVAILABLE AT-// |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
189 //-"http://depts.washington.edu/aimgroup/proj/dollar/"-// |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
190 float ta = -PI/4; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
191 float tb = PI/4; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
192 float dt = PI/90; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
193 float x1 = PHI*ta + (1-PHI)*tb; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
194 float f1 = dollarDifference(points,templ,x1); |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
195 float x2 = (1-PHI)*ta + PHI*tb; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
196 float f2 = dollarDifference(points,templ,x2); |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
197 while(abs(ta-tb) > dt) { |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
198 if(f1 < f2) { |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
199 tb = x2; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
200 x2 = x1; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
201 f2 = f1; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
202 x1 = PHI*ta + (1-PHI)*tb; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
203 f1 = dollarDifference(points,templ,x1); |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
204 } |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
205 else { |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
206 ta = x1; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
207 x1 = x2; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
208 f1 = f2; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
209 x2 = (1-PHI)*ta + PHI*tb; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
210 f2 = dollarDifference(points,templ,x2); |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
211 } |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
212 } |
4656
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
213 /* |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
214 if(f1 <= f2) |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
215 printf("Min angle (x1): %f\n",x1); |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
216 else if(f1 > f2) |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
217 printf("Min angle (x2): %f\n",x2); |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
218 */ |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
219 return SDL_min(f1,f2); |
4654
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
220 } |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
221 |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
222 float dollarRecognize(SDL_Surface* screen, DollarPath path,int *bestTempl) { |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
223 |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
224 Point points[DOLLARNPOINTS]; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
225 int numPoints = dollarNormalize(path,points); |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
226 int i; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
227 |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
228 int k; |
4655
4c94f2023d62
Fixed bugs in input, cleaned up $1
Jim Grandpre <jim.tla@gmail.com>
parents:
4654
diff
changeset
|
229 /* |
4654
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
230 for(k = 0;k<DOLLARNPOINTS;k++) { |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
231 printf("(%f,%f)\n",points[k].x, |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
232 points[k].y); |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
233 } |
4655
4c94f2023d62
Fixed bugs in input, cleaned up $1
Jim Grandpre <jim.tla@gmail.com>
parents:
4654
diff
changeset
|
234 */ |
4654
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
235 drawDollarPath(screen,points,numPoints,-15,0xFF6600); |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
236 |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
237 int bestDiff = 10000; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
238 *bestTempl = -1; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
239 for(i = 0;i < numDollarTemplates;i++) { |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
240 int diff = bestDollarDifference(points,dollarTemplate[i]); |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
241 if(diff < bestDiff) {bestDiff = diff; *bestTempl = i;} |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
242 } |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
243 return bestDiff; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
244 } |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
245 |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
246 //DollarPath contains raw points, plus (possibly) the calculated length |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
247 int dollarNormalize(DollarPath path,Point *points) { |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
248 int i; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
249 //Calculate length if it hasn't already been done |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
250 if(path.length <= 0) { |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
251 for(i=1;i<path.numPoints;i++) { |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
252 float dx = path.p[i ].x - |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
253 path.p[i-1].x; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
254 float dy = path.p[i ].y - |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
255 path.p[i-1].y; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
256 path.length += sqrt(dx*dx+dy*dy); |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
257 } |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
258 } |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
259 |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
260 |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
261 //Resample |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
262 float interval = path.length/(DOLLARNPOINTS - 1); |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
263 float dist = 0; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
264 |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
265 int numPoints = 0; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
266 Point centroid; centroid.x = 0;centroid.y = 0; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
267 //printf("(%f,%f)\n",path.p[path.numPoints-1].x,path.p[path.numPoints-1].y); |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
268 for(i = 1;i < path.numPoints;i++) { |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
269 float d = sqrt((path.p[i-1].x-path.p[i].x)*(path.p[i-1].x-path.p[i].x)+ |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
270 (path.p[i-1].y-path.p[i].y)*(path.p[i-1].y-path.p[i].y)); |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
271 //printf("d = %f dist = %f/%f\n",d,dist,interval); |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
272 while(dist + d > interval) { |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
273 points[numPoints].x = path.p[i-1].x + |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
274 ((interval-dist)/d)*(path.p[i].x-path.p[i-1].x); |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
275 points[numPoints].y = path.p[i-1].y + |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
276 ((interval-dist)/d)*(path.p[i].y-path.p[i-1].y); |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
277 centroid.x += points[numPoints].x; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
278 centroid.y += points[numPoints].y; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
279 numPoints++; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
280 |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
281 dist -= interval; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
282 } |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
283 dist += d; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
284 } |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
285 if(numPoints < 1) return 0; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
286 centroid.x /= numPoints; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
287 centroid.y /= numPoints; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
288 |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
289 //printf("Centroid (%f,%f)",centroid.x,centroid.y); |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
290 //Rotate Points so point 0 is left of centroid and solve for the bounding box |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
291 float xmin,xmax,ymin,ymax; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
292 xmin = centroid.x; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
293 xmax = centroid.x; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
294 ymin = centroid.y; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
295 ymax = centroid.y; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
296 |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
297 float ang = atan2(centroid.y - points[0].y, |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
298 centroid.x - points[0].x); |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
299 |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
300 for(i = 0;i<numPoints;i++) { |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
301 float px = points[i].x; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
302 float py = points[i].y; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
303 points[i].x = (px - centroid.x)*cos(ang) - |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
304 (py - centroid.y)*sin(ang) + centroid.x; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
305 points[i].y = (px - centroid.x)*sin(ang) + |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
306 (py - centroid.y)*cos(ang) + centroid.y; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
307 |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
308 |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
309 if(points[i].x < xmin) xmin = points[i].x; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
310 if(points[i].x > xmax) xmax = points[i].x; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
311 if(points[i].y < ymin) ymin = points[i].y; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
312 if(points[i].y > ymax) ymax = points[i].y; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
313 } |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
314 |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
315 //Scale points to DOLLARSIZE, and translate to the origin |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
316 float w = xmax-xmin; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
317 float h = ymax-ymin; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
318 |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
319 for(i=0;i<numPoints;i++) { |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
320 points[i].x = (points[i].x - centroid.x)*DOLLARSIZE/w; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
321 points[i].y = (points[i].y - centroid.y)*DOLLARSIZE/h; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
322 } |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
323 return numPoints; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
324 } |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
325 |
4651
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
326 void DrawScreen(SDL_Surface* screen, int h) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
327 { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
328 int x, y, xm,ym,c; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
329 if(SDL_MUSTLOCK(screen)) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
330 { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
331 if(SDL_LockSurface(screen) < 0) return; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
332 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
333 for(y = 0; y < screen->h; y++ ) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
334 { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
335 for( x = 0; x < screen->w; x++ ) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
336 { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
337 //setpixel(screen, x, y, (x*x)/256+3*y+h, (y*y)/256+x+h, h); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
338 //xm = (x+h)%screen->w; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
339 //ym = (y+h)%screen->w; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
340 //c = sin(h/256*2*PI)*x*y/screen->w/screen->h; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
341 //setpix(screen,x,y,255*sin(xm/screen->w*2*PI),sin(h/255*2*PI)*255*y/screen->h,c); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
342 setpix(screen,x,y,((x%255)<<16) + ((y%255)<<8) + (x+y)%255); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
343 //setpix(screen,x,y,0); //Inefficient, but that's okay... |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
344 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
345 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
346 drawCircle(screen,mousx,mousy,-30,0xFFFFFF); |
4653
744b75ad18b8
Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents:
4651
diff
changeset
|
347 drawLine(screen,0,0,screen->w,screen->h,0xFFFFFF); |
4656
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
348 |
4651
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
349 int i; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
350 //draw Touch History |
4656
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
351 TouchPoint gestureLast[MAXFINGERS]; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
352 //printf("------------------Start History------------------\n"); |
4653
744b75ad18b8
Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents:
4651
diff
changeset
|
353 for(i = 0;i < MAXFINGERS;i++) { |
4656
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
354 gestureLast[i].f.id = -1; |
4653
744b75ad18b8
Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents:
4651
diff
changeset
|
355 } |
4656
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
356 int numDownFingers = 0; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
357 Point centroid; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
358 float gdtheta,gdDist; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
359 |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
360 |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
361 for(i = SDL_max(0,eventWrite - EVENT_BUF_SIZE);i < eventWrite;i++) { |
4651
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
362 SDL_Event event = events[i&(EVENT_BUF_SIZE-1)]; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
363 int age = eventWrite - i - 1; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
364 if(event.type == SDL_FINGERMOTION || |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
365 event.type == SDL_FINGERDOWN || |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
366 event.type == SDL_FINGERUP) { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
367 SDL_Touch* inTouch = SDL_GetTouch(event.tfinger.touchId); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
368 //SDL_Finger* inFinger = SDL_GetFinger(inTouch,event.tfinger.fingerId); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
369 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
370 float x = ((float)event.tfinger.x)/inTouch->xres; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
371 float y = ((float)event.tfinger.y)/inTouch->yres; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
372 int j,empty = -1; |
4654
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
373 |
4651
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
374 for(j = 0;j<MAXFINGERS;j++) { |
4656
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
375 if(gestureLast[j].f.id == event.tfinger.fingerId) { |
4651
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
376 if(event.type == SDL_FINGERUP) { |
4656
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
377 numDownFingers--; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
378 if(numDownFingers <= 1) { |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
379 gdtheta = 0; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
380 gdDist = 0; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
381 } |
4654
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
382 if(!keystat[32]){ //spacebar |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
383 int bestTempl; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
384 float error = dollarRecognize(screen,dollarPath[j],&bestTempl); |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
385 if(bestTempl >= 0){ |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
386 drawDollarPath(screen,dollarTemplate[bestTempl] |
4656
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
387 ,DOLLARNPOINTS,-15,0x0066FF); |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
388 printf("Dollar error: %f\n",error); |
4654
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
389 } |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
390 |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
391 } |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
392 else if(numDollarTemplates < MAXTEMPLATES) { |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
393 |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
394 dollarNormalize(dollarPath[j], |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
395 dollarTemplate[numDollarTemplates]); |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
396 /* |
4656
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
397 int k; |
4654
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
398 for(k = 0;k<DOLLARNPOINTS;k++) { |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
399 printf("(%f,%f)\n",dollarTemplate[numDollarTemplates][i].x, |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
400 dollarTemplate[numDollarTemplates][i].y); |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
401 }*/ |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
402 numDollarTemplates++; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
403 } |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
404 |
4656
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
405 gestureLast[j].f.id = -1; |
4651
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
406 break; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
407 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
408 else { |
4654
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
409 dollarPath[j].p[dollarPath[j].numPoints].x = x; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
410 dollarPath[j].p[dollarPath[j].numPoints].y = y; |
4656
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
411 float dx = (dollarPath[j].p[dollarPath[j].numPoints ].x- |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
412 dollarPath[j].p[dollarPath[j].numPoints-1].x); |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
413 float dy = (dollarPath[j].p[dollarPath[j].numPoints ].y- |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
414 dollarPath[j].p[dollarPath[j].numPoints-1].y); |
4654
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
415 dollarPath[j].length += sqrt(dx*dx + dy*dy); |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
416 |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
417 dollarPath[j].numPoints++; |
4653
744b75ad18b8
Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents:
4651
diff
changeset
|
418 |
4656
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
419 centroid.x = centroid.x + dx/numDownFingers; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
420 centroid.y = centroid.y + dy/numDownFingers; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
421 if(numDownFingers > 1) { |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
422 Point lv; //Vector from centroid to last x,y position |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
423 Point v; //Vector from centroid to current x,y position |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
424 lv.x = gestureLast[j].cv.x; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
425 lv.y = gestureLast[j].cv.y; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
426 float lDist = sqrt(lv.x*lv.x + lv.y*lv.y); |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
427 |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
428 v.x = x - centroid.x; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
429 v.y = y - centroid.y; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
430 gestureLast[j].cv = v; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
431 float Dist = sqrt(v.x*v.x+v.y*v.y); |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
432 // cos(dTheta) = (v . lv)/(|v| * |lv|) |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
433 |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
434 lv.x/=lDist; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
435 lv.y/=lDist; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
436 v.x/=Dist; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
437 v.y/=Dist; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
438 float dtheta = atan2(lv.x*v.y - lv.y*v.x,lv.x*v.x + lv.y*v.y); |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
439 |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
440 float dDist = (lDist - Dist); |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
441 |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
442 gestureLast[j].dDist = dDist; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
443 gestureLast[j].dtheta = dtheta; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
444 |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
445 //gdtheta = gdtheta*.9 + dtheta*.1; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
446 //gdDist = gdDist*.9 + dDist*.1 |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
447 gdtheta += dtheta; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
448 gdDist += dDist; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
449 |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
450 //printf("thetaSum = %f, distSum = %f\n",gdtheta,gdDist); |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
451 //printf("id: %i dTheta = %f, dDist = %f\n",j,dtheta,dDist); |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
452 } |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
453 else { |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
454 gestureLast[j].dDist = 0; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
455 gestureLast[j].dtheta = 0; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
456 gestureLast[j].cv.x = 0; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
457 gestureLast[j].cv.y = 0; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
458 } |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
459 gestureLast[j].f.p.x = x; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
460 gestureLast[j].f.p.y = y; |
4651
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
461 break; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
462 //pressure? |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
463 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
464 } |
4656
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
465 else if(gestureLast[j].f.id == -1 && empty == -1) { |
4651
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
466 empty = j; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
467 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
468 } |
4654
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
469 |
4651
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
470 if(j >= MAXFINGERS && empty >= 0) { |
4654
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
471 // printf("Finger Down!!!\n"); |
4656
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
472 numDownFingers++; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
473 centroid.x = (centroid.x*(numDownFingers - 1) + x)/numDownFingers; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
474 centroid.y = (centroid.y*(numDownFingers - 1) + y)/numDownFingers; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
475 |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
476 j = empty; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
477 gestureLast[j].f.id = event.tfinger.fingerId; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
478 gestureLast[j].f.p.x = x; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
479 gestureLast[j].f.p.y = y; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
480 |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
481 |
4654
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
482 dollarPath[j].length = 0; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
483 dollarPath[j].p[0].x = x; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
484 dollarPath[j].p[0].y = y; |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
485 dollarPath[j].numPoints = 1; |
4651
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
486 } |
4656
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
487 |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
488 //draw the touch: |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
489 |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
490 if(gestureLast[j].f.id < 0) continue; //Finger up. Or some error... |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
491 |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
492 unsigned int c = colors[gestureLast[j].f.id%7]; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
493 unsigned int col = |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
494 ((unsigned int)(c*(.1+.85))) | |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
495 ((unsigned int)((0xFF*(1-((float)age)/EVENT_BUF_SIZE))) & 0xFF)<<24; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
496 x = gestureLast[j].f.p.x; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
497 y = gestureLast[j].f.p.y; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
498 if(event.type == SDL_FINGERMOTION) |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
499 drawCircle(screen,x*screen->w,y*screen->h,5,col); |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
500 else if(event.type == SDL_FINGERDOWN) |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
501 drawCircle(screen,x*screen->w,y*screen->h,-10,col); |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
502 |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
503 //if there is a centroid, draw it |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
504 if(numDownFingers > 1) { |
4651
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
505 unsigned int col = |
4656
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
506 ((unsigned int)(0xFFFFFF)) | |
4651
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
507 ((unsigned int)((0xFF*(1-((float)age)/EVENT_BUF_SIZE))) & 0xFF)<<24; |
4656
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
508 drawCircle(screen,centroid.x*screen->w,centroid.y*screen->h,5,col); |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
509 } |
4651
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
510 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
511 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
512 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
513 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
514 for(i=0;i<MAXFINGERS;i++) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
515 if(finger[i].p.x >= 0 && finger[i].p.y >= 0) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
516 if(finger[i].pressure > 0) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
517 drawCircle(screen,finger[i].p.x*screen->w,finger[i].p.y*screen->h |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
518 ,20,0xFF*finger[i].pressure); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
519 else |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
520 drawCircle(screen,finger[i].p.x*screen->w,finger[i].p.y*screen->h |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
521 ,20,0xFF); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
522 |
4656
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
523 |
4651
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
524 |
4656
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
525 keystat[32] = 0; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
526 |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
527 if(knob.p.x > 0) |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
528 drawKnob(screen,knob); |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
529 |
4651
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
530 if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
531 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
532 SDL_Flip(screen); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
533 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
534 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
535 SDL_Surface* initScreen(int width,int height) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
536 { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
537 return SDL_SetVideoMode(width, height, DEPTH, |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
538 SDL_HWSURFACE | SDL_RESIZABLE); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
539 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
540 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
541 int main(int argc, char* argv[]) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
542 { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
543 SDL_Surface *screen; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
544 SDL_Event event; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
545 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
546 int keypress = 0; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
547 int h=0,s=1,i,j; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
548 |
4656
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
549 //gesture variables |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
550 int numDownFingers = 0; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
551 float gdtheta = 0,gdDist = 0; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
552 Point centroid; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
553 knob.r = .1; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
554 knob.ang = 0; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
555 TouchPoint gestureLast[MAXFINGERS]; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
556 for(i = 0;i < MAXFINGERS;i++) |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
557 gestureLast[i].f.id = -1; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
558 |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
559 |
4651
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
560 memset(keystat,0,512*sizeof(keystat[0])); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
561 if (SDL_Init(SDL_INIT_VIDEO) < 0 ) return 1; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
562 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
563 if (!(screen = initScreen(WIDTH,HEIGHT))) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
564 { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
565 SDL_Quit(); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
566 return 1; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
567 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
568 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
569 while(!keystat[27]) { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
570 //Poll SDL |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
571 while(SDL_PollEvent(&event)) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
572 { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
573 //Record _all_ events |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
574 events[eventWrite & (EVENT_BUF_SIZE-1)] = event; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
575 eventWrite++; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
576 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
577 switch (event.type) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
578 { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
579 case SDL_QUIT: |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
580 keystat[27] = 1; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
581 break; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
582 case SDL_KEYDOWN: |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
583 //printf("%i\n",event.key.keysym.sym); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
584 keystat[event.key.keysym.sym] = 1; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
585 //keypress = 1; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
586 break; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
587 case SDL_KEYUP: |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
588 //printf("%i\n",event.key.keysym.sym); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
589 keystat[event.key.keysym.sym] = 0; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
590 //keypress = 1; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
591 break; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
592 case SDL_VIDEORESIZE: |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
593 if (!(screen = initScreen(event.resize.w, |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
594 event.resize.h))) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
595 { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
596 SDL_Quit(); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
597 return 1; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
598 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
599 break; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
600 case SDL_MOUSEMOTION: |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
601 mousx = event.motion.x; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
602 mousy = event.motion.y; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
603 break; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
604 case SDL_MOUSEBUTTONDOWN: |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
605 bstatus |= (1<<(event.button.button-1)); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
606 break; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
607 case SDL_MOUSEBUTTONUP: |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
608 bstatus &= ~(1<<(event.button.button-1)); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
609 break; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
610 case SDL_FINGERMOTION: |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
611 ; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
612 //printf("Finger: %i,x: %i, y: %i\n",event.tfinger.fingerId, |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
613 // event.tfinger.x,event.tfinger.y); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
614 SDL_Touch* inTouch = SDL_GetTouch(event.tfinger.touchId); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
615 SDL_Finger* inFinger = SDL_GetFinger(inTouch,event.tfinger.fingerId); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
616 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
617 for(i = 0;i<MAXFINGERS;i++) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
618 if(index2fingerid[i] == event.tfinger.fingerId) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
619 break; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
620 if(i == MAXFINGERS) break; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
621 if(inTouch > 0) { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
622 finger[i].p.x = ((float)event.tfinger.x)/ |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
623 inTouch->xres; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
624 finger[i].p.y = ((float)event.tfinger.y)/ |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
625 inTouch->yres; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
626 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
627 finger[i].pressure = |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
628 ((float)event.tfinger.pressure)/inTouch->pressureres; |
4656
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
629 /* |
4651
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
630 printf("Finger: %i, Pressure: %f Pressureres: %i\n", |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
631 event.tfinger.fingerId, |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
632 finger[i].pressure, |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
633 inTouch->pressureres); |
4656
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
634 */ |
4651
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
635 //printf("Finger: %i, pressure: %f\n",event.tfinger.fingerId, |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
636 // finger[event.tfinger.fingerId].pressure); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
637 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
638 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
639 break; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
640 case SDL_FINGERDOWN: |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
641 printf("Finger: %i down - x: %i, y: %i\n",event.tfinger.fingerId, |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
642 event.tfinger.x,event.tfinger.y); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
643 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
644 for(i = 0;i<MAXFINGERS;i++) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
645 if(index2fingerid[i] == -1) { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
646 index2fingerid[i] = event.tfinger.fingerId; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
647 break; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
648 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
649 finger[i].p.x = event.tfinger.x; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
650 finger[i].p.y = event.tfinger.y; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
651 break; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
652 case SDL_FINGERUP: |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
653 printf("Figner: %i up - x: %i, y: %i\n",event.tfinger.fingerId, |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
654 event.tfinger.x,event.tfinger.y); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
655 for(i = 0;i<MAXFINGERS;i++) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
656 if(index2fingerid[i] == event.tfinger.fingerId) { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
657 index2fingerid[i] = -1; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
658 break; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
659 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
660 finger[i].p.x = -1; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
661 finger[i].p.y = -1; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
662 break; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
663 } |
4656
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
664 |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
665 |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
666 if(event.type == SDL_FINGERMOTION || |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
667 event.type == SDL_FINGERDOWN || |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
668 event.type == SDL_FINGERUP) { |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
669 SDL_Touch* inTouch = SDL_GetTouch(event.tfinger.touchId); |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
670 //SDL_Finger* inFinger = SDL_GetFinger(inTouch,event.tfinger.fingerId); |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
671 |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
672 float x = ((float)event.tfinger.x)/inTouch->xres; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
673 float y = ((float)event.tfinger.y)/inTouch->yres; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
674 int j,empty = -1; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
675 |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
676 for(j = 0;j<MAXFINGERS;j++) { |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
677 if(gestureLast[j].f.id == event.tfinger.fingerId) { |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
678 if(event.type == SDL_FINGERUP) { |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
679 numDownFingers--; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
680 if(numDownFingers <= 1) { |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
681 gdtheta = 0; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
682 gdDist = 0; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
683 } |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
684 gestureLast[j].f.id = -1; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
685 break; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
686 } |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
687 else { |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
688 float dx = x - gestureLast[j].f.p.x; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
689 float dy = y - gestureLast[j].f.p.y; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
690 centroid.x = centroid.x + dx/numDownFingers; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
691 centroid.y = centroid.y + dy/numDownFingers; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
692 if(numDownFingers > 1) { |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
693 Point lv; //Vector from centroid to last x,y position |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
694 Point v; //Vector from centroid to current x,y position |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
695 lv = gestureLast[j].cv; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
696 float lDist = sqrt(lv.x*lv.x + lv.y*lv.y); |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
697 printf("lDist = %f\n",lDist); |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
698 v.x = x - centroid.x; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
699 v.y = y - centroid.y; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
700 gestureLast[j].cv = v; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
701 float Dist = sqrt(v.x*v.x+v.y*v.y); |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
702 // cos(dTheta) = (v . lv)/(|v| * |lv|) |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
703 |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
704 lv.x/=lDist; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
705 lv.y/=lDist; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
706 v.x/=Dist; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
707 v.y/=Dist; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
708 float dtheta = atan2(lv.x*v.y - lv.y*v.x,lv.x*v.x + lv.y*v.y); |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
709 |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
710 float dDist = (Dist - lDist); |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
711 if(lDist == 0) {dDist = 0;dtheta = 0;} |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
712 gestureLast[j].dDist = dDist; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
713 gestureLast[j].dtheta = dtheta; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
714 |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
715 printf("dDist = %f, dTheta = %f\n",dDist,dtheta); |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
716 //gdtheta = gdtheta*.9 + dtheta*.1; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
717 //gdDist = gdDist*.9 + dDist*.1 |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
718 knob.r += dDist/numDownFingers; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
719 knob.ang += dtheta; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
720 //printf("thetaSum = %f, distSum = %f\n",gdtheta,gdDist); |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
721 //printf("id: %i dTheta = %f, dDist = %f\n",j,dtheta,dDist); |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
722 } |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
723 else { |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
724 gestureLast[j].dDist = 0; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
725 gestureLast[j].dtheta = 0; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
726 gestureLast[j].cv.x = 0; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
727 gestureLast[j].cv.y = 0; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
728 } |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
729 gestureLast[j].f.p.x = x; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
730 gestureLast[j].f.p.y = y; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
731 break; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
732 //pressure? |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
733 } |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
734 } |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
735 else if(gestureLast[j].f.id == -1 && empty == -1) { |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
736 empty = j; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
737 } |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
738 } |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
739 |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
740 if(j >= MAXFINGERS && empty >= 0) { |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
741 printf("Finger Down!!!\n"); |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
742 numDownFingers++; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
743 centroid.x = (centroid.x*(numDownFingers - 1) + x)/numDownFingers; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
744 centroid.y = (centroid.y*(numDownFingers - 1) + y)/numDownFingers; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
745 |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
746 j = empty; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
747 gestureLast[j].f.id = event.tfinger.fingerId; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
748 gestureLast[j].f.p.x = x; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
749 gestureLast[j].f.p.y = y; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
750 gestureLast[j].cv.x = 0; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
751 gestureLast[j].cv.y = 0; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
752 } |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
753 |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
754 //draw the touch: |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
755 } |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
756 //And draw |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
757 if(numDownFingers > 1) |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
758 knob.p = centroid; |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
759 else |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
760 knob.p.x = -1; |
4651
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
761 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
762 DrawScreen(screen,h); |
4656
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
763 //printf("c: (%f,%f)\n",centroid.x,centroid.y); |
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
764 //printf("numDownFingers: %i\n",numDownFingers); |
4654
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
765 //for(i=0;i<512;i++) |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
766 // if(keystat[i]) printf("%i\n",i); |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
767 |
7dbcd71216df
Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
4653
diff
changeset
|
768 |
4651
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
769 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
770 SDL_Quit(); |
4656
b5007b7995c6
Added multi-finger gestures
Jim Grandpre <jim.tla@gmail.com>
parents:
4655
diff
changeset
|
771 |
4651
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
772 return 0; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
773 } |