顯示具有 01160882_廖經豪 標籤的文章。 顯示所有文章
顯示具有 01160882_廖經豪 標籤的文章。 顯示所有文章

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 );
  }
}
/*------------------------------------------------------------------------*/

2015年3月9日 星期一

Week03, 手控制方塊



import de.voidplus.leapmotion.*;
LeapMotion leap;
void setup(){
  size(800, 600, P3D);
  leap = new LeapMotion(this);
}
void draw(){
  background(255);
  for (Hand hand: leap.getHands()){
    println("yaw:" + hand.getYaw());
    pushMatrix();
    translate(hand.getPosition().x, hand.getPosition().y);
    rotateZ(radians(hand.getPitch()));
    rotateY(-radians(hand.getYaw()));
    stroke(0); fill(255); box(100);
    popMatrix();
    hand.draw();
    myDraw(hand.getPosition());
    myDraw(hand.getThumb().getPosition());
    myDraw(hand.getIndexFinger().getPosition());
    myDraw(hand.getMiddleFinger().getPosition());
    myDraw(hand.getRingFinger().getPosition());
    myDraw(hand.getPinkyFinger().getPosition());
  }
}
void myDraw(PVector pos){
  pushMatrix();
  translate(pos.x, pos.y);
  fill(255, 0, 0);
  sphere(20);
  popMatrix();
}

2015年3月2日 星期一

Week01, 首次運行leap & 程式


import de.voidplus.leapmotion.*; //use all leapmotion
LeapMotion lp;
void setup(){
  size(800, 600, P3D); //create a window 800x600
  lp = new LeapMotion(this);
}
void draw(){
  background(255);
  //C# loop (good!)
  for (Hand hand : lp.getHands()){
    hand.draw(); //show hands
  }
}