We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi,
I'm having trouble integrating P5 in my leap motion sketch. I created a GUI and everything but can't seem to have the GUI do anything when the options are changed via mouse. I'm using a leap motion to draw things and I'd like the GUI i have set up be able to change the size/color/etc of the spheres/boxes it's drawing. I'm not sure what I'm doing wrong. The sphere and box are initialized as line.
import de.voidplus.leapmotion.Bone;
import de.voidplus.leapmotion.Arm;
import de.voidplus.leapmotion.*;
import controlP5.*;
ControlP5 controlP5;
LeapMotion leap;
int GUI_WIDTH = 400;
float lineWeight = 50;
float lineHue = 128;
float lineSaturation = 128;
float lineBrightness = 128;
float lineAlpha = 128;
void setup() {
size(1000, 1000, P3D);
background(255, 0, 0);
ellipseMode(CENTER);
rectMode(CENTER);
// ...
setupGUI();
//Declaring Leap Call
leap = new LeapMotion(this);
}
void draw() {
//Define depth lighting//Closer lighting is stronger//further back its not.
lights();
//GUI settings
if(mousePressed)
drawGUIBackground();
drawLinePreview();
drawCursor();
// ...
int fps = leap.getFrameRate();
// ========= HANDS =========
for (Hand hand : leap.getHands ()) {
// ----- BASICS -----
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 = radians(hand.getRoll());
float hand_pitch = radians(hand.getPitch());
float hand_yaw = degrees(hand.getYaw());//spins on X
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();
// ----- SPECIFIC FINGER -----
Finger finger_thumb =hand.getFinger("thumb");
Finger finger_index = hand.getFinger("index");
Finger finger_middle = hand.getFinger("middle");
Finger finger_ring = hand.getFinger("ring");
Finger finger_pink = hand.getFinger("pinky");
// ----- DRAWING -----
// hand.draw();
pushMatrix();
translate(hand_stabilized.x, hand_stabilized.y, hand_stabilized.z);
rotateX(QUARTER_PI);
rotateY(hand_pitch);
rotateZ(-hand_yaw);
fill(random(255),50,77);
noStroke();
// stroke(255,77);
sphere(25);
box(85, 25, 1);
popMatrix();
// hand.drawSphere();
// ========= 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();
}
// ========= FINGERS =========
for (Finger finger : 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();
// ----- 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();
Bone bone_intermediate = finger.getIntermediateBone();
Bone bone_proximal = finger.getProximalBone();
Bone bone_metacarpal = finger.getMetacarpalBone();
// ----- DRAWING -----
// finger.draw(); // = drawLines()+drawJoints()
// finger.drawLines();
// ----- TOUCH EMULATION -----
int touch_zone = finger.getTouchZone();
float touch_distance = finger.getTouchDistance();
switch(touch_zone) {
case -1: // None
break;
case 0: // Hovering
// println("Hovering (#"+finger_id+"): "+touch_distance);
break;
case 1: // Touching
// println("Touching (#"+finger_id+")");
break;
}
}
// ========= TOOLS =========
for (Tool tool : hand.getTools ()) {
// ----- BASICS -----
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();
// ----- DRAWING -----
tool.draw();
// ----- TOUCH EMULATION -----
int touch_zone = tool.getTouchZone();
float touch_distance = tool.getTouchDistance();
switch(touch_zone) {
case -1: // None
break;
case 0: // Hovering
// println("Hovering (#"+tool_id+"): "+touch_distance);
break;
case 1: // Touching
// println("Touching (#"+tool_id+")");
break;
}
}
}
// ========= DEVICES =========
for (Device device : leap.getDevices ()) {
float device_horizontal_view_angle = device.getHorizontalViewAngle();
float device_verical_view_angle = device.getVerticalViewAngle();
float device_range = device.getRange();
}
}
This is the GUI class underneath.
void setupGUI() {
controlP5 = new ControlP5(this);
PFont GUIfont = createFont("zapphino", 12);
controlP5.setControlFont(GUIfont);
controlP5.addSlider("lineWeight", 1.0, 255.0, 20, 120, 250, 15).setLabel("weight");
controlP5.addSlider("lineHue", 1.0, 255.0, 20, 140, 250, 15).setLabel("hue");
controlP5.addSlider("lineBrightness", 1.0, 255.0, 20, 160, 250, 15).setLabel("brightness");
controlP5.addSlider("lineAlpha", 1.0, 225.0, 20, 180, 250, 15).setLabel("alpha");
controlP5.addButton("saveImage", 0,20,340,80,21).setLabel("save");
controlP5.addButton("clearImage", 0,103,340,90,21).setLabel("clear");
}
void drawCursor() {
if(mouseX>GUI_WIDTH) cursor(CROSS);
if(mouseX<=GUI_WIDTH) cursor(HAND);
}
void drawGUIBackground() {
noStroke();
fill(0);
rect(0,0, GUI_WIDTH, height);
}
void drawLinePreview() {
// draw white box
noStroke();
fill(255);
rect(20,60,GUI_WIDTH-40,50);
//draw outline
stroke(140);
strokeWeight(1);
fill(0,0);
rect(20, 10, GUI_WIDTH-40, 100);
// draw preview line
strokeWeight(lineWeight);
stroke(lineHue, lineSaturation, lineBrightness, lineAlpha);
line(70, 60, GUI_WIDTH-70, 60);
}