2016年3月17日 星期四

02160740_莊鎧旭_WEEK04


手指

旋轉

PVector []bullet_dir=new PVector[10];
int bulletNow=0;
LeapMotion leap;
void setup(){
  size(600,400,P3D);
  leap=new LeapMotion(this);
  for(int i=0;i<10;i++){
    bullet[i]=new PVector(0,0,0);
    bullet_dir[i]=new PVector(0,0,0);
  }
}
void draw(){
  background(255);
  for(Hand hand:leap.getHands()){
    Finger finger_index=hand.getIndexFinger();
    finger_index.draw();
    pos=finger_index.getPosition();
    dir=finger_index.getDirection();
  }
 lights();
 fill(255,0,0);
 translate(width/2,height/2);
 pushMatrix();
    for(int i=0;i<10;i++){
      if(dir!=null) translate(dir.x*10*i,dir.y*10*i,dir.z*10*i);
      sphere(40);
    }
    popMatrix();
    pushMatrix();
      fill(0,0,255);
      for(int i=0;i<10;i++){
        pushMatrix();
          translate(bullet[i].x,bullet[i].y,bullet[i].z);
          sphere(41);
          bullet[i].x+=bullet_dir[i].x;
          bullet[i].y+=bullet_dir[i].y;
          bullet[i].z+=bullet_dir[i].z;
        popMatrix();
      }
      popMatrix();
}
void keyPressed(){
bullet[bulletNow].x=0; bullet[bulletNow].y=0; bullet[bulletNow].z=0;
  bullet_dir[bulletNow].x=dir.x*5;
  bullet_dir[bulletNow].y=dir.y*5;
  bullet_dir[bulletNow].z=dir.z*5;
  bulletNow++;
if(bulletNow>=10){
    bulletNow=0;
  }
}
射擊遊戲
import de.voidplus.leapmotion.*;
LeapMotion leap;
void setup(){
  size(600,400,P3D);
  leap=new LeapMotion(this);
}
PVector pos=null,dir=null;
void draw(){
  background(255);
  for(Hand hand:leap.getHands()){
    Finger finger_index=hand.getIndexFinger();
    finger_index.draw();
    pos=finger_index.getPosition();
    dir=finger_index.getDirection();
  }
  lights();
  fill(255,0,0);
  pushMatrix();
    translate(width/2,height/2);
    for(int i=0;i<10;i++){
      if(dir!=null)
        translate(dir.x*10*i,dir.y*10*i,dir.z*10*i);
       sphere(40);
    }
    popMatrix();
}

import de.voidplus.leapmotion.*;
PVector pos=null,dir=null;
PVector []bullet=new PVector[10];
PVector []bullet_dir=new PVector[10];
int bulletNow=0;
LeapMotion leap;
void setup(){
  size(600,400,P3D);
  leap=new LeapMotion(this);
  for(int i=0;i<10;i++){
    bullet[i]=new PVector(0,0,0);
    bullet_dir[i]=new PVector(0,0,0);
  }
}
void draw(){
  background(255);
  for(Hand hand:leap.getHands()){
    Finger finger_index=hand.getIndexFinger();
    finger_index.draw();
    dir=finger_index.getDirection();
  }
  lights();
  fill(255,0,0);
  translate(width/2,height/2);
  pushMatrix();
    for(int i=0;i<10;i++){
      if(dir!=null)
        translate(dir.x*10*i,dir.y*10*i,dir.z*10*i);
       sphere(40);
    }
  popMatrix();
  pushMatrix();
    fill(0,0,255);
    for(int i=0;i<10;i++){
      pushMatrix();
        translate(bullet[i].x,bullet[i].y,bullet[i].z);
        sphere(41);
        bullet[i].x+=bullet_dir[i].x;
        bullet[i].y+=bullet_dir[i].y;
        bullet[i].z+=bullet_dir[i].z;
      popMatrix();
    }
    popMatrix();
}
void keyPressed(){
  bullet_dir[bulletNow].x=dir.x*5;
  bullet_dir[bulletNow].y=dir.y*5;
  bullet_dir[bulletNow].z=dir.z*5;
  bulletNow++;

}

沒有留言:

張貼留言