one particle with prevous path but bugged
This commit is contained in:
commit
a747c84af8
11
.gitignore
vendored
Normal file
11
.gitignore
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
# java binary
|
||||
application.linux-arm64/
|
||||
application.linux-armv6hf/
|
||||
application.linux32/
|
||||
application.linux64/
|
||||
|
||||
#vim temporaty file
|
||||
.*.sw*
|
||||
|
||||
#procesing autosave
|
||||
*.autosave
|
74
LaserOut.pde
Normal file
74
LaserOut.pde
Normal file
@ -0,0 +1,74 @@
|
||||
|
||||
public void processing_draw_line(Point[] line)
|
||||
{
|
||||
int i;
|
||||
Point p1, p2;
|
||||
|
||||
for (i = 0; i < line.length - 1; i++)
|
||||
{
|
||||
p1 = line[i];
|
||||
p2 = line[i + 1];
|
||||
|
||||
// println(" print seg:", p1.x, p1.y, p2.x, p2.y);
|
||||
stroke(p1.r, p1.g, p1.b);
|
||||
line(p1.x, p1.y, p2.x, p2.y);
|
||||
}
|
||||
}
|
||||
|
||||
public class LaserOut
|
||||
{
|
||||
String laser_out;
|
||||
boolean is_empty;
|
||||
boolean is_printing;
|
||||
|
||||
LaserOut(boolean printing)
|
||||
{
|
||||
laser_out = new String();
|
||||
laser_out += "[";
|
||||
is_empty = true;
|
||||
is_printing = printing;
|
||||
}
|
||||
|
||||
LaserOut()
|
||||
{
|
||||
laser_out = new String();
|
||||
laser_out += "[";
|
||||
is_empty = true;
|
||||
is_printing = true;
|
||||
}
|
||||
|
||||
void print_frame()
|
||||
{
|
||||
// to terminate json array
|
||||
laser_out += "]";
|
||||
if (is_printing)
|
||||
println(laser_out);
|
||||
|
||||
// flush the string, prepar for next frame
|
||||
laser_out = "";
|
||||
laser_out += "[";
|
||||
is_empty = true;
|
||||
}
|
||||
|
||||
void add_line(Point[] line)
|
||||
{
|
||||
if (is_empty)
|
||||
is_empty = false;
|
||||
else
|
||||
{
|
||||
laser_out += ", ";
|
||||
}
|
||||
|
||||
// on met un point noir quoi qu'il arrive
|
||||
laser_out += "[" + str(line[0].x) + ", " + str(line[0].y) + ", 0]";
|
||||
for (int i = 0; i < line.length; i++)
|
||||
{
|
||||
laser_out += ", [" + str(line[i].x) + ", " + str(line[i].y) + ", " + str(line[i].col) + "]";
|
||||
}
|
||||
laser_out += ", [" + str(line[line.length - 1].x) + ", " + str(line[line.length - 1].y) + ", 0]";
|
||||
|
||||
processing_draw_line(line); // On pourait rajouter une condition si un paraetre est activer
|
||||
}
|
||||
}
|
||||
|
||||
|
32
Point.pde
Normal file
32
Point.pde
Normal file
@ -0,0 +1,32 @@
|
||||
public class Point
|
||||
{
|
||||
public int x;
|
||||
public int y;
|
||||
|
||||
public int r;
|
||||
public int g;
|
||||
public int b;
|
||||
|
||||
public int col;
|
||||
|
||||
|
||||
Point(int in_x, int in_y, int c)
|
||||
{
|
||||
x = in_x;
|
||||
y = in_y;
|
||||
r = (c >> 16) & 0xFF;
|
||||
g = (c >> 8) & 0xFF;
|
||||
b = (c >> 0) & 0xFF;
|
||||
col = c;
|
||||
}
|
||||
|
||||
Point(int in_x, int in_y, int col_r, int col_g, int col_b)
|
||||
{
|
||||
x = in_x;
|
||||
y = in_y;
|
||||
r = col_r & 0xFF;
|
||||
g = col_g & 0xFF;
|
||||
b = col_b & 0xFF;
|
||||
col = (r & 0xFF) << 16| ((g & 0xFF) << 8) | ((b & 0xFF));
|
||||
}
|
||||
}
|
45
atractor.pde
Normal file
45
atractor.pde
Normal file
@ -0,0 +1,45 @@
|
||||
// il y aura 10 attractor, plus on ne fera pas
|
||||
|
||||
public class Attractor
|
||||
{
|
||||
PVector pos;
|
||||
float weight;
|
||||
boolean is_active;
|
||||
|
||||
float circle_radius;
|
||||
int col;
|
||||
int circle_pt;
|
||||
|
||||
Attractor(){
|
||||
pos = new PVector(0, 0, 0);
|
||||
is_active = false;
|
||||
weight = 30;
|
||||
|
||||
circle_radius = 20;
|
||||
col = getColInt(0, 0, 50);
|
||||
circle_pt = 10;
|
||||
}
|
||||
|
||||
void draw(){
|
||||
if (is_active){
|
||||
if (att_stdout)
|
||||
laser_frame.add_line(create_circle(pos.x, pos.y, circle_radius, circle_pt, col));
|
||||
else
|
||||
processing_draw_line(create_circle(pos.x, pos.y, circle_radius, circle_pt, col));
|
||||
}
|
||||
}
|
||||
|
||||
// we need to remap position from the leap motion
|
||||
void update_pos(PVector p){
|
||||
pos.x = ( p.x - 0) * 1;
|
||||
pos.y = (70. - p.z) * (800.0 / 70.0);
|
||||
is_active = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// void update_position(float px, float py){
|
||||
// pos.x = px;
|
||||
// pos.y = py;
|
||||
// }
|
||||
}
|
117
mini_leap.pde
Normal file
117
mini_leap.pde
Normal file
@ -0,0 +1,117 @@
|
||||
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];
|
||||
Particle[] particles = new Particle[1];
|
||||
|
||||
PVector min_pos;
|
||||
PVector max_pos;
|
||||
|
||||
boolean att_stdout;
|
||||
|
||||
void setup() {
|
||||
size(800, 500);
|
||||
background(0);
|
||||
// ...
|
||||
|
||||
leap = new LeapMotion(this);
|
||||
|
||||
att_stdout = false;
|
||||
boolean print_stdout = false;
|
||||
laser_frame = new LaserOut(print_stdout);
|
||||
|
||||
// init_attractors
|
||||
for (int i = 0; i < attractors.length; i++){
|
||||
attractors[i] = new Attractor();
|
||||
}
|
||||
for (int i = 0; i < particles.length; i++){
|
||||
particles[i] = new Particle(200); // number of previous position drawn
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void disable_attractors(){
|
||||
for (Attractor att : attractors){
|
||||
att.is_active = false;
|
||||
}
|
||||
}
|
||||
|
||||
void draw_attractors(){
|
||||
for (Attractor att : attractors){
|
||||
if (att.is_active)
|
||||
att.draw();
|
||||
}
|
||||
}
|
||||
|
||||
void draw_particles(){
|
||||
for (Particle p : particles){
|
||||
p.draw();
|
||||
}
|
||||
}
|
||||
|
||||
void particles_update_position(){
|
||||
for (Particle p : particles){
|
||||
p.update_position(attractors);
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
// 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);
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
particles_update_position();
|
||||
draw_attractors();
|
||||
draw_particles();
|
||||
laser_frame.print_frame(); // print frame on stdout
|
||||
}
|
||||
|
||||
|
||||
// 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++;
|
||||
// }
|
97
particle.pde
Normal file
97
particle.pde
Normal file
@ -0,0 +1,97 @@
|
||||
class Particle{
|
||||
PVector pos;
|
||||
PVector speed;
|
||||
int col;
|
||||
|
||||
int circular_nb;
|
||||
int circular_id; // the id in the circular buffer
|
||||
PVector[] circular_pos;
|
||||
boolean draw_previous;
|
||||
|
||||
|
||||
// pour pouvoir faire les trainer il faudrait retenir les position precedente
|
||||
// avoir un beffer tournant
|
||||
// retenir l'index actuel
|
||||
|
||||
|
||||
void init_circular(int nb_previous, boolean previous_drawing){
|
||||
draw_previous = previous_drawing;
|
||||
circular_nb = nb_previous;
|
||||
circular_id = 0;
|
||||
circular_pos = new PVector[circular_nb];
|
||||
for (int i = 0; i < circular_pos.length; i++){
|
||||
circular_pos[i] = new PVector(pos.x, pos.y, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void init_particle(){
|
||||
pos = new PVector(random(50, 750), random(50, 70));
|
||||
speed = new PVector(0, 0, 0);
|
||||
col = getColInt(255, 255, 255);
|
||||
|
||||
}
|
||||
|
||||
Particle(){
|
||||
init_particle();
|
||||
init_circular(1, false);
|
||||
}
|
||||
|
||||
Particle(int nb_previous){
|
||||
init_particle();
|
||||
init_circular(nb_previous, true);
|
||||
}
|
||||
|
||||
void update_position(Attractor[] attractors){
|
||||
for (Attractor att : attractors){
|
||||
if (!att.is_active)
|
||||
continue;
|
||||
PVector d = vecSub(att.pos, pos);
|
||||
float dist = sqrt(d.x * d.x + d.y * d.y);
|
||||
float factor = att.weight * 1.0 / (dist + 10);
|
||||
|
||||
normalize(d);
|
||||
|
||||
speed.x += d.x * factor;
|
||||
speed.y += d.y * factor;
|
||||
|
||||
float cross = cross_product(getNormalized(speed), d);
|
||||
float slow_distance = 0.2;
|
||||
// limitation de l'eloignement
|
||||
if (cross < 0){
|
||||
speed.x *= 1.0 - (slow_distance * abs(cross));
|
||||
speed.y *= 1.0 - (slow_distance * abs(cross));
|
||||
}
|
||||
|
||||
pos.x += speed.x;
|
||||
pos.y += speed.y;
|
||||
|
||||
circular_id = (circular_id + 1) % circular_pos.length;
|
||||
circular_pos[circular_id].x = float(int(pos.x));
|
||||
circular_pos[circular_id].y = float(int(pos.y));
|
||||
}
|
||||
}
|
||||
|
||||
void draw(){
|
||||
//println("hello im drowing:", pos);
|
||||
if (draw_previous){
|
||||
int id;
|
||||
Point[] previous_pos = new Point[circular_pos.length];
|
||||
for (int i = 0; i < circular_pos.length; i++){
|
||||
id = (circular_id - i + circular_pos.length) % circular_pos.length;
|
||||
previous_pos[i] = new Point(int(circular_pos[i].x), int(circular_pos[id].y), getColInt(0, 255, 0));
|
||||
}
|
||||
//println("plop");
|
||||
laser_frame.add_line(previous_pos);
|
||||
}
|
||||
else
|
||||
laser_frame.add_line(create_point(pos, getColInt(0, 255, 0)));
|
||||
}
|
||||
}
|
||||
|
||||
Point[] create_point(PVector pos, int col){
|
||||
Point[] point = new Point[2];
|
||||
|
||||
point[0] = new Point(int(pos.x), int(pos.y), col);
|
||||
point[1] = new Point(int(pos.x+1), int(pos.y+1), col);
|
||||
return point;
|
||||
}
|
85
utils.pde
Normal file
85
utils.pde
Normal file
@ -0,0 +1,85 @@
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
Point[] create_circle(float center_x, float center_y, float radius, int nb_point, int col){
|
||||
Point[] line = new Point[nb_point + 1];
|
||||
float px, py, factor;
|
||||
|
||||
for (int i = 0; i < line.length; i++){
|
||||
factor = float(i) / float(line.length - 1);
|
||||
px = center_x + radius * cos(factor * TWO_PI);
|
||||
py = center_y + radius * sin(factor * TWO_PI);
|
||||
line[i] = new Point(int(px), int(py), col);
|
||||
}
|
||||
return (line);
|
||||
}
|
||||
|
||||
int getColInt(int r, int g, int b){
|
||||
int col;
|
||||
|
||||
col = ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | ((b & 0xFF));
|
||||
return (col);
|
||||
}
|
||||
|
||||
public void showFields(Object o) {
|
||||
Class<?> clazz = o.getClass();
|
||||
|
||||
println("private fileds");
|
||||
for(Field field : clazz.getDeclaredFields()) {
|
||||
//you can also use .toGenericString() instead of .getName(). This will
|
||||
//give you the type information as well.
|
||||
|
||||
println("\t", field.getName());
|
||||
}
|
||||
|
||||
System.out.println("inherited fileds");
|
||||
for(Field field : clazz.getFields()) {
|
||||
//you can also use .toGenericString() instead of .getName(). This will
|
||||
//give you the type information as well.
|
||||
println("\t", field.getName());
|
||||
}
|
||||
}
|
||||
|
||||
public void showMethodes(Object o) {
|
||||
Class<?> clazz = o.getClass();
|
||||
|
||||
System.out.println("private methode");
|
||||
for(Method method : clazz.getDeclaredMethods()) {
|
||||
println("\t", method.getName());
|
||||
}
|
||||
|
||||
System.out.println("private methode");
|
||||
for(Method method : clazz.getMethods()) {
|
||||
println("\t", method.getName());
|
||||
}
|
||||
}
|
||||
|
||||
PVector vecSub(PVector a, PVector b){
|
||||
PVector diff = new PVector();
|
||||
|
||||
diff.x = a.x - b.x;
|
||||
diff.y = a.y - b.y;
|
||||
diff.z = a.z - b.z;
|
||||
return diff;
|
||||
}
|
||||
|
||||
void normalize(PVector p){
|
||||
float norme;
|
||||
|
||||
norme = sqrt(p.x * p.x + p.y * p.y + p.z * p.z);
|
||||
p.x /= norme;
|
||||
p.y /= norme;
|
||||
p.z /= norme;
|
||||
}
|
||||
|
||||
PVector getNormalized(PVector v){
|
||||
PVector res = new PVector(v.x, v.y, v.z);
|
||||
|
||||
normalize(res);
|
||||
return (res);
|
||||
}
|
||||
|
||||
|
||||
float cross_product(PVector a, PVector b){
|
||||
return (a.x*b.x + a.y*b.y + a.z*b.z);
|
||||
}
|
Loading…
Reference in New Issue
Block a user