Class: CyberarmEngine::Light

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

Constant Summary collapse

DIRECTIONAL =
0
POINT =
1
SPOT =
2

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#ambientObject

Returns the value of attribute ambient.



8
9
10
# File 'lib/cyberarm_engine/opengl/light.rb', line 8

def ambient
  @ambient
end

#diffuseObject

Returns the value of attribute diffuse.



8
9
10
# File 'lib/cyberarm_engine/opengl/light.rb', line 8

def diffuse
  @diffuse
end

#directionObject

Returns the value of attribute direction.



8
9
10
# File 'lib/cyberarm_engine/opengl/light.rb', line 8

def direction
  @direction
end

#intensityObject

Returns the value of attribute intensity.



8
9
10
# File 'lib/cyberarm_engine/opengl/light.rb', line 8

def intensity
  @intensity
end

#light_idObject (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

#positionObject

Returns the value of attribute position.



8
9
10
# File 'lib/cyberarm_engine/opengl/light.rb', line 8

def position
  @position
end

#specularObject

Returns the value of attribute specular.



8
9
10
# File 'lib/cyberarm_engine/opengl/light.rb', line 8

def specular
  @specular
end

#typeObject

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

#drawObject



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