Class: CyberarmEngine::Light
- Inherits:
-
Object
- Object
- CyberarmEngine::Light
- Defined in:
- lib/cyberarm_engine/opengl/light.rb
Constant Summary collapse
- DIRECTIONAL =
0- POINT =
1- SPOT =
2
Instance Attribute Summary collapse
-
#ambient ⇒ Object
Returns the value of attribute ambient.
-
#diffuse ⇒ Object
Returns the value of attribute diffuse.
-
#direction ⇒ Object
Returns the value of attribute direction.
-
#intensity ⇒ Object
Returns the value of attribute intensity.
-
#light_id ⇒ Object
readonly
Returns the value of attribute light_id.
-
#position ⇒ Object
Returns the value of attribute position.
-
#specular ⇒ Object
Returns the value of attribute specular.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #convert(struct, apply_intensity = false) ⇒ Object
- #draw ⇒ Object
-
#initialize(id:, type: Light::POINT, ambient: Vector.new(0.5, 0.5, 0.5), diffuse: Vector.new(1, 1, 1), specular: Vector.new(0.2, 0.2, 0.2), position: Vector.new(0, 0, 0), direction: Vector.new(0, 0, 0), intensity: 1) ⇒ Light
constructor
A new instance of Light.
Constructor Details
#initialize(id:, type: Light::POINT, ambient: Vector.new(0.5, 0.5, 0.5), diffuse: Vector.new(1, 1, 1), specular: Vector.new(0.2, 0.2, 0.2), position: Vector.new(0, 0, 0), direction: Vector.new(0, 0, 0), intensity: 1) ⇒ Light
Returns a new instance of Light.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/cyberarm_engine/opengl/light.rb', line 10 def initialize( id:, type: Light::POINT, ambient: Vector.new(0.5, 0.5, 0.5), diffuse: Vector.new(1, 1, 1), specular: Vector.new(0.2, 0.2, 0.2), position: Vector.new(0, 0, 0), direction: Vector.new(0, 0, 0), intensity: 1 ) @light_id = id @type = type @ambient = ambient @diffuse = diffuse @specular = specular @position = position @direction = direction @intensity = intensity end |
Instance Attribute Details
#ambient ⇒ Object
Returns the value of attribute ambient.
8 9 10 |
# File 'lib/cyberarm_engine/opengl/light.rb', line 8 def ambient @ambient end |
#diffuse ⇒ Object
Returns the value of attribute diffuse.
8 9 10 |
# File 'lib/cyberarm_engine/opengl/light.rb', line 8 def diffuse @diffuse end |
#direction ⇒ Object
Returns the value of attribute direction.
8 9 10 |
# File 'lib/cyberarm_engine/opengl/light.rb', line 8 def direction @direction end |
#intensity ⇒ Object
Returns the value of attribute intensity.
8 9 10 |
# File 'lib/cyberarm_engine/opengl/light.rb', line 8 def intensity @intensity end |
#light_id ⇒ Object (readonly)
Returns the value of attribute light_id.
7 8 9 |
# File 'lib/cyberarm_engine/opengl/light.rb', line 7 def light_id @light_id end |
#position ⇒ Object
Returns the value of attribute position.
8 9 10 |
# File 'lib/cyberarm_engine/opengl/light.rb', line 8 def position @position end |
#specular ⇒ Object
Returns the value of attribute specular.
8 9 10 |
# File 'lib/cyberarm_engine/opengl/light.rb', line 8 def specular @specular end |
#type ⇒ Object
Returns the value of attribute type.
8 9 10 |
# File 'lib/cyberarm_engine/opengl/light.rb', line 8 def type @type end |
Instance Method Details
#convert(struct, apply_intensity = false) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/cyberarm_engine/opengl/light.rb', line 42 def convert(struct, apply_intensity = false) if apply_intensity struct.to_a.compact.map { |i| i * @intensity } else struct.to_a.compact end end |
#draw ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/cyberarm_engine/opengl/light.rb', line 32 def draw glLightfv(@light_id, GL_AMBIENT, convert(@ambient).pack("f*")) glLightfv(@light_id, GL_DIFFUSE, convert(@diffuse, true).pack("f*")) glLightfv(@light_id, GL_SPECULAR, convert(@specular, true).pack("f*")) glLightfv(@light_id, GL_POSITION, convert(@position).pack("f*")) glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1) glEnable(GL_LIGHTING) glEnable(@light_id) end |