Mercurial > sdl-ios-xcode
annotate touchTest/gestureTest.c @ 4651:86c171888eee
Added gesture test c file. Beginning of gesture recognition.
author | Jim Grandpre <jim.tla@gmail.com> |
---|---|
date | Mon, 14 Jun 2010 01:44:04 -0400 |
parents | |
children | 744b75ad18b8 |
rev | line source |
---|---|
4651
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
1 #include <stdio.h> |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
2 #include <SDL.h> |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
3 #include <math.h> |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
4 #include <SDL_touch.h> |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
5 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
6 #define PI 3.1415926535897 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
7 #define WIDTH 640 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
8 #define HEIGHT 480 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
9 #define BPP 4 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
10 #define DEPTH 32 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
11 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
12 #define MAXFINGERS 3 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
13 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
14 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
15 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
16 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
17 //MUST BE A POWER OF 2! |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
18 #define EVENT_BUF_SIZE 256 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
19 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
20 SDL_Event events[EVENT_BUF_SIZE]; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
21 int eventWrite; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
22 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
23 int mousx,mousy; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
24 int keystat[512]; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
25 int bstatus; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
26 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
27 int colors[7] = {0xFF,0xFF00,0xFF0000,0xFFFF00,0x00FFFF,0xFF00FF,0xFFFFFF}; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
28 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
29 int index2fingerid[MAXFINGERS]; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
30 int fingersDown; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
31 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
32 typedef struct { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
33 float x,y; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
34 } Point; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
35 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
36 typedef struct { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
37 Point p; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
38 float pressure; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
39 int id; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
40 } Finger; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
41 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
42 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
43 Finger finger[MAXFINGERS]; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
44 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
45 Finger gestureLast[MAXFINGERS]; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
46 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
47 void handler (int sig) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
48 { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
49 printf ("\exiting...(%d)\n", sig); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
50 exit (0); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
51 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
52 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
53 void perror_exit (char *error) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
54 { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
55 perror (error); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
56 handler (9); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
57 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
58 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
59 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
60 void setpix(SDL_Surface *screen, int x, int y, unsigned int col) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
61 { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
62 Uint32 *pixmem32; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
63 Uint32 colour; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
64 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
65 if((unsigned)x > screen->w) return; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
66 if((unsigned)y > screen->h) return; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
67 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
68 pixmem32 = (Uint32*) screen->pixels + y*screen->pitch/BPP + x; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
69 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
70 Uint8 r,g,b; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
71 float a; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
72 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
73 memcpy(&colour,pixmem32,screen->format->BytesPerPixel); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
74 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
75 SDL_GetRGB(colour,screen->format,&r,&g,&b); //Always returns 0xFFFFFF? |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
76 //r = 0;g = 0; b = 0; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
77 a = (col>>24)&0xFF; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
78 if(a == 0) a = 0xFF; //Hack, to make things easier. |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
79 a /= 0xFF; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
80 r = r*(1-a) + ((col>>16)&0xFF)*(a); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
81 g = g*(1-a) + ((col>> 8)&0xFF)*(a); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
82 b = b*(1-a) + ((col>> 0)&0xFF)*(a); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
83 colour = SDL_MapRGB( screen->format,r, g, b); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
84 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
85 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
86 *pixmem32 = colour; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
87 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
88 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
89 void drawCircle(SDL_Surface* screen,int x,int y,int r,unsigned int c) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
90 { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
91 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
92 float a; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
93 int tx; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
94 /* |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
95 for(a=0;a<PI/2;a+=1.f/(float)abs(r)) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
96 { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
97 if(r > 0) { //r > 0 ==> filled circle |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
98 for(tx=x-r*cos(a);tx<x+r*cos(a);tx++) { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
99 setpix(screen,tx,(int)(y+r*sin(a)),c); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
100 setpix(screen,tx,(int)(y-r*sin(a)),c); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
101 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
102 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
103 else { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
104 //Draw Outline |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
105 setpix(screen,(int)(x+r*cos(a)),(int)(y+r*sin(a)),c); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
106 setpix(screen,(int)(x-r*cos(a)),(int)(y+r*sin(a)),c); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
107 setpix(screen,(int)(x+r*cos(a)),(int)(y-r*sin(a)),c); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
108 setpix(screen,(int)(x-r*cos(a)),(int)(y-r*sin(a)),c); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
109 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
110 }*/ |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
111 int ty; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
112 float xr; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
113 for(ty = -abs(r);ty <= abs(r);ty++) { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
114 xr = sqrt(r*r - ty*ty); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
115 if(r > 0) { //r > 0 ==> filled circle |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
116 for(tx=-xr+.5;tx<=xr-.5;tx++) { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
117 setpix(screen,x+tx,y+ty,c); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
118 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
119 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
120 else { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
121 setpix(screen,x-xr+.5,y+ty,c); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
122 setpix(screen,x+xr-.5,y+ty,c); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
123 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
124 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
125 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
126 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
127 void DrawScreen(SDL_Surface* screen, int h) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
128 { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
129 int x, y, xm,ym,c; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
130 if(SDL_MUSTLOCK(screen)) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
131 { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
132 if(SDL_LockSurface(screen) < 0) return; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
133 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
134 for(y = 0; y < screen->h; y++ ) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
135 { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
136 for( x = 0; x < screen->w; x++ ) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
137 { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
138 //setpixel(screen, x, y, (x*x)/256+3*y+h, (y*y)/256+x+h, h); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
139 //xm = (x+h)%screen->w; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
140 //ym = (y+h)%screen->w; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
141 //c = sin(h/256*2*PI)*x*y/screen->w/screen->h; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
142 //setpix(screen,x,y,255*sin(xm/screen->w*2*PI),sin(h/255*2*PI)*255*y/screen->h,c); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
143 setpix(screen,x,y,((x%255)<<16) + ((y%255)<<8) + (x+y)%255); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
144 //setpix(screen,x,y,0); //Inefficient, but that's okay... |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
145 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
146 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
147 drawCircle(screen,mousx,mousy,-30,0xFFFFFF); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
148 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
149 int i; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
150 //draw Touch History |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
151 for(i = 0;i < MAXFINGERS;i++) gestureLast[i].id = -1; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
152 for(i = SDL_max(0,eventWrite - EVENT_BUF_SIZE);i != eventWrite;i++) { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
153 SDL_Event event = events[i&(EVENT_BUF_SIZE-1)]; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
154 int age = eventWrite - i - 1; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
155 if(event.type == SDL_FINGERMOTION || |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
156 event.type == SDL_FINGERDOWN || |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
157 event.type == SDL_FINGERUP) { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
158 SDL_Touch* inTouch = SDL_GetTouch(event.tfinger.touchId); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
159 //SDL_Finger* inFinger = SDL_GetFinger(inTouch,event.tfinger.fingerId); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
160 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
161 float x = ((float)event.tfinger.x)/inTouch->xres; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
162 float y = ((float)event.tfinger.y)/inTouch->yres; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
163 int j,empty = -1; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
164 for(j = 0;j<MAXFINGERS;j++) { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
165 if(gestureLast[j].id == event.tfinger.fingerId) { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
166 if(event.type == SDL_FINGERUP) { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
167 gestureLast[j].id = -1; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
168 break; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
169 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
170 else { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
171 gestureLast[j].p.x = x; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
172 gestureLast[j].p.y = y; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
173 break; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
174 //pressure? |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
175 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
176 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
177 else if(gestureLast[j].id == -1 && empty == -1) { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
178 empty = j; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
179 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
180 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
181 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
182 if(j >= MAXFINGERS && empty >= 0) { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
183 printf("Finger Down!!!\n"); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
184 j = empty; //important that j is the index of the added finger |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
185 gestureLast[j].id = event.tfinger.fingerId; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
186 gestureLast[j].p.x = x; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
187 gestureLast[j].p.y = y; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
188 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
189 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
190 //draw the touch && each centroid: |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
191 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
192 if(gestureLast[j].id < 0) continue; //Finger up. Or some error... |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
193 int k; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
194 for(k = 0; k < MAXFINGERS;k++) { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
195 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
196 if(gestureLast[k].id < 0) continue; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
197 //colors have no alpha, so shouldn't overflow |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
198 unsigned int c = (colors[gestureLast[j].id%7] + |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
199 colors[gestureLast[k].id%7])/2; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
200 unsigned int col = |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
201 ((unsigned int)(c*(.1+.85))) | |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
202 ((unsigned int)((0xFF*(1-((float)age)/EVENT_BUF_SIZE))) & 0xFF)<<24; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
203 x = (gestureLast[j].p.x + gestureLast[k].p.x)/2; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
204 y = (gestureLast[j].p.y + gestureLast[k].p.y)/2; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
205 if(event.type == SDL_FINGERMOTION) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
206 drawCircle(screen,x*screen->w,y*screen->h,5,col); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
207 else if(event.type == SDL_FINGERDOWN) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
208 drawCircle(screen,x*screen->w,y*screen->h,-10,col); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
209 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
210 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
211 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
212 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
213 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
214 for(i=0;i<MAXFINGERS;i++) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
215 if(finger[i].p.x >= 0 && finger[i].p.y >= 0) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
216 if(finger[i].pressure > 0) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
217 drawCircle(screen,finger[i].p.x*screen->w,finger[i].p.y*screen->h |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
218 ,20,0xFF*finger[i].pressure); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
219 else |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
220 drawCircle(screen,finger[i].p.x*screen->w,finger[i].p.y*screen->h |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
221 ,20,0xFF); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
222 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
223 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
224 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
225 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
226 if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
227 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
228 SDL_Flip(screen); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
229 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
230 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
231 SDL_Surface* initScreen(int width,int height) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
232 { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
233 return SDL_SetVideoMode(width, height, DEPTH, |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
234 SDL_HWSURFACE | SDL_RESIZABLE); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
235 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
236 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
237 int main(int argc, char* argv[]) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
238 { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
239 SDL_Surface *screen; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
240 SDL_Event event; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
241 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
242 int keypress = 0; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
243 int h=0,s=1,i,j; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
244 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
245 memset(keystat,0,512*sizeof(keystat[0])); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
246 if (SDL_Init(SDL_INIT_VIDEO) < 0 ) return 1; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
247 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
248 if (!(screen = initScreen(WIDTH,HEIGHT))) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
249 { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
250 SDL_Quit(); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
251 return 1; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
252 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
253 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
254 while(!keystat[27]) { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
255 //Poll SDL |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
256 while(SDL_PollEvent(&event)) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
257 { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
258 //Record _all_ events |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
259 events[eventWrite & (EVENT_BUF_SIZE-1)] = event; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
260 eventWrite++; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
261 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
262 switch (event.type) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
263 { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
264 case SDL_QUIT: |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
265 keystat[27] = 1; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
266 break; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
267 case SDL_KEYDOWN: |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
268 //printf("%i\n",event.key.keysym.sym); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
269 keystat[event.key.keysym.sym] = 1; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
270 //keypress = 1; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
271 break; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
272 case SDL_KEYUP: |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
273 //printf("%i\n",event.key.keysym.sym); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
274 keystat[event.key.keysym.sym] = 0; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
275 //keypress = 1; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
276 break; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
277 case SDL_VIDEORESIZE: |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
278 if (!(screen = initScreen(event.resize.w, |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
279 event.resize.h))) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
280 { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
281 SDL_Quit(); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
282 return 1; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
283 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
284 break; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
285 case SDL_MOUSEMOTION: |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
286 mousx = event.motion.x; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
287 mousy = event.motion.y; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
288 break; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
289 case SDL_MOUSEBUTTONDOWN: |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
290 bstatus |= (1<<(event.button.button-1)); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
291 break; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
292 case SDL_MOUSEBUTTONUP: |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
293 bstatus &= ~(1<<(event.button.button-1)); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
294 break; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
295 case SDL_FINGERMOTION: |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
296 ; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
297 //printf("Finger: %i,x: %i, y: %i\n",event.tfinger.fingerId, |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
298 // event.tfinger.x,event.tfinger.y); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
299 SDL_Touch* inTouch = SDL_GetTouch(event.tfinger.touchId); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
300 SDL_Finger* inFinger = SDL_GetFinger(inTouch,event.tfinger.fingerId); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
301 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
302 for(i = 0;i<MAXFINGERS;i++) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
303 if(index2fingerid[i] == event.tfinger.fingerId) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
304 break; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
305 if(i == MAXFINGERS) break; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
306 if(inTouch > 0) { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
307 finger[i].p.x = ((float)event.tfinger.x)/ |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
308 inTouch->xres; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
309 finger[i].p.y = ((float)event.tfinger.y)/ |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
310 inTouch->yres; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
311 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
312 finger[i].pressure = |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
313 ((float)event.tfinger.pressure)/inTouch->pressureres; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
314 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
315 printf("Finger: %i, Pressure: %f Pressureres: %i\n", |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
316 event.tfinger.fingerId, |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
317 finger[i].pressure, |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
318 inTouch->pressureres); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
319 //printf("Finger: %i, pressure: %f\n",event.tfinger.fingerId, |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
320 // finger[event.tfinger.fingerId].pressure); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
321 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
322 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
323 break; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
324 case SDL_FINGERDOWN: |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
325 printf("Finger: %i down - x: %i, y: %i\n",event.tfinger.fingerId, |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
326 event.tfinger.x,event.tfinger.y); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
327 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
328 for(i = 0;i<MAXFINGERS;i++) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
329 if(index2fingerid[i] == -1) { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
330 index2fingerid[i] = event.tfinger.fingerId; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
331 break; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
332 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
333 finger[i].p.x = event.tfinger.x; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
334 finger[i].p.y = event.tfinger.y; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
335 break; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
336 case SDL_FINGERUP: |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
337 printf("Figner: %i up - x: %i, y: %i\n",event.tfinger.fingerId, |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
338 event.tfinger.x,event.tfinger.y); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
339 for(i = 0;i<MAXFINGERS;i++) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
340 if(index2fingerid[i] == event.tfinger.fingerId) { |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
341 index2fingerid[i] = -1; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
342 break; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
343 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
344 finger[i].p.x = -1; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
345 finger[i].p.y = -1; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
346 break; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
347 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
348 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
349 //And draw |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
350 DrawScreen(screen,h); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
351 /* |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
352 for(i=0;i<512;i++) |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
353 if(keystat[i]) printf("%i\n",i); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
354 printf("Buttons:%i\n",bstatus); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
355 */ |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
356 } |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
357 SDL_Quit(); |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
358 |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
359 return 0; |
86c171888eee
Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
360 } |