ruby-processingでProcessing->Examples->3D->Cameraの写経

 写経してみたw;

Perspective関連の設定がいまいち思い出せない、年だな〜w;

case :Perspective
when :Perspective
  def setup
    size 640,360,P3D
    no_stroke
  end
  
  def draw
    lights
    background 204
    
    camera_y = height/2.0
    fov = (mouse_x / width.to_f) * (PI / 2.0)
    camera_z  = camera_y / tan(fov / 2.0 )
    aspect = width.to_f / height.to_f
    
    aspect = aspect/2.0 if mouse_pressed?
    
    perspective fov,aspect,camera_z/10,camera_z*10
    
    translate width/2+30, height/2, 0
    rotate_x -PI/6
    rotate_y PI/3 + mouse_y/height.to_f * PI
    box 45
    translate 0,0,-50
    box 30
  end
when :OrthoVSPerspective
  def setup
    size 640,360,P3D
    no_stroke
    fill 204
  end
  
  def draw
    lights
    background 0
    
    if mouse_pressed?
      fov = PI/3
      camera_z = (height/2) / tan(PI*fov/360)
      perspective fov, width/height.to_f,
      camera_z/2,camera_z*2
    else
      ortho -width/2,width/2, -height/2,height/2, -10,10
    end
    
    translate width/2,height/2,0
    rotate_x -PI/6
    rotate_y PI/3
    box 160
  end
when :MoveEye
  def setup
    size 640,360,P3D
    fill 204
  end
  
  def draw
    lights
    background 0
    
    camera 30.0, mouse_y, 220.0,
    0.0,0.0,0.0,
    0.0,1.0,0.0
    
    no_stroke
    box 90
    stroke 255
    line -100,0,0,100,0,0
    line 0,-100,0,0,100,0
    line 0,0,-100,0,0,100
  end
end