Class: Engine::Components::DirectionLight

Inherits:
Engine::Component show all
Includes:
MatrixHelpers
Defined in:
lib/engine/components/direction_light.rb

Instance Attribute Summary collapse

Attributes inherited from Engine::Component

#game_object

Class Method Summary collapse

Instance Method Summary collapse

Methods included from MatrixHelpers

#look_at, #ortho, #perspective

Methods inherited from Engine::Component

#_erase!, #destroy, #destroyed?, destroyed_components, erase_destroyed_components, method_added, #renderer?, #set_game_object, #ui_renderer?, #update

Methods included from Serializable

allowed_class?, get_class, included, register_class, #uuid

Instance Attribute Details

#cast_shadowsObject

Returns the value of attribute cast_shadows.



9
10
11
# File 'lib/engine/components/direction_light.rb', line 9

def cast_shadows
  @cast_shadows
end

#colourObject

Returns the value of attribute colour.



9
10
11
# File 'lib/engine/components/direction_light.rb', line 9

def colour
  @colour
end

#shadow_distanceObject

Returns the value of attribute shadow_distance.



9
10
11
# File 'lib/engine/components/direction_light.rb', line 9

def shadow_distance
  @shadow_distance
end

#shadow_layer_indexObject

Returns the value of attribute shadow_layer_index.



10
11
12
# File 'lib/engine/components/direction_light.rb', line 10

def shadow_layer_index
  @shadow_layer_index
end

Class Method Details

.direction_lightsObject



57
58
59
# File 'lib/engine/components/direction_light.rb', line 57

def self.direction_lights
  @direction_lights ||= []
end

Instance Method Details

#awakeObject



12
13
14
15
16
17
18
19
# File 'lib/engine/components/direction_light.rb', line 12

def awake
  @colour ||= [1.0, 1.0, 1.0]
  @cast_shadows = true if @cast_shadows.nil?
  @shadow_distance ||= 50.0
  @shadow_layer_index = nil
  @cached_light_space_matrix = nil
  @cache_key = nil
end

#destroy!Object



39
40
41
# File 'lib/engine/components/direction_light.rb', line 39

def destroy!
  DirectionLight.direction_lights.delete(self)
end

#directionObject



43
44
45
# File 'lib/engine/components/direction_light.rb', line 43

def direction
  game_object.forward.normalize
end

#light_space_matrixObject



47
48
49
50
51
52
53
54
55
# File 'lib/engine/components/direction_light.rb', line 47

def light_space_matrix
  current_key = compute_cache_key
  if @cached_light_space_matrix && @cache_key == current_key
    return @cached_light_space_matrix
  end

  @cache_key = current_key
  @cached_light_space_matrix = compute_light_space_matrix
end

#startObject



35
36
37
# File 'lib/engine/components/direction_light.rb', line 35

def start
  DirectionLight.direction_lights << self
end