-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgesturerecognizer.cpp
executable file
·74 lines (63 loc) · 1.4 KB
/
gesturerecognizer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "gesturerecognizer.h"
#include <iostream>
#include <cmath>
#include "gesturemoveleft.h"
#include "gesturemoveright.h"
#include "gesturemoveup.h"
#include "gesturemovedown.h"
int point_subtract(QPoint a, QPoint b)
{
int x = abs(a.x()-b.x());
int y = abs(a.y()-b.y());
return round(sqrt(x*x+y*y));
}
GestureRecognizer::GestureRecognizer()
{
gestures.clear();
points.clear();
addGesture(new GestureMoveLeft());
addGesture(new GestureMoveRight());
addGesture(new GestureMoveUp());
addGesture(new GestureMoveDown());
}
void GestureRecognizer::resetGesture()
{
points.clear();
}
void GestureRecognizer::addPoint(QPoint p)
{
cout << points.size() << endl;
points.push_back(p);
}
Gesture * GestureRecognizer::getGesture()
{
removeNoise();
for(vector<Gesture *>::iterator it = gestures.begin();it !=gestures.end();it++)
{
if((*it)->check(points)) return (*it);
}
return NULL;
}
void GestureRecognizer::removeNoise()
{
if(points.size()<3) return;
unsigned f = 1, a = 1;
while(f<points.size() && a<points.size())
{
if(point_subtract(points[f-1],points[a])<MAX_POINT_DISTANCE)
{
points[f] = points[a];
f++;
}
a++;
}
points.resize(f);
}
void GestureRecognizer::addGesture(Gesture * g)
{
gestures.push_back(g);
}
GestureRecognizer::~GestureRecognizer()
{
for(typeof(gestures.begin()) it = gestures.begin();it!=gestures.end();it++) delete (*it);
}