2015年3月9日 星期一

Week02

先試試看幫手穿一個方塊

import de.voidplus.leapmotion.*;
LeapMotion leap;
void setup(){
  size(600, 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();
}

再加上一個可以隨著手擺動而轉動的方塊

import de.voidplus.leapmotion.*;
LeapMotion leap;

void setup(){
  size(600,600,P3D);
  leap=new LeapMotion(this);
}

void draw(){
  background(255);
  for(Hand hand : leap.getHands()){
    println("yaw:"+hand.getYaw());
    pushMatrix();
    translate(300,300);
    rotateY(hand.getYaw()*0.1);
    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();
}

讓方塊更明顯

import de.voidplus.leapmotion.*;
LeapMotion leap;

void setup(){
  size(600,600,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()));
    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();
}

剪刀石頭布判定

import de.voidplus.leapmotion.*;
LeapMotion leap;

void setup() {
  size(800, 600, P3D);
  leap = new LeapMotion(this);
}

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

沒有留言:

張貼留言