Class: Mittsu::LatheGeometry
- Defined in:
- lib/mittsu/extras/geometries/lathe_geometry.rb
Constant Summary
Constants included from OpenGLGeometryLike
OpenGLGeometryLike::CONST_BUFFER_NAMES
Instance Attribute Summary
Attributes inherited from Geometry
#bounding_box, #bounding_sphere, #colors, #dynamic, #face_vertex_uvs, #faces, #groups, #has_tangents, #id, #initted, #line_distances, #morph_colors, #morph_normals, #morph_targets, #name, #skin_indices, #skin_weights, #type, #uuid, #vertices
Attributes included from OpenGLGeometryLike
#custom_attributes_list, #face_count, #faces3, #initted_arrays, #line_count, #morph_normals_arrays, #morph_normals_buffers, #morph_targets_arrays, #morph_targets_buffers, #num_morph_normals, #num_morph_targets, #num_vertices, #particle_count, #renderer, #type_array, #vertex_array_object
Instance Method Summary collapse
-
#initialize(points, segments = 12, phi_start = 0.0, phi_length = (::Math::PI * 2.0)) ⇒ LatheGeometry
constructor
A new instance of LatheGeometry.
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, #create_line_buffers, #create_particle_buffers, #dispose, #from_buffer_geometry, #init_geometry_groups, #init_line_buffers, #init_particle_buffers, #merge, #merge_mesh, #merge_vertices, #set_line_buffers, #set_particle_buffers, #to_json
Methods included from OpenGLGeometryLike
#bind_vertex_array_object, #update_other_buffers, #update_vertex_buffer
Methods included from EventDispatcher
#add_event_listener, #dispatch_event, #has_event_listener, #remove_event_listener
Constructor Details
#initialize(points, segments = 12, phi_start = 0.0, phi_length = (::Math::PI * 2.0)) ⇒ LatheGeometry
Returns a new instance of LatheGeometry.
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/mittsu/extras/geometries/lathe_geometry.rb', line 6 def initialize(points, segments = 12, phi_start = 0.0, phi_length = (::Math::PI * 2.0)) super() @type = 'LatheGeometry' @parameters = { points: points, segments: segments, phi_start: phi_start, phi_length: phi_length } inverse_point_length = 1.0 / (points.length.to_f - 1.0) inverse_segments = 1.0 / segments.to_f for i in 0..segments do phi = phi_start + i.to_f * inverse_segments * phi_length c = ::Math.cos(phi) s = ::Math.sin(phi) for j in 0...points.length do pt = points[j] vertex = Vector3.new vertex.x = c * pt.x vertex.y = pt.y vertex.z = s * pt.x @vertices << vertex end end np = points.length for i in 0...segments do for j in 0...(points.length - 1) do base = j + np * i a = base b = base + np c = base + 1 + np d = base + 1 u0 = i.to_f * inverse_segments v0 = j.to_f * inverse_point_length u1 = u0 + inverse_segments v1 = v0 + inverse_point_length @faces << Face3.new(a, b, d) @face_vertex_uvs[0] << [ Vector2.new(u0, v0), Vector2.new(u1, v0), Vector2.new(u0, v1) ] @faces << Face3.new(b, c, d) @face_vertex_uvs[0] << [ Vector2.new(u1, v0), Vector2.new(u1, v1), Vector2.new(u0, v1) ] end end merge_vertices compute_face_normals compute_vertex_normals end |