2020-10-09 15:18:04 +00:00
|
|
|
import de.voidplus.leapmotion.*;
|
|
|
|
|
|
|
|
// ======================================================
|
|
|
|
// Table of Contents:
|
|
|
|
// ├─ 1. Callbacks
|
|
|
|
// ├─ 2. Hand
|
|
|
|
// ├─ 3. Arms
|
|
|
|
// ├─ 4. Fingers
|
|
|
|
// ├─ 5. Bones
|
|
|
|
// ├─ 6. Tools
|
|
|
|
// └─ 7. Devices
|
|
|
|
// ======================================================
|
|
|
|
|
|
|
|
|
|
|
|
LeapMotion leap;
|
|
|
|
LaserOut laser_frame;
|
|
|
|
int hand_id;
|
|
|
|
Attractor[] attractors = new Attractor[10];
|
2020-10-09 17:00:10 +00:00
|
|
|
Particle[] particles;
|
2020-10-09 15:18:04 +00:00
|
|
|
|
|
|
|
PVector min_pos;
|
|
|
|
PVector max_pos;
|
|
|
|
|
|
|
|
boolean att_stdout;
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
size(800, 500);
|
|
|
|
background(0);
|
2020-10-09 17:00:10 +00:00
|
|
|
|
|
|
|
int particle_path_length = 20;
|
|
|
|
int nb_particle = 10;
|
|
|
|
boolean particle_stdout = true; // print particle on stdout
|
|
|
|
att_stdout = false; // print attroctor on stdout
|
2020-10-09 15:18:04 +00:00
|
|
|
// ...
|
|
|
|
|
|
|
|
leap = new LeapMotion(this);
|
2020-10-09 17:00:10 +00:00
|
|
|
particles = new Particle[nb_particle];
|
2020-10-09 15:18:04 +00:00
|
|
|
|
2020-10-09 17:00:10 +00:00
|
|
|
laser_frame = new LaserOut(particle_stdout);
|
2020-10-09 15:18:04 +00:00
|
|
|
|
|
|
|
// init_attractors
|
|
|
|
for (int i = 0; i < attractors.length; i++){
|
|
|
|
attractors[i] = new Attractor();
|
|
|
|
}
|
|
|
|
for (int i = 0; i < particles.length; i++){
|
2020-10-09 17:00:10 +00:00
|
|
|
if (particle_path_length > 0)
|
|
|
|
particles[i] = new Particle(particle_path_length); // number of previous position drawn
|
|
|
|
else
|
|
|
|
particles[i] = new Particle(); // no previous article
|
2020-10-09 15:18:04 +00:00
|
|
|
|
|
|
|
}
|
2020-10-09 17:00:10 +00:00
|
|
|
|
2020-10-09 15:18:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void draw() {
|
|
|
|
background(50);
|
|
|
|
// ...
|
|
|
|
|
|
|
|
int fps = leap.getFrameRate();
|
|
|
|
int i = 0;
|
|
|
|
int att_id;
|
|
|
|
|
|
|
|
for (Hand hand : leap.getHands ()) {
|
|
|
|
if (i >= 2)
|
|
|
|
{
|
|
|
|
println("\n\n\n\t\t !! MORE THAN 2 hands isn't implemented");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------
|
|
|
|
// Drawing
|
|
|
|
// hand.draw();
|
|
|
|
|
2020-10-09 17:00:10 +00:00
|
|
|
// // update attractors position and draw
|
|
|
|
// att_id = i * 5 + 0; // 5 => number of finger
|
|
|
|
// PVector pos = hand.getIndexFinger().getPositionOfJointDip();
|
|
|
|
// attractors[att_id].update_pos(pos);
|
|
|
|
|
|
|
|
int j = 0;
|
|
|
|
for (Finger finger : hand.getFingers()) {
|
|
|
|
|
|
|
|
att_id = i * 5 + j; // 5 => nunber of finger
|
|
|
|
PVector pos = finger.getPositionOfJointDip();
|
|
|
|
attractors[att_id].update_pos(pos);
|
|
|
|
j++;
|
|
|
|
}
|
2020-10-09 15:18:04 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
particles_update_position();
|
|
|
|
draw_attractors();
|
|
|
|
draw_particles();
|
|
|
|
laser_frame.print_frame(); // print frame on stdout
|
2020-10-09 17:00:10 +00:00
|
|
|
disable_attractors();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void disable_attractors(){
|
|
|
|
for (Attractor att : attractors){
|
|
|
|
att.is_active = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void draw_attractors(){
|
|
|
|
for (Attractor att : attractors){
|
|
|
|
if (att.is_active)
|
|
|
|
att.draw();
|
|
|
|
}
|
2020-10-09 15:18:04 +00:00
|
|
|
}
|
|
|
|
|
2020-10-09 17:00:10 +00:00
|
|
|
void draw_particles(){
|
|
|
|
for (Particle p : particles){
|
|
|
|
p.draw();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void particles_update_position(){
|
|
|
|
for (Particle p : particles){
|
|
|
|
p.update_position(attractors);
|
|
|
|
}
|
|
|
|
}
|
2020-10-09 15:18:04 +00:00
|
|
|
|
|
|
|
// println("finger_pos:", pos);
|
|
|
|
|
|
|
|
// // println("---");
|
|
|
|
// int j = 0;
|
|
|
|
// for (Finger finger : hand.getFingers()) {
|
|
|
|
//
|
|
|
|
// // update attractors position and draw
|
|
|
|
// att_id = i * 5 + j; // 5 => number of finger
|
|
|
|
// PVector pos = finger.getPosition();
|
|
|
|
// attractors[att_id].update_pos(pos);
|
|
|
|
// j++;
|
|
|
|
// }
|