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