2015年3月9日 星期一

Week03

在指尖上畫一個圓形的手指
import de.voidplus.leapmotion.*;
LeapMotion leap;
void setup(){
 size(600,400,P3D);
leap = new LeapMotion(this); 
}
void draw(){
 background(255);
for(Hand hand : leap.getHands() ){
 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(15);
 popMatrix(); 
}
自己寫一個函示 myDraw


----------------------------------------------------------------------------------------------

手平行轉動(Yaw)帶動方塊轉
import de.voidplus.leapmotion.*;
LeapMotion leap;
void setup() {
  size(600, 400, P3D);
  leap = new LeapMotion(this);
}
void draw() {
  background(255);
  for (Hand hand : leap.getHands () ) {
    println("yaw"+hand.getYaw());
    
    pushMatrix();
    translate(300,300);
    rotateY(-radians(hand.getYaw()));
    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(15);
  popMatrix();
}



增加更多旋轉方式(raw pitch roll)
類似開飛機,方塊代表飛機


import de.voidplus.leapmotion.*;
LeapMotion leap;
void setup() {
  size(600, 400, P3D);
  leap = new LeapMotion(this);
}
void draw() {
  background(255);
  for (Hand hand : leap.getHands () ) {
    println("yaw"+hand.getYaw());
    println("pitch"+hand.getPitch());
    println("roll"+hand.getRoll());
    
    pushMatrix();
    translate(hand.getPosition().x,hand.getPosition().y);
    rotateY(-radians(hand.getYaw()));
    rotateZ(radians(hand.getPitch()));
    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(15);
  popMatrix();
}


沒有留言:

張貼留言