annotate touchTest/gestureTest.c @ 4654:7dbcd71216df

Added $1 gesture recognition. Functional.
author Jim Grandpre <jim.tla@gmail.com>
date Thu, 17 Jun 2010 03:41:27 -0400
parents 744b75ad18b8
children 4c94f2023d62
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;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
217 for(k = 0;k<DOLLARNPOINTS;k++) {
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
218 printf("(%f,%f)\n",points[k].x,
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
219 points[k].y);
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
220 }
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
221
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
222 drawDollarPath(screen,points,numPoints,-15,0xFF6600);
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
223
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
224 int bestDiff = 10000;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
225 *bestTempl = -1;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
226 for(i = 0;i < numDollarTemplates;i++) {
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
227 int diff = bestDollarDifference(points,dollarTemplate[i]);
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
228 if(diff < bestDiff) {bestDiff = diff; *bestTempl = i;}
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
229 }
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
230 return bestDiff;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
231 }
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 //DollarPath contains raw points, plus (possibly) the calculated length
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
234 int dollarNormalize(DollarPath path,Point *points) {
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
235 int i;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
236 //Calculate length if it hasn't already been done
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
237 if(path.length <= 0) {
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
238 for(i=1;i<path.numPoints;i++) {
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
239 float dx = path.p[i ].x -
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
240 path.p[i-1].x;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
241 float dy = path.p[i ].y -
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
242 path.p[i-1].y;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
243 path.length += sqrt(dx*dx+dy*dy);
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
244 }
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
245 }
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
246
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 //Resample
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
249 float interval = path.length/(DOLLARNPOINTS - 1);
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
250 float dist = 0;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
251
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
252 int numPoints = 0;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
253 Point centroid; centroid.x = 0;centroid.y = 0;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
254 //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
255 for(i = 1;i < path.numPoints;i++) {
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
256 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
257 (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
258 //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
259 while(dist + d > interval) {
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
260 points[numPoints].x = path.p[i-1].x +
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
261 ((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
262 points[numPoints].y = path.p[i-1].y +
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
263 ((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
264 centroid.x += points[numPoints].x;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
265 centroid.y += points[numPoints].y;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
266 numPoints++;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
267
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
268 dist -= interval;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
269 }
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
270 dist += d;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
271 }
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
272 if(numPoints < 1) return 0;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
273 centroid.x /= numPoints;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
274 centroid.y /= numPoints;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
275
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
276 //printf("Centroid (%f,%f)",centroid.x,centroid.y);
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
277 //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
278 float xmin,xmax,ymin,ymax;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
279 xmin = centroid.x;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
280 xmax = centroid.x;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
281 ymin = centroid.y;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
282 ymax = centroid.y;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
283
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
284 float ang = atan2(centroid.y - points[0].y,
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
285 centroid.x - points[0].x);
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
286
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
287 for(i = 0;i<numPoints;i++) {
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
288 float px = points[i].x;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
289 float py = points[i].y;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
290 points[i].x = (px - centroid.x)*cos(ang) -
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
291 (py - centroid.y)*sin(ang) + centroid.x;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
292 points[i].y = (px - centroid.x)*sin(ang) +
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
293 (py - centroid.y)*cos(ang) + centroid.y;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
294
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 if(points[i].x < xmin) xmin = points[i].x;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
297 if(points[i].x > xmax) xmax = points[i].x;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
298 if(points[i].y < ymin) ymin = points[i].y;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
299 if(points[i].y > ymax) ymax = points[i].y;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
300 }
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 //Scale points to DOLLARSIZE, and translate to the origin
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
303 float w = xmax-xmin;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
304 float h = ymax-ymin;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
305
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
306 for(i=0;i<numPoints;i++) {
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
307 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
308 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
309 }
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
310 return numPoints;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
311 }
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
312
4651
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
313 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
314 {
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
315 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
316 if(SDL_MUSTLOCK(screen))
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
317 {
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
318 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
319 }
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
320 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
321 {
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
322 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
323 {
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
324 //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
325 //xm = (x+h)%screen->w;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
326 //ym = (y+h)%screen->w;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
327 //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
328 //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
329 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
330 //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
331 }
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 drawCircle(screen,mousx,mousy,-30,0xFFFFFF);
4653
744b75ad18b8 Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents: 4651
diff changeset
334 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
335 int i;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
336 //draw Touch History
4653
744b75ad18b8 Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents: 4651
diff changeset
337 for(i = 0;i < MAXFINGERS;i++) {
744b75ad18b8 Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents: 4651
diff changeset
338 gestureLast[i].id = -1;
4654
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
339 #ifdef DRAW_VECTOR_EST
4653
744b75ad18b8 Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents: 4651
diff changeset
340 gestureLine[i].points = 0;
4654
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
341 #endif
4653
744b75ad18b8 Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents: 4651
diff changeset
342 }
4651
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
343 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
344 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
345 int age = eventWrite - i - 1;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
346 if(event.type == SDL_FINGERMOTION ||
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
347 event.type == SDL_FINGERDOWN ||
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
348 event.type == SDL_FINGERUP) {
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
349 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
350 //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
351
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
352 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
353 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
354 int j,empty = -1;
4654
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
355
4651
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
356 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
357 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
358 if(event.type == SDL_FINGERUP) {
4654
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
359 #ifdef DRAW_VECTOR_EST
4653
744b75ad18b8 Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents: 4651
diff changeset
360 if(gestureLine[j].points > 0)
4654
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
361 drawLine(screen,
4653
744b75ad18b8 Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents: 4651
diff changeset
362 gestureLine[j].s.x*screen->w,
744b75ad18b8 Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents: 4651
diff changeset
363 gestureLine[j].s.y*screen->h,
744b75ad18b8 Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents: 4651
diff changeset
364 (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
365 (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
366 0xFF00);
744b75ad18b8 Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents: 4651
diff changeset
367
744b75ad18b8 Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents: 4651
diff changeset
368 gestureLine[j].points = 0;
4654
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
369 #endif
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
370 //ignore last point - probably invalid
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
371 dollarPath[j].numPoints--;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
372
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
373
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
374 float dx = dollarPath[j].p[dollarPath[j].numPoints].x -
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
375 dollarPath[j].p[dollarPath[j].numPoints - 1].x;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
376 float dy = dollarPath[j].p[dollarPath[j].numPoints].y -
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
377 dollarPath[j].p[dollarPath[j].numPoints - 1].y;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
378 dollarPath[j].length -= sqrt(dx*dx+dy*dy);
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
379
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
380 if(!keystat[32]){ //spacebar
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
381 int bestTempl;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
382 float error = dollarRecognize(screen,dollarPath[j],&bestTempl);
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
383 printf("%i\n",bestTempl);
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
384 if(bestTempl >= 0){
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
385 drawDollarPath(screen,dollarTemplate[bestTempl]
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
386 ,DOLLARNPOINTS,-15,0x0066FF);\
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
387
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
388 printf("ERROR: %f\n",error);
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
389 }
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
390
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
391 }
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
392 else if(numDollarTemplates < MAXTEMPLATES) {
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
393
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
394 dollarNormalize(dollarPath[j],
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
395 dollarTemplate[numDollarTemplates]);
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
396 int k;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
397 /*
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
398 for(k = 0;k<DOLLARNPOINTS;k++) {
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
399 printf("(%f,%f)\n",dollarTemplate[numDollarTemplates][i].x,
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
400 dollarTemplate[numDollarTemplates][i].y);
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
401 }*/
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
402 numDollarTemplates++;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
403 }
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
404
4651
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
405 gestureLast[j].id = -1;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
406 break;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
407 }
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
408 else {
4654
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
409 #ifdef DRAW_VECTOR_EST
4653
744b75ad18b8 Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents: 4651
diff changeset
410 if(gestureLine[j].points == 1) {
744b75ad18b8 Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents: 4651
diff changeset
411 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
412 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
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].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
416 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
417
744b75ad18b8 Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents: 4651
diff changeset
418 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
419 x - gestureLast[j].p.x;
744b75ad18b8 Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents: 4651
diff changeset
420 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
421 y - gestureLast[j].p.y;;
744b75ad18b8 Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents: 4651
diff changeset
422
744b75ad18b8 Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents: 4651
diff changeset
423
744b75ad18b8 Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents: 4651
diff changeset
424 gestureLine[j].points++;
744b75ad18b8 Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents: 4651
diff changeset
425
744b75ad18b8 Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents: 4651
diff changeset
426 gestureLine[j].s.x /= gestureLine[j].points;
744b75ad18b8 Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents: 4651
diff changeset
427 gestureLine[j].s.y /= gestureLine[j].points;
744b75ad18b8 Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents: 4651
diff changeset
428
744b75ad18b8 Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents: 4651
diff changeset
429 gestureLine[j].d.x /= gestureLine[j].points;
4654
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
430 gestureLine[j].d.y /= gestureLine[j].points;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
431 #endif
4653
744b75ad18b8 Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents: 4651
diff changeset
432
4654
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
433 dollarPath[j].p[dollarPath[j].numPoints].x = x;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
434 dollarPath[j].p[dollarPath[j].numPoints].y = y;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
435 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
436 dollarPath[j].p[dollarPath[j].numPoints ].x);
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
437 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
438 dollarPath[j].p[dollarPath[j].numPoints ].y);
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
439 dollarPath[j].length += sqrt(dx*dx + dy*dy);
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
440
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
441 dollarPath[j].numPoints++;
4653
744b75ad18b8 Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents: 4651
diff changeset
442
744b75ad18b8 Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents: 4651
diff changeset
443
4651
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
444 gestureLast[j].p.x = x;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
445 gestureLast[j].p.y = y;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
446 break;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
447 //pressure?
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
448 }
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
449 }
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
450 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
451 empty = j;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
452 }
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
453 }
4654
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
454
4651
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
455 if(j >= MAXFINGERS && empty >= 0) {
4654
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
456 // printf("Finger Down!!!\n");
4651
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
457 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
458 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
459 gestureLast[j].p.x = x;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
460 gestureLast[j].p.y = y;
4654
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
461 #ifdef DRAW_VECTOR_EST
4653
744b75ad18b8 Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents: 4651
diff changeset
462 gestureLine[j].s.x = x;
744b75ad18b8 Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents: 4651
diff changeset
463 gestureLine[j].s.y = y;
744b75ad18b8 Started adding vectorization of touch data.
Jim Grandpre <jim.tla@gmail.com>
parents: 4651
diff changeset
464 gestureLine[j].points = 1;
4654
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
465 #endif
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
466
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
467 dollarPath[j].length = 0;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
468 dollarPath[j].p[0].x = x;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
469 dollarPath[j].p[0].y = y;
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
470 dollarPath[j].numPoints = 1;
4651
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
471 }
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
472
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
473 //draw the touch && each centroid:
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
474
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
475 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
476 int k;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
477 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
478
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
479 if(gestureLast[k].id < 0) continue;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
480 //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
481 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
482 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
483 unsigned int col =
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
484 ((unsigned int)(c*(.1+.85))) |
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
485 ((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
486 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
487 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
488 if(event.type == SDL_FINGERMOTION)
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
489 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
490 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
491 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
492 }
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
493 }
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
494 }
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
495
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 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
498 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
499 if(finger[i].pressure > 0)
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
500 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
501 ,20,0xFF*finger[i].pressure);
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
502 else
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
503 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
504 ,20,0xFF);
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
505
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
506
4654
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
507 keystat[32] = 0;
4651
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
508
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
509 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
510
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
511 SDL_Flip(screen);
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
512 }
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
513
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
514 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
515 {
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
516 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
517 SDL_HWSURFACE | SDL_RESIZABLE);
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
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
520 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
521 {
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
522 SDL_Surface *screen;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
523 SDL_Event event;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
524
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
525 int keypress = 0;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
526 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
527
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
528 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
529 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
530
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
531 if (!(screen = initScreen(WIDTH,HEIGHT)))
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
532 {
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
533 SDL_Quit();
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
534 return 1;
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
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
537 while(!keystat[27]) {
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
538 //Poll SDL
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
539 while(SDL_PollEvent(&event))
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
540 {
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
541 //Record _all_ events
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
542 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
543 eventWrite++;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
544
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
545 switch (event.type)
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
546 {
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
547 case SDL_QUIT:
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
548 keystat[27] = 1;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
549 break;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
550 case SDL_KEYDOWN:
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
551 //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
552 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
553 //keypress = 1;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
554 break;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
555 case SDL_KEYUP:
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
556 //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
557 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
558 //keypress = 1;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
559 break;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
560 case SDL_VIDEORESIZE:
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
561 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
562 event.resize.h)))
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
563 {
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
564 SDL_Quit();
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
565 return 1;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
566 }
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
567 break;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
568 case SDL_MOUSEMOTION:
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
569 mousx = event.motion.x;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
570 mousy = event.motion.y;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
571 break;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
572 case SDL_MOUSEBUTTONDOWN:
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
573 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
574 break;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
575 case SDL_MOUSEBUTTONUP:
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
576 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
577 break;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
578 case SDL_FINGERMOTION:
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
579 ;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
580 //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
581 // 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
582 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
583 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
584
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
585 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
586 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
587 break;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
588 if(i == MAXFINGERS) break;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
589 if(inTouch > 0) {
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
590 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
591 inTouch->xres;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
592 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
593 inTouch->yres;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
594
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
595 finger[i].pressure =
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
596 ((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
597
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
598 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
599 event.tfinger.fingerId,
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
600 finger[i].pressure,
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
601 inTouch->pressureres);
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
602 //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
603 // finger[event.tfinger.fingerId].pressure);
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
604 }
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
605
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
606 break;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
607 case SDL_FINGERDOWN:
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
608 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
609 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
610
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
611 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
612 if(index2fingerid[i] == -1) {
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
613 index2fingerid[i] = event.tfinger.fingerId;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
614 break;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
615 }
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
616 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
617 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
618 break;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
619 case SDL_FINGERUP:
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
620 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
621 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
622 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
623 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
624 index2fingerid[i] = -1;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
625 break;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
626 }
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
627 finger[i].p.x = -1;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
628 finger[i].p.y = -1;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
629 break;
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 }
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
632 //And draw
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
633 DrawScreen(screen,h);
4654
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
634
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
635 //for(i=0;i<512;i++)
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
636 // if(keystat[i]) printf("%i\n",i);
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
637
7dbcd71216df Added $1 gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents: 4653
diff changeset
638
4651
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
639 }
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
640 SDL_Quit();
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
641
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
642 return 0;
86c171888eee Added gesture test c file. Beginning of gesture recognition.
Jim Grandpre <jim.tla@gmail.com>
parents:
diff changeset
643 }