2016年3月31日 星期四

期中作品_class_02160323_02160615

import de.voidplus.leapmotion.*;
LeapMotion leap;
PImage imgBoard;
PVector old, right,left,up,down;
void setup()
{
  size(400, 600);
  leap=new LeapMotion(this);
  old=new PVector(0, 0, 0);
  right = new PVector(1, 0, 0);
  left =new PVector(-1, 0, 0);
  up= new PVector(0, -1, 0);
  down=new PVector(0, 1, 0);
  //imgBoard=loadImage("board.png");
}
int [] ans= {1,1,1,0 };
void draw() {
  background(0);
  for (Hand hand : leap.getHands ())
  {
    background(255);
    PVector now =hand.getPosition();
    if (old.x==0 && old.y==0 && old.z==0) {
      old.x=now.x;
      old.y=now.y;
      old.z=now.z;
    }
    if (iGood) {
      image(imgGood, 0, 0);
      iGood--;
    } else if ((PVector.dist(old, now)>10))
    {
      PVector dir =PVector.sub(now, old);
      if (dir.angleBetween(dir, right)<radians(30) && ans[score]==1) {
        score++;
        iGood=60;
      }
      if (dir.angleBetween(dir, left)<radians(30) && ans[score]==2) {
        score++;
        iGood=60;
      }
      if (dir.angleBetween(dir, up)<radians(30) && ans[score]==3) {
        score++;
        iGood=60;
      }
      if (dir.angleBetween(dir, down)<radians(30) && ans[score]==4) {
        score++;
        iGood=60;
      }
    }

    old.x=now.x;
    old.y=now.y;
    old.z=now.z;
  }
  text("score"+score,50,60);
  PVector direction= g.getDirection();
}



////未完待續

沒有留言:

張貼留言