2014年3月10日 星期一

第四周上課內容


  • 跑Rotate程式

  • 簡易的LeapMotion


import de.voidplus.leapmotion.*;
LeapMotion leap;
void setup(){
  size(800,500,P3D);
  leap=new LeapMotion(this);
}
void draw()
{
  background(255);
  for(Hand hand:leap.getHands()){
  hand.draw();
  }
}

  • 利用LEAPMOTION移動手部位置,在地形上投射方塊


  • 讀入OBJ檔



  • 利用地形與自己的OBJ火箭結合
import saito.objloader.*;

OBJModel model;


PeasyCam cam;

BPhysics physics;

BObject rigid;
BTerrain terrain;

public void setup() {
  model = new OBJModel(this, "sh.obj", "relative", QUADS);
  size(1280, 720, P3D);
  frameRate(60);

  cam = new PeasyCam(this, 200);
  cam.pan(0, 50);
  cam.rotateX(.4f);

  physics = new BPhysics();
  physics.world.setGravity(new Vector3f(0, 40, 0));

  float height = 1.1f;
  //BTerrain(PApplet p, int tesselation, float height, int seed, Vector3f position, Vector3f scale) 
  terrain = new BTerrain(this, 110, height, 10, new Vector3f(), new Vector3f(2, 2, 2));
  physics.addBody(terrain);

  //create the first rigidBody as Sphere
  rigid = new BBox(this, 5, 1.0f, 10.0f, 1.0f);
}

public void draw() {
  background(255);
  lights();
  rotateY(frameCount*.002f);

  if (frameCount%2==0) {
    Vector3f pos = new Vector3f(random(-90, 90), -30, random(-90, 90));
    //reuse the rigidBody of the sphere for performance resons
    BObject r = new BObject(this, 5, rigid, pos, true);
    physics.addBody(r);
  }

  physics.update();
  terrain.display();
  for (int i =1;i<physics.rigidBodies.size();i++) {
    BObject b = (BObject) physics.rigidBodies.get(i);
//    b.display(50, 50, 50);
    Vector3f pos = b.getPosition();
    pushMatrix();
    translate(pos.x, pos.y, pos.z);
    model.draw();
    popMatrix();
  }
}



沒有留言:

張貼留言