processingのカメラユーティリティークラス。

3Dカメラのアニメーションを手軽にやりたい。そんなときのために。

Camera.pde

/**
 * Camera class
 * easy animation camera ;
 * 
 * NEED import traer.animation.*;
 * ####### Functions ########
 * 
 * Camera(float x, float y, float z);
 * Camera(); ============ default is Camera(width/2, height/2, 0);
 * void camera.draw();=========== use in draw() method !!
 * void camera.pos.move(float x, float y, float z);
 * void camera.pos.add(x,y,z);
 * void camera.rot.move(x,y,z);
 * void camera.rot.add(x,y,z);
 **/
public class Camera
{
  import traer.animation.*;

  public Parameter pos, rot;
  private Animator tween;


  public Camera(float x, float y, float z)
  {
    tween = new Animator(0.95);
    pos = new Parameter(tween.make3DSmoother());
    rot = new Parameter(tween.make3DSmoother());
  }

  public Camera()
  {
    this(width/2, height/2, 0);
  }
  public void draw()
  {
    tween.tick();
    translate(width/2+pos.x(), height/2+pos.y(), pos.z());
    rotateX(rot.x());
    rotateY(rot.y());
    rotateZ(rot.z());
  }

  class Parameter
  {
    Smoother3D p;
    Parameter(Smoother3D p0)
    {
      p = p0;
    }
    public void move(float x, float y, float z)
    {
      p.setTarget(-x,-y,z);
    }
    public void add(float x, float y, float z)
    {
      x = p.x()+x;
      y = p.y()+y;
      z = p.z()+z;
      p.setTarget(x,y,z);
    }
    public float x() { 
      return p.x(); 
    }
    public float y() { 
      return p.y(); 
    }
    public float z() { 
      return p.z(); 
    }
  }

}