-
Notifications
You must be signed in to change notification settings - Fork 2
/
locationawarewidget.cpp
116 lines (89 loc) · 2.8 KB
/
locationawarewidget.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "locationawarewidget.h"
#include <QDebug>
#include "settings.h"
LocationAwareWidget::LocationAwareWidget()
: maxFinger(0)
{
this->targetReached = false;
this->defColor.x = 1.0;
this->defColor.y = 0.0;
this->defColor.z = 0.0;
}
void LocationAwareWidget::interactionEnd(MultiWidgets::GrabManager &input)
{
MultiWidgets::Widget::interactionEnd(input);
this->setRotation(0);
this->setVelocity(0,0);
}
void LocationAwareWidget::grabFinger(long fingerId, MultiWidgets::GrabManager &gm)
{
MultiWidgets::Widget::grabFinger(fingerId, gm);
}
void LocationAwareWidget::grabHand(long handId, MultiWidgets::GrabManager &gm)
{
// DO NOT GRAP HAND
}
void LocationAwareWidget::input(MultiWidgets::GrabManager &gm, float dt)
{
MultiWidgets::Widget::input(gm, dt);
int fingers = this->grabFingerCount();
if( DEBUG ) {
// set color based on number of fingers
if( fingers == 0 ) {
this->setColor( this->defColor.x, this->defColor.y, this->defColor.z , 0.95);
}
if( fingers == 1 ) {
this->setColor(0,1,0,0.95);
}
if( fingers == 2 ) {
this->setColor(0,0,1,0.95);
}
}
int middleX = initialX + ( targetX - initialX ) / 2;
int middleY = initialY + ( targetY - initialY ) / 2;
Nimble::Vector2 v1( initialX - middleX, initialY - middleY );
Nimble::Vector2 v2( (this->location().x + this->width() / 2) - middleX, ( this->location().x + this->width() / 2) - middleY );
// qDebug() << v1.x << " " << v1.y;
// qDebug() << v2.x << " " << v2.y;
float angle = acos( (v1.x * v2.x + v1.y * v2.y ) / ( v1.length() * v2.length() ) );
// qDebug() << angle;
if( fingers > this->maxFinger ) {
this->maxFinger = fingers;
}
int ERROR_MARGIN = 20;
if( qAbs( ( this->location().y + this->width() / 2) - this->targetY ) <= ERROR_MARGIN && qAbs( ( this->location().x + this->width() / 2) - this->targetX ) <= ERROR_MARGIN ) {
if( DEBUG ) {
this->setColor(0.5, 0.3, 0.5, 1);
}
// purukumia! ## todo fix
if( !this->targetReached ) {
this->targetReached = true;
eventSend("target_reached");
}
} else {
this->targetReached = false;
}
}
bool LocationAwareWidget::isContactLost()
{
if( this->grabFingerCount() < this->maxFinger ) {
this->maxFinger = this->grabFingerCount();
return true;
}
return false;
}
void LocationAwareWidget::setTarget(Nimble::Vector2 target)
{
this->targetX = target.x;
this->targetY = target.y;
}
bool LocationAwareWidget::isTargetReached()
{
return this->targetReached;
}
void LocationAwareWidget::setDefaultColor(float r, float g, float b)
{
this->defColor.x = r;
this->defColor.y = g;
this->defColor.z = b;
}