Mercurial > sdl-ios-xcode
annotate touchTest/gestureSDLTest.c @ 4662:3c4e0130c9b1
Added alternative finger tracking method. Still prefer IPHONE_TOUCH_EFFICIENT_DANGEROUS.
author | Jim Grandpre <jim.tla@gmail.com> |
---|---|
date | Tue, 13 Jul 2010 18:31:09 -0400 |
parents | 063b9455bd1a |
children | 317a151b79ad |
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> |
4659
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
5 #include <SDL_gesture.h> |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
6 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
7 #define PI 3.1415926535897 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
8 #define PHI ((sqrt(5)-1)/2) |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
9 #define WIDTH 640 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
10 #define HEIGHT 480 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
11 #define BPP 4 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
12 #define DEPTH 32 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
13 |
4662
3c4e0130c9b1
Added alternative finger tracking method. Still prefer IPHONE_TOUCH_EFFICIENT_DANGEROUS.
Jim Grandpre <jim.tla@gmail.com>
parents:
4659
diff
changeset
|
14 #define MAXFINGERS 5 |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
15 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
16 #define DOLLARNPOINTS 64 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
17 #define DOLLARSIZE 256 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
18 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
19 //MUST BE A POWER OF 2! |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
20 #define EVENT_BUF_SIZE 256 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
21 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
22 SDL_Event events[EVENT_BUF_SIZE]; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
23 int eventWrite; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
24 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
25 int mousx,mousy; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
26 int keystat[512]; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
27 int bstatus; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
28 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
29 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
|
30 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
31 int index2fingerid[MAXFINGERS]; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
32 int fingersDown; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
33 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
34 typedef struct { |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
35 float x,y; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
36 } Point; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
37 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
38 typedef struct { |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
39 Point p; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
40 float pressure; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
41 int id; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
42 } Finger; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
43 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
44 typedef struct { |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
45 Finger f; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
46 Point cv; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
47 float dtheta,dDist; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
48 } TouchPoint; |
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 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
51 typedef struct { //dt + s |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
52 Point d,s; //direction, start |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
53 int points; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
54 } Line; |
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 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
57 typedef struct { |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
58 float length; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
59 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
60 int numPoints; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
61 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
|
62 } DollarPath; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
63 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
64 typedef struct { |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
65 float ang,r; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
66 Point p; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
67 } Knob; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
68 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
69 Knob knob; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
70 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
71 Finger finger[MAXFINGERS]; |
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 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
74 DollarPath dollarPath[MAXFINGERS]; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
75 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
76 #define MAXTEMPLATES 4 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
77 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
78 Point dollarTemplate[MAXTEMPLATES][DOLLARNPOINTS]; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
79 int numDollarTemplates = 0; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
80 #ifdef DRAW_VECTOR_EST |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
81 Line gestureLine[MAXFINGERS]; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
82 #endif |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
83 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
84 void handler (int sig) |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
85 { |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
86 printf ("\exiting...(%d)\n", sig); |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
87 exit (0); |
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 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
90 void perror_exit (char *error) |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
91 { |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
92 perror (error); |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
93 handler (9); |
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 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
97 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
|
98 { |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
99 Uint32 *pixmem32; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
100 Uint32 colour; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
101 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
102 if((unsigned)x > screen->w) return; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
103 if((unsigned)y > screen->h) return; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
104 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
105 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
|
106 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
107 Uint8 r,g,b; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
108 float a; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
109 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
110 memcpy(&colour,pixmem32,screen->format->BytesPerPixel); |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
111 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
112 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
|
113 //r = 0;g = 0; b = 0; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
114 a = (col>>24)&0xFF; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
115 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
|
116 a /= 0xFF; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
117 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
|
118 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
|
119 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
|
120 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
|
121 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
122 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
123 *pixmem32 = colour; |
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 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
126 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
|
127 float t; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
128 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
|
129 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
|
130 } |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
131 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
|
132 { |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
133 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
134 float a; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
135 int tx; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
136 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
137 int ty; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
138 float xr; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
139 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
|
140 xr = sqrt(r*r - ty*ty); |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
141 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
|
142 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
|
143 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
|
144 } |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
145 } |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
146 else { |
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 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
|
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 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
153 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
|
154 //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
|
155 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
156 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
|
157 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
158 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
|
159 (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
|
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 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
163 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
|
164 { |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
165 int x, y, xm,ym,c; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
166 if(SDL_MUSTLOCK(screen)) |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
167 { |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
168 if(SDL_LockSurface(screen) < 0) return; |
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 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
|
171 { |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
172 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
|
173 { |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
174 //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
|
175 //xm = (x+h)%screen->w; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
176 //ym = (y+h)%screen->w; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
177 //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
|
178 //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
|
179 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
|
180 //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
|
181 } |
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 drawCircle(screen,mousx,mousy,-30,0xFFFFFF); |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
184 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
|
185 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
186 int i; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
187 //draw Touch History |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
188 TouchPoint gestureLast[MAXFINGERS]; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
189 //printf("------------------Start History------------------\n"); |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
190 for(i = 0;i < MAXFINGERS;i++) { |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
191 gestureLast[i].f.id = -1; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
192 } |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
193 int numDownFingers = 0; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
194 Point centroid; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
195 float gdtheta,gdDist; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
196 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
197 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
198 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
|
199 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
|
200 int age = eventWrite - i - 1; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
201 if(event.type == SDL_FINGERMOTION || |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
202 event.type == SDL_FINGERDOWN || |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
203 event.type == SDL_FINGERUP) { |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
204 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
|
205 //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
|
206 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
207 float x = ((float)event.tfinger.x)/inTouch->xres; |
4659
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
208 float y = ((float)event.tfinger.y)/inTouch->yres; |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
209 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
210 //draw the touch: |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
211 |
4659
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
212 unsigned int c = colors[event.tfinger.touchId%7]; |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
213 unsigned int col = |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
214 ((unsigned int)(c*(.1+.85))) | |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
215 ((unsigned int)((0xFF*(1-((float)age)/EVENT_BUF_SIZE))) & 0xFF)<<24; |
4659
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
216 |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
217 if(event.type == SDL_FINGERMOTION) |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
218 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
|
219 else if(event.type == SDL_FINGERDOWN) |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
220 drawCircle(screen,x*screen->w,y*screen->h,-10,col); |
4659
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
221 /* |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
222 //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
|
223 if(numDownFingers > 1) { |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
224 unsigned int col = |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
225 ((unsigned int)(0xFFFFFF)) | |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
226 ((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
|
227 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
|
228 } |
4659
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
229 */ |
4657
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 } |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
232 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
233 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
234 for(i=0;i<MAXFINGERS;i++) |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
235 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
|
236 if(finger[i].pressure > 0) |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
237 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
|
238 ,20,0xFF*finger[i].pressure); |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
239 else |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
240 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
|
241 ,20,0xFF); |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
242 |
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 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
245 keystat[32] = 0; |
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 if(knob.p.x > 0) |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
248 drawKnob(screen,knob); |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
249 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
250 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
|
251 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
252 SDL_Flip(screen); |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
253 } |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
254 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
255 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
|
256 { |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
257 return SDL_SetVideoMode(width, height, DEPTH, |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
258 SDL_HWSURFACE | SDL_RESIZABLE); |
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 int main(int argc, char* argv[]) |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
262 { |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
263 SDL_Surface *screen; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
264 SDL_Event event; |
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 keypress = 0; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
267 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
|
268 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
269 //gesture variables |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
270 int numDownFingers = 0; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
271 float gdtheta = 0,gdDist = 0; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
272 Point centroid; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
273 knob.r = .1; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
274 knob.ang = 0; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
275 TouchPoint gestureLast[MAXFINGERS]; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
276 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
277 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
278 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
279 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
|
280 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
|
281 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
282 if (!(screen = initScreen(WIDTH,HEIGHT))) |
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 SDL_Quit(); |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
285 return 1; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
286 } |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
287 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
288 while(!keystat[27]) { |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
289 //Poll SDL |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
290 while(SDL_PollEvent(&event)) |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
291 { |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
292 //Record _all_ events |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
293 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
|
294 eventWrite++; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
295 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
296 switch (event.type) |
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 case SDL_QUIT: |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
299 keystat[27] = 1; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
300 break; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
301 case SDL_KEYDOWN: |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
302 //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
|
303 keystat[event.key.keysym.sym] = 1; |
4659
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
304 if(event.key.keysym.sym == 32) { |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
305 SDL_RecordGesture(-1); |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
306 } |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
307 else if(event.key.keysym.sym == 115) { |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
308 FILE *fp; |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
309 fp = fopen("gestureSave","w"); |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
310 SDL_SaveAllDollarTemplates(fp); |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
311 fclose(fp); |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
312 } |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
313 else if(event.key.keysym.sym == 108) { |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
314 FILE *fp; |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
315 fp = fopen("gestureSave","r"); |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
316 printf("Loaded: %i\n",SDL_LoadDollarTemplates(-1,fp)); |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
317 fclose(fp); |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
318 } |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
319 |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
320 //keypress = 1; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
321 break; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
322 case SDL_KEYUP: |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
323 //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
|
324 keystat[event.key.keysym.sym] = 0; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
325 //keypress = 1; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
326 break; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
327 case SDL_VIDEORESIZE: |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
328 if (!(screen = initScreen(event.resize.w, |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
329 event.resize.h))) |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
330 { |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
331 SDL_Quit(); |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
332 return 1; |
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 break; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
335 case SDL_MOUSEMOTION: |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
336 mousx = event.motion.x; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
337 mousy = event.motion.y; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
338 break; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
339 case SDL_MOUSEBUTTONDOWN: |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
340 bstatus |= (1<<(event.button.button-1)); |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
341 break; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
342 case SDL_MOUSEBUTTONUP: |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
343 bstatus &= ~(1<<(event.button.button-1)); |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
344 break; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
345 case SDL_FINGERMOTION: |
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 //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
|
348 // event.tfinger.x,event.tfinger.y); |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
349 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
|
350 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
|
351 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
352 for(i = 0;i<MAXFINGERS;i++) |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
353 if(index2fingerid[i] == event.tfinger.fingerId) |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
354 break; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
355 if(i == MAXFINGERS) break; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
356 if(inTouch > 0) { |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
357 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
|
358 inTouch->xres; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
359 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
|
360 inTouch->yres; |
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 finger[i].pressure = |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
363 ((float)event.tfinger.pressure)/inTouch->pressureres; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
364 /* |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
365 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
|
366 event.tfinger.fingerId, |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
367 finger[i].pressure, |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
368 inTouch->pressureres); |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
369 */ |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
370 //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
|
371 // finger[event.tfinger.fingerId].pressure); |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
372 } |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
373 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
374 break; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
375 case SDL_FINGERDOWN: |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
376 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
|
377 event.tfinger.x,event.tfinger.y); |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
378 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
379 for(i = 0;i<MAXFINGERS;i++) |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
380 if(index2fingerid[i] == -1) { |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
381 index2fingerid[i] = event.tfinger.fingerId; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
382 break; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
383 } |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
384 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
|
385 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
|
386 break; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
387 case SDL_FINGERUP: |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
388 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
|
389 event.tfinger.x,event.tfinger.y); |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
390 for(i = 0;i<MAXFINGERS;i++) |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
391 if(index2fingerid[i] == event.tfinger.fingerId) { |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
392 index2fingerid[i] = -1; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
393 break; |
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 finger[i].p.x = -1; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
396 finger[i].p.y = -1; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
397 break; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
398 case SDL_MULTIGESTURE: |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
399 knob.p.x = event.mgesture.x; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
400 knob.p.y = event.mgesture.y; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
401 knob.ang += event.mgesture.dTheta; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
402 knob.r += event.mgesture.dDist; |
4659
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
403 break; |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
404 case SDL_DOLLARGESTURE: |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
405 printf("Gesture %lu performed, error: %f\n", |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
406 event.dgesture.gestureId, |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
407 event.dgesture.error); |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
408 break; |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
409 case SDL_DOLLARRECORD: |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
410 printf("Recorded gesture: %lu\n",event.dgesture.gestureId); |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
411 break; |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
412 } |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
413 } |
4659
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
414 DrawScreen(screen,h); |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
415 for(i = 0; i < 256; i++) |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
416 if(keystat[i]) |
063b9455bd1a
Added some files I had previosuly missed
Jim Grandpre <jim.tla@gmail.com>
parents:
4657
diff
changeset
|
417 printf("Key %i down\n",i); |
4657
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
418 } |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
419 SDL_Quit(); |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
420 |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
421 return 0; |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
422 } |
eed063a0bf5b
Moved Multi finger gesture recognition into the library.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff
changeset
|
423 |