annotate touchTest/gestureTest.c @ 4655:4c94f2023d62

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