Class: Mittsu::Sprite

Inherits:
Object3D show all
Defined in:
lib/mittsu/objects/sprite.rb,
lib/mittsu/renderers/opengl/objects/sprite.rb

Constant Summary collapse

INDICES =
[0, 1, 2,
0, 2, 3]
VERTICES =
[-0.5, -0.5, 0.0,
0.5, -0.5, 0.0,
0.5, 0.5, 0.0,
-0.5, 0.5, 0.0]
UVS =
[0.0, 0.0,
1.0, 0.0,
1.0, 1.0,
0.0, 1.0]
GEOMETRY =
BufferGeometry.new

Constants inherited from Object3D

Object3D::DefaultUp

Instance Attribute Summary collapse

Attributes inherited from Object3D

#active, #cast_shadow, #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 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, #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(material = SpriteMaterial.new) ⇒ Sprite

Returns a new instance of Sprite.



21
22
23
24
25
26
27
28
29
# File 'lib/mittsu/objects/sprite.rb', line 21

def initialize(material = SpriteMaterial.new)
  super()

  @type = 'Sprite'

  @geometry = GEOMETRY
  @material = material
  @z = nil
end

Instance Attribute Details

#materialObject

Returns the value of attribute material.



3
4
5
# File 'lib/mittsu/objects/sprite.rb', line 3

def material
  @material
end

#zObject

Returns the value of attribute z.



3
4
5
# File 'lib/mittsu/objects/sprite.rb', line 3

def z
  @z
end

Instance Method Details

#clone(object = Sprite.new(@material)) ⇒ Object



48
49
50
51
# File 'lib/mittsu/objects/sprite.rb', line 48

def clone(object = Sprite.new(@material))
  super(object)
  object
end

#project(renderer) ⇒ Object



3
4
5
6
7
8
9
10
# File 'lib/mittsu/renderers/opengl/objects/sprite.rb', line 3

def project(renderer)
  @renderer = renderer
  return unless visible
  init
  # TODO!!! FIXME!!!
  @renderer.instance_variable_get(:@sprites) << self
  project_children
end

#raycast(raycaster, intersects) ⇒ Object



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

def raycast(raycaster, intersects)
  @_matrix_position ||= Vector3.new

  @_matrix_position.set_from_matrix_position(@matrix_world)

  distance = raycaster.ray.distance_to_pint(@_matrix_position)

  return if distance > @scale.x

  intersects.push({
    distance: distance,
    point: @position,
    face: nil,
    object: self
    })
end