Sha256: 437276288585e86d07b9a667a9aea17b7fa313fd282370121241dfe0fa7e0154

Contents?: true

Size: 1.03 KB

Versions: 6

Compression:

Stored size: 1.03 KB

Contents

# Click to see the difference between orthographic projection
# and perspective projection as applied to a simple box.
# The ortho function sets an orthographic projection and 
# defines a parallel clipping volume. All objects with the 
# same dimension appear the same size, regardless of whether 
# they are near or far from the camera. The parameters to this 
# function specify the clipping volume where left and right 
# are the minimum and maximum x values, top and bottom are the 
# minimum and maximum y values, and near and far are the minimum 
# and maximum z values.

def setup
  size 640, 360, P3D
  no_stroke
  fill 204
end

def draw
  background 0
  lights
  
  mouse_pressed? ? show_perspective : show_orthographic
  
  translate width/2, height/2, 0
  rotate_x -PI/6
  rotate_y PI/3
  box 160
end

def show_perspective
  fov = PI/3.0
  camera_z = (height/2.0) / tan(PI * fov / 360.0)
  perspective fov, width.to_f/height.to_f, camera_z/2.0, camera_z*2.0
end

def show_orthographic
  ortho -width/2, width/2, -height/2, height/2, -10, 10
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ruby-processing-1.0.11 samples/processing_app/3D/camera/ortho_vs_perspective.rb
ruby-processing-1.0.10.1 samples/processing_app/3D/camera/ortho_vs_perspective.rb
ruby-processing-1.0.9 samples/processing_app/3D/camera/ortho_vs_perspective.rb
ruby-processing-1.0.6 samples/processing_app/3D/camera/ortho_vs_perspective.rb
ruby-processing-1.0.7 samples/processing_app/3D/camera/ortho_vs_perspective.rb
ruby-processing-1.0.8 samples/processing_app/3D/camera/ortho_vs_perspective.rb