2015年4月13日 星期一

week07




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

void setup() {
  size(800, 500, P3D);

  leap = new LeapMotion(this);
}


float nowX=0, nowY, nowA=0;

void draw() {
  background(255);
  for (Hand hand : leap.getHands ()) {
    switch(hand.getOutstrechtedFingers().size()) {
    case 0:
      {
        pushMatrix();
        translate(hand.getPosition().x, hand.getPosition().y);
        rotateZ(radians(hand.getPitch()));
        //rotateZ(-radians(hand.getRoll()));
        rotateY(-radians(hand.getYaw()));
        stroke(0);
        fill(50);
        box(100);
        popMatrix();
      }
      break;
    case 1:
      {
        pushMatrix();
        translate(hand.getPosition().x, hand.getPosition().y);
        rotateZ(radians(hand.getPitch()));
        //rotateZ(-radians(hand.getRoll()));
        rotateY(-radians(hand.getYaw()));
        stroke(0);
        fill(100);
        box(100);
        popMatrix();
      }
      break;
    case 2:
      {
        pushMatrix();
        translate(hand.getPosition().x, hand.getPosition().y);
        rotateZ(radians(hand.getPitch()));
        //rotateZ(-radians(hand.getRoll()));
        rotateY(-radians(hand.getYaw()));
        stroke(0);
        fill(150);
        box(100);
        popMatrix();
      }
      break;
    case 3:
      {
        pushMatrix();
        translate(hand.getPosition().x, hand.getPosition().y);
        rotateZ(radians(hand.getPitch()));
        //rotateZ(-radians(hand.getRoll()));
        rotateY(-radians(hand.getYaw()));
        stroke(0);
        fill(200);
        box(100);
        popMatrix();
      }
      break;
    case 4:
      {
        pushMatrix();
        translate(hand.getPosition().x, hand.getPosition().y);
        rotateZ(radians(hand.getPitch()));
        //rotateZ(-radians(hand.getRoll()));
        rotateY(-radians(hand.getYaw()));
        stroke(0);
        fill(0);
        box(100);
        popMatrix();
      }
      break;

    case 5:
      {
        pushMatrix();
        translate(hand.getPosition().x, hand.getPosition().y);
        rotateZ(radians(hand.getPitch()));
        //rotateZ(-radians(hand.getRoll()));
        rotateY(-radians(hand.getYaw()));
        stroke(0);
        fill(255,0,0);
        sphere(50);
        popMatrix();
      }
      break;
    }
    hand.draw();
  }
}


下面為讀圖用
import de.voidplus.leapmotion.*;
LeapMotion leap;
PImage img;
void setup() {
  size(800, 500, P3D);
  img=loadImage("1.jpg");
  leap = new LeapMotion(this);
}


float nowX=0, nowY, nowA=0;
void draw() {
  background(255);
  for (Hand hand : leap.getHands ()) {
    switch(hand.getOutstrechtedFingers().size()) {
    case 0:
      {
        pushMatrix();
        translate(hand.getPosition().x-50, hand.getPosition().y-50);
        //rotateZ(radians(hand.getPitch()));
        //rotateZ(-radians(hand.getRoll()));
        //rotateY(-radians(hand.getYaw()));
        //stroke(0);
        //fill(50);
        image(img,0,0);
        popMatrix();
      }
      break;
    case 1:
      {
        pushMatrix();..................................................

沒有留言:

張貼留言