Class: Rubytracer::Scene

Inherits:
Object
  • Object
show all
Defined in:
lib/rubytracer/scene.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(objects = [], lighting = []) ⇒ Scene

Returns a new instance of Scene.



5
6
7
8
# File 'lib/rubytracer/scene.rb', line 5

def initialize(objects=[], lighting=[])
  @objects = objects
  @lighting = lighting
end

Instance Attribute Details

#lightingObject (readonly)

Returns the value of attribute lighting.



3
4
5
# File 'lib/rubytracer/scene.rb', line 3

def lighting
  @lighting
end

Instance Method Details

#add_light(light) ⇒ Object



14
15
16
# File 'lib/rubytracer/scene.rb', line 14

def add_light(light)
  @lighting << light
end

#add_object(object) ⇒ Object



10
11
12
# File 'lib/rubytracer/scene.rb', line 10

def add_object(object)
  @objects << object
end

#intersect(ray) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/rubytracer/scene.rb', line 18

def intersect(ray)
  min = [nil, Float::INFINITY]
  @objects.map { |object| [object, object.intersect(ray)[0]] }.each do |object, intersection|
    min = [object, intersection] if intersection > 0 && intersection < min[1]
  end
  min
end