Sha256: 68317b451df2ff44edb2cbbde3c764a0cfc9d09c1f4a51e71900e703b3ed194f

Contents?: true

Size: 1.14 KB

Versions: 16

Compression:

Stored size: 1.14 KB

Contents

# Move the mouse left and right to change the field of view (fov).
# Click to modify the aspect ratio. The perspective method
# sets a perspective projection applying foreshortening, making 
# distant objects appear smaller than closer ones. The parameters 
# define a viewing volume with the shape of truncated pyramid. 
# Objects near to the front of the volume appear their actual size, 
# while farther objects appear smaller. This projection simulates 
# the perspective of the world more accurately than orthographic projection. 
# The version of perspective without parameters sets the default 
# perspective and the version with four parameters allows the programmer 
# to set the area precisely.

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 /= 2.0 if mouse_pressed?
  
  perspective(fov, aspect, camera_z/10.0, camera_z*10.0)
  
  translate width/2.0+30, height/2.0, 0
  rotate_x -PI/6
  rotate_y PI/3 + mouse_y/height.to_f * PI
  box 45
  translate 0, 0, -50
  box 30
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
ruby-processing-2.6.3 samples/processing_app/basics/camera/perspective.rb
ruby-processing-2.6.2 samples/processing_app/basics/camera/perspective.rb
ruby-processing-2.6.1 samples/processing_app/basics/camera/perspective.rb
ruby-processing-2.6.0 samples/processing_app/basics/camera/perspective.rb
ruby-processing-2.5.1 samples/processing_app/basics/camera/perspective.rb
ruby-processing-2.5.0 samples/processing_app/basics/camera/perspective.rb
ruby-processing-2.4.4 samples/processing_app/basics/camera/perspective.rb
ruby-processing-2.4.3 samples/processing_app/basics/camera/perspective.rb
ruby-processing-2.4.2 samples/processing_app/basics/camera/perspective.rb
ruby-processing-2.4.1 samples/processing_app/basics/camera/perspective.rb
ruby-processing-1.0.11 samples/processing_app/3D/camera/perspective.rb
ruby-processing-1.0.10.1 samples/processing_app/3D/camera/perspective.rb
ruby-processing-1.0.9 samples/processing_app/3D/camera/perspective.rb
ruby-processing-1.0.6 samples/processing_app/3D/camera/perspective.rb
ruby-processing-1.0.7 samples/processing_app/3D/camera/perspective.rb
ruby-processing-1.0.8 samples/processing_app/3D/camera/perspective.rb