-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGUISketch.java
188 lines (157 loc) · 5.89 KB
/
GUISketch.java
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import processing.core.*;
import de.voidplus.leapmotion.*;
public class GUISketch extends PApplet {
LeapMotion leap;
LeapMotion factoryLeap;
PImage img24 = loadImage("24pattern.png");
PImage img34 = loadImage("good34.png");
PImage img44 = loadImage("44pattern.jpg");
PImage img = img24;
Boolean hasBaton;
Tool globalTool;
com.leapmotion.leap.Controller controller;
com.leapmotion.leap.Listener listener;
public GUISketch(Tool inputTool) {
this.globalTool = inputTool;
}
public void changeBackground(int input) {
if (input == 24) img = img24;
else if (input == 34) img = img34;
else img = img44;
}
@Override
public void setup() {
size(600, 550); // w, h
//background(255);
img.resize(600, 550);
background(img);
leap = new LeapMotion(this);
controller = new com.leapmotion.leap.Controller();
listener = new com.leapmotion.leap.Listener();
controller.addListener(listener);
}
@Override
public void draw() {
//background(255);
// img.resize(800, 550);
// background(img);
// int fps = leap.getFrameRate();
hasBaton = null;
if (img == null) {
background(255);
} else {
image(img,0,0, width, height);
}
com.leapmotion.leap.Frame frame = controller.frame();
// ========= HANDS =========
if (!frame.hands().isEmpty()) {
for(Hand hand : leap.getHands()) {
//hasBaton = hand.hasTools();
int hand_id = hand.getId();
PVector hand_position = hand.getPosition();
PVector hand_stabilized = hand.getStabilizedPosition();
PVector hand_direction = hand.getDirection();
PVector hand_dynamics = hand.getDynamics();
float hand_roll = hand.getRoll();
float hand_pitch = hand.getPitch();
float hand_yaw = hand.getYaw();
boolean hand_is_left = hand.isLeft();
boolean hand_is_right = hand.isRight();
float hand_grab = hand.getGrabStrength();
float hand_pinch = hand.getPinchStrength();
float hand_time = hand.getTimeVisible();
PVector sphere_position = hand.getSpherePosition();
float sphere_radius = hand.getSphereRadius();
hand.draw();
hand.drawSphere();
// ========= FINGERS =========
for(Finger finger : hand.getOutstrechtedFingers()){
// was hand.getFingers()
// ----- BASICS -----
int finger_id = finger.getId();
PVector finger_position = finger.getPosition();
PVector finger_stabilized = finger.getStabilizedPosition();
PVector finger_velocity = finger.getVelocity();
PVector finger_direction = finger.getDirection();
float finger_time = finger.getTimeVisible();
// ========= ARM =========
if(hand.hasArm()){
Arm arm = hand.getArm();
float arm_width = arm.getWidth();
PVector arm_wrist_pos = arm.getWristPosition();
PVector arm_elbow_pos = arm.getElbowPosition();
}
// ----- SPECIFIC FINGER -----
switch(finger.getType()){
case 0:
// System.out.println("thumb");
break;
case 1:
// System.out.println("index");
break;
case 2:
// System.out.println("middle");
break;
case 3:
// System.out.println("ring");
break;
case 4:
// System.out.println("pinky");
break;
}
// ----- SPECIFIC BONE -----
Bone bone_distal = finger.getDistalBone();
// or finger.get("distal");
// or finger.getBone(0);
Bone bone_intermediate = finger.getIntermediateBone();
// or finger.get("intermediate");
// or finger.getBone(1);
Bone bone_proximal = finger.getProximalBone();
// or finger.get("proximal");
// or finger.getBone(2);
Bone bone_metacarpal = finger.getMetacarpalBone();
// or finger.get("metacarpal");
// or finger.getBone(3);
// ----- DRAWING -----
finger.draw(20); // = drawLines()+drawJoints()
finger.drawLines();
finger.drawJoints();
}
// ========= TOOLS =========
if (this.globalTool != null) System.out.println("GREAT SUCCESS!!!");
//globalTool.draw();
for(Tool tool : hand.getTools()){
int tool_id = tool.getId();
PVector tool_position = tool.getPosition();
PVector tool_stabilized = tool.getStabilizedPosition();
PVector tool_velocity = tool.getVelocity();
PVector tool_direction = tool.getDirection();
float tool_time = tool.getTimeVisible();
// Tool tool = null;
// if (hand.countTools() > 0) {
// tool = hand.getTools().get(0);
// hasBaton = true;
// }
// tool.draw();
}
}
} // if frame has no hands
else {
//com.leapmotion.leap.Frame frame = controller.frame();
if (this.globalTool != null) {
System.out.println("GREAT SUCCESS!!!");
globalTool.draw();
}
if (frame.tools().count() > 0) {
hasBaton = true;
}
else {
hasBaton = false;
//System.out.print(hasBaton);
}
}
}
public void onFrame() {
hasBaton = true;
}
}