Class: CyberarmEngine::Light
- Inherits:
-
Object
- Object
- CyberarmEngine::Light
- Includes:
- OpenGL
- 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.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/cyberarm_engine/opengl/light.rb', line 12 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.
10 11 12 |
# File 'lib/cyberarm_engine/opengl/light.rb', line 10 def ambient @ambient end |
#diffuse ⇒ Object
Returns the value of attribute diffuse.
10 11 12 |
# File 'lib/cyberarm_engine/opengl/light.rb', line 10 def diffuse @diffuse end |
#direction ⇒ Object
Returns the value of attribute direction.
10 11 12 |
# File 'lib/cyberarm_engine/opengl/light.rb', line 10 def direction @direction end |
#intensity ⇒ Object
Returns the value of attribute intensity.
10 11 12 |
# File 'lib/cyberarm_engine/opengl/light.rb', line 10 def intensity @intensity end |
#light_id ⇒ Object (readonly)
Returns the value of attribute light_id.
9 10 11 |
# File 'lib/cyberarm_engine/opengl/light.rb', line 9 def light_id @light_id end |
#position ⇒ Object
Returns the value of attribute position.
10 11 12 |
# File 'lib/cyberarm_engine/opengl/light.rb', line 10 def position @position end |
#specular ⇒ Object
Returns the value of attribute specular.
10 11 12 |
# File 'lib/cyberarm_engine/opengl/light.rb', line 10 def specular @specular end |
#type ⇒ Object
Returns the value of attribute type.
10 11 12 |
# File 'lib/cyberarm_engine/opengl/light.rb', line 10 def type @type end |
Instance Method Details
#convert(struct, apply_intensity = false) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/cyberarm_engine/opengl/light.rb', line 44 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
34 35 36 37 38 39 40 41 42 |
# File 'lib/cyberarm_engine/opengl/light.rb', line 34 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 |