第三週上課內容
第一節
1.介紹Leap
2.安裝Leap Driver+SDK
3.執行example
第二節
size(800,800);PImage img0 = loadImage("00.png");
PImage img2 = loadImage("02.png");
PImage img5 = loadImage("05.png");
int n=5;
if(n==0) image(img0,0,0);
if(n==2) image(img2,0,0);
if(n==5) image(img5,0,0);
import de.voidplus.leapmotion.*;
LeapMotion leap;
PImage img0, img2, img5;
void setup() {
size(800, 500, P3D);
background(255);
noStroke();
fill(50);
img0 = loadImage("00.png");
img2 = loadImage("02.png");
img5 = loadImage("05.png");
imageMode(CENTER);
leap = new LeapMotion(this);
}
void draw() {
background(255);
// ...
int fps = leap.getFrameRate();
// HANDS
for (Hand hand : leap.getHands()) {
hand.draw();
int hand_id = hand.getId();
PVector hand_position = hand.getPosition();
println("x:" + hand_position.x + " Y:" + hand_position.y);
int n = hand.countFingers();
if (n==5 || n==4) image(img5, hand_position.x, hand_position.y);
if (n==2 || n==3) image(img2, hand_position.x, hand_position.y);
if (n==0 || n==1) image(img0, hand_position.x, hand_position.y);
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();
float hand_time = hand.getTimeVisible();
PVector sphere_position = hand.getSpherePosition();
float sphere_radius = hand.getSphereRadius();
// FINGERS
for (Finger finger : hand.getFingers()) {
// Basics
finger.draw();
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();
// 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
tool.draw();
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();
// 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();
// }
}
void leapOnInit() {
// println("Leap Motion Init");
}
void leapOnConnect() {
// println("Leap Motion Connect");
}
void leapOnFrame() {
// println("Leap Motion Frame");
}
void leapOnDisconnect() {
// println("Leap Motion Disconnect");
}
void leapOnExit() {
// println("Leap Motion Exit");
}
第三節
1.寫下其中作品IDEA(圖+文字)
2.Processing+粒子系統
3.方向盤模擬器
import de.voidplus.leapmotion.*;
LeapMotion leap;
PImage imgWheel;
void setup() {
size(600, 600);
noStroke();
fill(50);
leap = new LeapMotion(this);
imgWheel = loadImage("5555.jpg");
}
void draw() {
background(255);
int fps = leap.getFrameRate();
PVector [] Pt = new PVector[4];
int PtN=0;
for (Hand hand : leap.getHands()) {
PVector pos = hand.getPosition();
ellipse(pos.x,pos.y,50,50);
Pt[PtN] = pos;
PtN++;
}
float angle = 0;
if(PtN>=2)
{
line(Pt[0].x, Pt[0].y, Pt[1].x, Pt[1].y);
angle = atan2((Pt[0].y-Pt[1].y),(Pt[0].x-Pt[1].x));
}
imageMode(CENTER);
translate(300,300);
rotate(angle);
translate(-300,-300);
image(imgWheel, 300, 300, 400, 400);
}




沒有留言:
張貼留言