2015年3月9日 星期一

HW03, Week03

複習上週課程:

sketch/Import Library/Add Library


last week's code:

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()){
    hand.draw();
  }
}



將手掌中心加入box:

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()){
    hand.draw();
    PVector pos= hand.getPosition();
    translate(pos.x, pos.y);
    fill(255, 0 , 0); box(100);
  }
}









每個手指間都有原點:

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()){
    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();
}




roll, pitch, yaw:
   
    pushMatrix();
    translate(hand.getPosition().x, hand.getPosition().y);
    rotateZ(radians(hand.getPitch()));
    rotateY(-radians(hand.getYaw()));
    rotateX(radians(hand.getRoll()));
    box(100);
    popMatrix();

only yaw's photo:




roll, pitch, yaw photo:







判斷左右手與手指數:

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






沒有留言:

張貼留言