-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdefault_hand_hold.pde
60 lines (45 loc) · 1.5 KB
/
default_hand_hold.pde
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
boolean flag_startHand = false;
boolean flag_moveHand = false;
float dist_Hand = 0.0;
long time_startHand = 0;
int duration_Hand = 0;
final float TimeTrigger_2 = 2000;
void default_hand_hold()
{
int hands = 0;
for (Hand handIn : leap.getHands ()) {
hand = handIn;
if(hand.getRawPosition().z>threshold_z_min&&hand.getRawPosition().z<threshold_z_max&&hand.getRawPosition().x>threshold_x_min&&hand.getRawPosition().x<threshold_x_max&&hand.getRawPosition().y>threshold_y_min&&hand.getRawPosition().y<threshold_y_max){
if(defaultFlag && defaultHand==false)
{
if(hand.isLeft())hands++;
}
else if(defaultFlag && defaultHand)
{
if(hand.isRight())hands++;
}
}
if ( hands > 0) {
PVector translation = hand.getPosition();
long time_currentFrame = millis();
if ( flag_startHand ) {
translation.sub( startHand.getPosition() );
dist_Hand = translation.mag();
}
else dist_Hand = 2 * dist_threshold;
if ( dist_Hand > dist_threshold || switch_triggered ) {
flag_startHand = true;
flag_moveHand = true;
startHand = hand;
time_startHand = millis();
duration_Hand = 0;
}
else duration_Hand = int(time_currentFrame - time_startHand);
if( duration_Hand > TimeTrigger_2) default_hand_hold = true;
else if( duration_Hand < TimeTrigger_2) default_hand_hold = false;
}
if( hands == 0 ){
flag_moveHand = false;
}
}
}