Bye Bye Moore

PoCソルジャーな零細事業主が作業メモを残すブログ

Processingで三次元視点を切り替える

camera関数でもいけますが、
Rotete系関数だとちょっとばかし楽にやれるようです。

実際のところ

void setup() {
  size(640, 360, P3D);
  noStroke();
}

void draw() {
  lights();
  background(0);
  float cameraY = height/2.0;  //カメラ視点Y
  float fov = mouseX/float(width) * PI/2;  //カメラ視点X、カメラに追従
  float cameraZ = cameraY / tan(fov / 2.0);//カメラ視点Z、カメラに追従

  perspective(fov, aspect, cameraZ/10.0, cameraZ*10.0);
  
  translate(width/2+30, height/2, 0);
  rotateX(-PI/6);
  rotateY(PI/3 + mouseY/float(height) * PI);
  box(45);
  translate(0, 0, -50);
  box(30);
}