Class: Disp3D::Light

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

Instance Method Summary collapse

Constructor Details

#initializeLight

Returns a new instance of Light.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/light.rb', line 5

def initialize()
  @diffuse_default = [0.7, 0.7, 0.7, 1]
  @ambient_default = [0.2, 0.2, 0.2, 1]
  @specular_default = [1, 1, 1, 1]
  @position_default = Vector3.new(0.0, 0.0, 1.0)
  @spot_direction_default = Vector3.new(0.0, 0.0, -1.0)

  light_count = 8 # openGL spec

  @enable = [false, false, false, false, false, false, false, false]
  @diffuse = Array.new(light_count, @diffuse_default)
  @ambient = Array.new(light_count, @ambient_default)
  @specular = Array.new(light_count, @specular_default)
  @position = Array.new(light_count, @position_default)
  @spot_direction = Array.new(light_count, @spot_direction_default)
  @light_id = Array.new(light_count)
  @light_id[0] = GL::GL_LIGHT0
  @light_id[1] = GL::GL_LIGHT1
  @light_id[2] = GL::GL_LIGHT2
  @light_id[3] = GL::GL_LIGHT3
  @light_id[4] = GL::GL_LIGHT4
  @light_id[5] = GL::GL_LIGHT5
  @light_id[6] = GL::GL_LIGHT6
  @light_id[7] = GL::GL_LIGHT7
end

Instance Method Details

#gl_displayObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/light.rb', line 31

def gl_display()
  GL.Enable(GL::GL_LIGHTING)
  @enable.each_with_index do | enable, idx |
    if(enable)
      GL.Enable( @light_id[idx])
      GL.Lightfv( @light_id[idx], GL::POSITION, [@position[idx].x,@position[idx].y,@position[idx].z] )
      GL.Lightfv( @light_id[idx], GL::SPOT_DIRECTION, [@spot_direction[idx].x,@spot_direction[idx].y,@spot_direction[idx].z] )
      GL.Lightfv( @light_id[idx], GL::DIFFUSE,  @diffuse[idx]  )
      GL.Lightfv( @light_id[idx], GL::AMBIENT,  @ambient[idx]  )
      GL.Lightfv( @light_id[idx], GL::SPECULAR, @specular[idx] )
    end
  end
  if(!@enable.include?(true))
    GL.Enable(@light_id[0])
  end
end

#open(&block) ⇒ Object



48
49
50
# File 'lib/light.rb', line 48

def open(&block)
  self.instance_eval(&block)
end