2015年3月16日 星期一

01162412_葉興宇




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);
    translate(pos.x, pos.y, pos.z);
    rotateY(-radians(angle));
    fill(128);
    stroke(0);
    box(100);
  }
}
















設定旋轉視角和移動速度


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);
    translate(pos.x, pos.y, pos.z);
    rotateY(-radians(angle));
    fill(128);
    stroke(0);
    box(100);
  }
}




判斷左右手與手指數:

void draw(){
  background(255);
  println(leap.getHands().size());
  fill(255, 0, 0);
  textSize(40);
  for(Hand hand: leap.getHands()){
    if(hand.isRight()){
      text("right:"+hand.getOutstrechtedFingers().size(), 300, 300);
    }
    else text("left:"+hand.getOutstrechtedFingers().size(), 150, 300);
  }
}





沒有留言:

張貼留言