Class: GlimR::Light

Inherits:
SceneObject show all
Defined in:
lib/glimr/renderer/light.rb

Constant Summary collapse

LIGHTS =
GL::constants.grep(/^LIGHT[0-9]+/).map{|l| GL.const_get l }

Instance Attribute Summary collapse

Attributes inherited from SceneObject

#children, #drawables, #mtime, #parent, #viewport

Attributes included from EventListener

#event_listeners, #listener_count

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SceneObject

#<<, #absolute_geometry, #absolute_material, #absolute_shader, #absolute_texture, #absolute_transform, #absolute_transform_for_drawing, #add_drawables, #apply, #attach, #clone, #default_config, #detach, #detach_self, #initialize, #inspect, #pop_state, #push_state, #remove_drawables, #render, #replace_node, #root, #touch!, #visible

Methods included from Configurable

#default_config, #initialize

Methods included from EventListener

#add_event_listener, #decrement_listener_count, #dispatch_event, #event_root, #increment_listener_count, #initialize, #method_missing, #multicast_event, #process_event, #remove_event_listener

Constructor Details

This class inherits a constructor from GlimR::SceneObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class GlimR::EventListener

Instance Attribute Details

#ambientObject

Returns the value of attribute ambient.



24
25
26
# File 'lib/glimr/renderer/light.rb', line 24

def ambient
  @ambient
end

#constant_attenuationObject

Returns the value of attribute constant_attenuation.



25
26
27
# File 'lib/glimr/renderer/light.rb', line 25

def constant_attenuation
  @constant_attenuation
end

#diffuseObject

Returns the value of attribute diffuse.



24
25
26
# File 'lib/glimr/renderer/light.rb', line 24

def diffuse
  @diffuse
end

#linear_attenuationObject

Returns the value of attribute linear_attenuation.



25
26
27
# File 'lib/glimr/renderer/light.rb', line 25

def linear_attenuation
  @linear_attenuation
end

#positionObject

Returns the value of attribute position.



24
25
26
# File 'lib/glimr/renderer/light.rb', line 24

def position
  @position
end

#quadratic_attenuationObject

Returns the value of attribute quadratic_attenuation.



25
26
27
# File 'lib/glimr/renderer/light.rb', line 25

def quadratic_attenuation
  @quadratic_attenuation
end

#specularObject

Returns the value of attribute specular.



24
25
26
# File 'lib/glimr/renderer/light.rb', line 24

def specular
  @specular
end

Class Method Details

.reserve_light_idObject



11
12
13
14
15
16
17
# File 'lib/glimr/renderer/light.rb', line 11

def self.reserve_light_id
  @index ||= 0
  return false if LIGHTS.size <= @index
  l = LIGHTS[@index]
  @index += 1
  l
end

.reset_lightsObject



19
20
21
22
# File 'lib/glimr/renderer/light.rb', line 19

def self.reset_lights
  @index = 0
  LIGHTS.each{|l| Disable(l) }
end

Instance Method Details

#setupObject



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/glimr/renderer/light.rb', line 27

def setup
  light_id = self.class.reserve_light_id
  return unless light_id
  Enable(light_id)
  Lightfv(light_id, POSITION, position ) if position
  Lightfv(light_id, DIFFUSE, diffuse ) if diffuse
  Lightfv( light_id, SPECULAR, specular ) if specular
  Lightfv( light_id, AMBIENT, ambient ) if ambient
  Lightf( light_id, CONSTANT_ATTENUATION, constant_attenuation) if constant_attenuation
  Lightf( light_id, LINEAR_ATTENUATION, linear_attenuation) if linear_attenuation
  Lightf( light_id, QUADRATIC_ATTENUATION, quadratic_attenuation) if quadratic_attenuation
end