2015年3月16日 星期一

Week04

1. 追蹤手
2. 飛行模擬

/* 飛機的上下左右移動 */

float angleYaw = hand.getYaw();
float anglePitch = hand.getPitch();
float angleRoll = hand.getRoll();

rotateX(-radians(angleRoll));
rotateY(-radians(angleYaw));
rotateZ(radians(anglePitch));

/* -------------------------------------------------------------- */ 

/*  讓地板移動的秘訣  */

float nowX, nowY, nowA;

nowX += sin(nowA); nowY += cos(nowA);
for ( int i=-10; .........){
for ( int j=-10...........){
...
...
translate(i*200 + nowX, j*200 + nowY, -200);
...
...
}
}

for (Hand hand : leap.getHands()){
...
...

nowA += radians ( -angleYaw / 100 );
}


/*------------------------------------------------------------------*/

/* 本周最終程式碼 */
import de.voidplus.leapmotion.*;
LeapMotion leap;
void setup(){
  size(600, 600, P3D);
  leap = new LeapMotion(this);
}
float nowX, nowY, nowA;
void draw(){
  nowX += sin(nowA); nowY += cos(nowA);
  background(255);
  for (int i=-10; i<=10; i++){
    for (int j=-10; j<=10; j++){
      pushMatrix();
      translate(300, 300);
      rotateX(radians(80));
      rotateZ(nowA);
      translate(i*200 + nowX, j*200 + nowY, -200);
      fill(255); box(200);
      popMatrix();
    }
  }
  for (Hand hand : leap.getHands()){
    hand.draw();
    float angleYaw = hand.getYaw();
    float anglePitch = hand.getPitch();
    float angleRoll = hand.getRoll();
    PVector pos = hand.getPosition();
    translate(pos.x, pos.y, pos.z);
    rotateX(-radians(angleRoll));
    rotateY(-radians(angleYaw));
    rotateZ(radians(anglePitch));
    fill(128); stroke(0); box(80);
    nowA += radians( -angleYaw/100 );
  }
}
/*------------------------------------------------------------------------*/

沒有留言:

張貼留言