Class: Mittsu::CircleGeometry

Inherits:
Geometry
  • Object
show all
Defined in:
lib/mittsu/extras/geometries/circle_geometry.rb

Instance Attribute Summary

Attributes inherited from Geometry

#bounding_box, #bounding_sphere, #colors, #dynamic, #face_vertex_uvs, #faces, #has_tangents, #id, #line_distances, #morph_colors, #morph_normals, #morph_targets, #name, #skin_indices, #skin_weights, #type, #uuid, #vertices

Instance Method Summary collapse

Methods inherited from Geometry

#apply_matrix, #center, #clone, #compute_bounding_box, #compute_bounding_sphere, #compute_face_normals, #compute_line_distances, #compute_morph_normals, #compute_tangents, #compute_vertex_normals, #dispose, #from_buffer_geometry, #merge, #merge_mesh, #merge_vertices, #to_json

Methods included from EventDispatcher

#add_event_listener, #dispatch_event, #has_event_listener, #remove_event_listener

Constructor Details

#initialize(radius = 50.0, segments = 8, theta_start = 0.0, theta_length = (::Math::PI * 2.0)) ⇒ CircleGeometry

Returns a new instance of CircleGeometry.



6
7
8
9
10
11
12
13
14
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
42
43
44
45
46
# File 'lib/mittsu/extras/geometries/circle_geometry.rb', line 6

def initialize(radius = 50.0, segments = 8, theta_start = 0.0, theta_length = (::Math::PI * 2.0))
  super()

  @type = 'CircleGeometry'

  @parameters = {
    radius:       radius,
    segments:     segments,
    theta_start:  theta_start,
    theta_length: theta_length
  }

  segments = [3, segments].max

  center = Vector3.new
  center_uv = Vector2.new(0.5, 0.5)

  @vertices << center
  uvs = [center_uv]

  for i in 0..segments do
    vertex = Vector3.new
    segment = theta_start + i.to_f / segments.to_f * theta_length

    vertex.x = radius * ::Math.cos(segment)
    vertex.y = radius * ::Math.sin(segment)

    @vertices << vertex
    uvs << Vector2.new((vertex.x / radius + 1.0) / 2.0, (vertex.y / radius + 1.0) / 2.0)
  end

  n = Vector3.new

  for i in 1..segments do
    @faces << Face3.new(i, i + 1, 0, [n.clone, n.clone, n.clone])
    @face_vertex_uvs[0] << [uvs[i].clone, uvs[i + 1].clone, center_uv.clone]
  end

  compute_face_normals
  @bounding_sphere = Sphere.new(Vector3.new, radius)
end