Draw a box on your hand's center:
import de.voidplus.leapmotion.*;
LeapMotion leap;
void setup(){
size(600, 600, P3D);
leap= new LeapMotion(this);
}
void draw(){
background(255); //background redraw
for(Hand hand: leap.getHands()){
hand.draw();
float angle= hand.getYaw(); //hand's angle
PVector pos= hand.getPosition(); //hand's position
translate(pos.x, pos.y, pos.z);
rotateY(-radians(angle));
fill(0, 100, 150);
stroke(0);
box(100);
}
}
Fly to right, ground translate to left:
import de.voidplus.leapmotion.*;
LeapMotion leap;
void setup(){
size(600, 600, P3D);
leap= new LeapMotion(this);
}
float groundDir=0;
void draw(){
background(255); //background redraw
//draw ground's box
for(int i=-10;i<=10;i++){
for(int j=-10;j<=10;j++){
pushMatrix(); //matrix
translate(300, 400); //ground's original x&y
rotateX(radians(70));
rotateZ(radians(groundDir));
translate(i*30, j*30);
fill(0, 150, 100);
box(30);
popMatrix(); //matrix
}
}
for(Hand hand: leap.getHands()){
hand.draw();
float angle= hand.getYaw(); //hand's angle
PVector pos= hand.getPosition(); //hand's position
translate(pos.x, pos.y, pos.z);
rotateY(-radians(angle));
fill(0, 100, 150);
stroke(0);
box(100);
groundDir= -angle;
}
}
plane's motion:
import de.voidplus.leapmotion.*;
LeapMotion leap;
void setup(){
size(600, 600, P3D);
leap= new LeapMotion(this);
}
float nowX=0, nowY=0, nowA=0;
void draw(){
nowY+=cos(nowA); nowX+=sin(nowA);
background(0, 150, 200, 100); //background redraw
//draw ground's box
for(int i=-10;i<=10;i++){
for(int j=-10;j<=10;j++){
pushMatrix(); //matrix
translate(300, 500); //ground's original x&y
rotateX(radians(70));
rotateZ(radians(nowA));
translate(i*200+nowX, j*200+nowY, -50);
fill(0, 150, 100); box(200); //ground's color and box's size
popMatrix(); //matrix
}
}
for(Hand hand: leap.getHands()){
hand.draw();
float angle= hand.getYaw(); //hand's angle
PVector pos= hand.getPosition(); //hand's position
nowA+= radians(-angle/40);
translate(pos.x, pos.y, pos.z);
rotateY(-radians(angle));
fill(181, 181, 181); stroke(0); box(100);
}
}
期中作業討論:
彈鋼琴
彈力球
貪吃蛇
賽車
下棋
停車
1010!










沒有留言:
張貼留言