Class: Mittsu::SpotLight

Inherits:
Light show all
Defined in:
lib/mittsu/lights/spot_light.rb,
lib/mittsu/renderers/opengl/lights/spot_light.rb

Defined Under Namespace

Classes: Cache

Constant Summary collapse

TYPE =
:spot

Constants inherited from Object3D

Object3D::DefaultUp

Instance Attribute Summary collapse

Attributes inherited from Light

#camera_helper, #color, #distance, #intensity, #only_shadow

Attributes inherited from Object3D

#active, #children, #frustum_culled, #geometry, #id, #initted, #matrix, #matrix_auto_update, #matrix_world, #matrix_world_needs_update, #model_view_matrix, #morph_target_influences, #name, #parent, #position, #quaternion, #receive_shadow, #render_order, #renderer, #rotation, #rotation_auto_update, #scale, #type, #up, #user_data, #uuid, #visible

Instance Method Summary collapse

Methods inherited from Light

null_remaining_lights, #project, #setup, #type

Methods inherited from Object3D

#active?, #add, #add_opengl_object, #apply_matrix, #buffer_material, #deinit, #get_object_by_id, #get_object_by_name, #get_object_by_property, #get_world_direction, #get_world_position, #get_world_quaternion, #get_world_rotation, #get_world_scale, #init, #init_geometry, #load_uniforms_matrices, #local_to_world, #look_at, #print_tree, #project, #raycast, #remove, #rotate_on_axis, #rotate_x, #rotate_y, #rotate_z, #set_rotation_from_axis_angle, #set_rotation_from_euler, #set_rotation_from_matrix, #set_rotation_from_quaternion, #setup_matrices, #to_json, #to_s, #translate_on_axis, #translate_x, #translate_y, #translate_z, #traverse, #traverse_ancestors, #traverse_visible, #update_matrix, #update_matrix_world, #world_to_local

Methods included from EventDispatcher

#add_event_listener, #dispatch_event, #has_event_listener, #remove_event_listener

Constructor Details

#initialize(color = nil, intensity = 1.0, distance = 0.0, angle = (::Math::PI / 3.0), exponent = 10.0, decay = 1.0) ⇒ SpotLight

Returns a new instance of SpotLight.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/mittsu/lights/spot_light.rb', line 23

def initialize(color = nil, intensity = 1.0, distance = 0.0, angle = (::Math::PI / 3.0), exponent = 10.0, decay = 1.0)
  super(color)

  @type = 'SpotLight'

  @position.set( 0, 1, 0 )
  @target = Object3D.new

  @intensity = intensity
  @distance = distance
  @angle = angle
  @exponent = exponent
  @decay = decay # for physically correct lights, should be 2.

  @cast_shadow = false
  @only_shadow = false

  #

  @shadow_camera_near = 50.0
  @shadow_camera_far = 5000.0
  @shadow_camera_fov = 50.0

  @shadow_camera_visible = false

  @shadow_bias = 0
  @shadow_darkness = 0.5

  @shadow_map_width = 512
  @shadow_map_height = 512

  #

  @shadow_map = nil
  @shadow_map_size = nil
  @shadow_camera = nil
  @shadow_matrix = nil
end

Instance Attribute Details

#angleObject

Returns the value of attribute angle.



5
6
7
# File 'lib/mittsu/lights/spot_light.rb', line 5

def angle
  @angle
end

#cast_shadowObject

Returns the value of attribute cast_shadow.



5
6
7
# File 'lib/mittsu/lights/spot_light.rb', line 5

def cast_shadow
  @cast_shadow
end

#decayObject

Returns the value of attribute decay.



5
6
7
# File 'lib/mittsu/lights/spot_light.rb', line 5

def decay
  @decay
end

#exponentObject

Returns the value of attribute exponent.



5
6
7
# File 'lib/mittsu/lights/spot_light.rb', line 5

def exponent
  @exponent
end

#shadow_biasObject

Returns the value of attribute shadow_bias.



5
6
7
# File 'lib/mittsu/lights/spot_light.rb', line 5

def shadow_bias
  @shadow_bias
end

#shadow_cameraObject

Returns the value of attribute shadow_camera.



5
6
7
# File 'lib/mittsu/lights/spot_light.rb', line 5

def shadow_camera
  @shadow_camera
end

#shadow_camera_farObject

Returns the value of attribute shadow_camera_far.



5
6
7
# File 'lib/mittsu/lights/spot_light.rb', line 5

def shadow_camera_far
  @shadow_camera_far
end

#shadow_camera_fovObject

Returns the value of attribute shadow_camera_fov.



5
6
7
# File 'lib/mittsu/lights/spot_light.rb', line 5

def shadow_camera_fov
  @shadow_camera_fov
end

#shadow_camera_nearObject

Returns the value of attribute shadow_camera_near.



5
6
7
# File 'lib/mittsu/lights/spot_light.rb', line 5

def shadow_camera_near
  @shadow_camera_near
end

#shadow_camera_visibleObject

Returns the value of attribute shadow_camera_visible.



5
6
7
# File 'lib/mittsu/lights/spot_light.rb', line 5

def shadow_camera_visible
  @shadow_camera_visible
end

#shadow_darknessObject

Returns the value of attribute shadow_darkness.



5
6
7
# File 'lib/mittsu/lights/spot_light.rb', line 5

def shadow_darkness
  @shadow_darkness
end

#shadow_mapObject

Returns the value of attribute shadow_map.



5
6
7
# File 'lib/mittsu/lights/spot_light.rb', line 5

def shadow_map
  @shadow_map
end

#shadow_map_heightObject

Returns the value of attribute shadow_map_height.



5
6
7
# File 'lib/mittsu/lights/spot_light.rb', line 5

def shadow_map_height
  @shadow_map_height
end

#shadow_map_sizeObject

Returns the value of attribute shadow_map_size.



5
6
7
# File 'lib/mittsu/lights/spot_light.rb', line 5

def shadow_map_size
  @shadow_map_size
end

#shadow_map_widthObject

Returns the value of attribute shadow_map_width.



5
6
7
# File 'lib/mittsu/lights/spot_light.rb', line 5

def shadow_map_width
  @shadow_map_width
end

#shadow_matrixObject

Returns the value of attribute shadow_matrix.



5
6
7
# File 'lib/mittsu/lights/spot_light.rb', line 5

def shadow_matrix
  @shadow_matrix
end

#targetObject

Returns the value of attribute target.



5
6
7
# File 'lib/mittsu/lights/spot_light.rb', line 5

def target
  @target
end

Instance Method Details

#cloneObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/mittsu/lights/spot_light.rb', line 70

def clone

  light = SpotLight.new

  super(light)

  light.target = @target.clone

  light.intensity = @intensity
  light.distance = @distance
  light.angle = @angle
  light.exponent = @exponent
  light.decay = @decay

  light.cast_shadow = @cast_shadow
  light.only_shadow = @only_shadow

  #

  light.shadow_camera_near = @shadow_camera_near
  light.shadow_camera_far = @shadow_camera_far
  light.shadow_camera_fov = @shadow_camera_fov

  light.shadow_camera_visible = @shadow_camera_visible

  light.shadow_bias = @shadow_bias
  light.shadow_darkness = @shadow_darkness

  light.shadow_map_width = @shadow_map_width
  light.shadow_map_height = @shadow_map_height

  return light
end

#is_virtual=(value) ⇒ Object



66
67
68
# File 'lib/mittsu/lights/spot_light.rb', line 66

def is_virtual=(value)
  @is_virtual = value
end

#setup_specific(index) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/mittsu/renderers/opengl/lights/spot_light.rb', line 15

def setup_specific(index)
  offset = index * 3

  OpenGLHelper.set_color_linear(@cache.colors, offset, color, intensity)

  @_direction.set_from_matrix_position(matrix_world)

  positions = @cache.positions
  positions[offset]     = @_direction.x
  positions[offset + 1] = @_direction.y
  positions[offset + 2] = @_direction.z

  @cache.distances[index] = distance

  @_vector3.set_from_matrix_position(target.matrix_world)
  @_direction.sub(@_vector3)
  @_direction.normalize

  directions = @cache.directions
  directions[offset]     = @_direction.x
  directions[offset + 1] = @_direction.y
  directions[offset + 2] = @_direction.z

  @cache.angles_cos[index] = ::Math.cos(angle)
  @cache.exponents[index] = exponent;
  @cache.decays[index] = distance.zero? ? 0.0 : decay
end

#to_symObject



43
44
45
# File 'lib/mittsu/renderers/opengl/lights/spot_light.rb', line 43

def to_sym
  :spot
end

#virtual?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/mittsu/lights/spot_light.rb', line 62

def virtual?
  @is_virtual
end