方塊的左右轉會根據手的旋轉方向轉動唷!!
LeapMotion leap;
void setup(){
size(600, 600, P3D);
leap = new LeapMotion(this);
}
void draw(){
background(255);
for(Hand hand : leap.getHands() ){
hand.draw();
float angle = hand.getYaw(); //抓手的左右轉
PVector pos = hand.getPosition(); //抓手的位置
translate(pos.x, pos.y, pos.z); //讓方塊跟著手一起移動
rotateY(-radians(angle)); //讓方塊跟著手一起轉動
fill(128); stroke(255); box(100); //stroke(0);線條是黑色
}
}
地板會跟方塊反方向轉動
import de.voidplus.leapmotion.*;
LeapMotion leap;
void setup(){
size(600, 600, P3D);
leap = new LeapMotion(this);
}
float groundDir=0;
void draw(){
background(255);
for(int i=-10; i<=10; i++){
for(int j=-10;j<=10; j++){
pushMatrix(); //一直重劃
translate(300, 300); //地板位置
rotateX(radians(70)); //向前面傾斜
rotateZ(radians(groundDir)); //左右轉動是根據groundDir
translate(i*30, j*30); //下一個地板方塊的位置
box(30); //建地板方塊
popMatrix();
}
}
for(Hand hand : leap.getHands() ){
hand.draw();
float angle = hand.getYaw();
PVector pos = hand.getPosition();
translate(pos.x, pos.y, pos.z);
rotateY(-radians(angle));
fill(128); stroke(0); box(100);
groundDir = -angle; //groundDir的角度跟手相反
}
}
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(){
background(255);
nowY+=cos(nowA); nowX+=sin(nowA); //左右旋轉角度
for(int i=-10; i<=10; i++){
for(int j=-10;j<=10; j++){
pushMatrix();
translate(300, 300);
rotateX(radians(70));
rotateZ(nowA); //旋轉
translate(i*200+nowX, j*200+nowY, 0); //
fill(255); box(200);
popMatrix();
}
}
for(Hand hand : leap.getHands() ){
hand.draw();
float angle = hand.getYaw();
PVector pos = hand.getPosition();
nowA += radians(-angle/40); //nowA是地板左右旋轉的角度
translate(pos.x, pos.y, pos.z);
rotateY(-radians(angle));
fill(128); stroke(0); box(100);
}
}
沒有留言:
張貼留言