Sha256: 08b7941f504b6f9d8ebeb1fa189d319bce130a6ec9f437d05d08e8752fe2854a
Contents?: true
Size: 1.2 KB
Versions: 3
Compression:
Stored size: 1.2 KB
Contents
require 'mittsu/core' require 'mittsu/math' module Mittsu class CircleGeometry < Geometry 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 end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
mittsu-0.3.2 | lib/mittsu/extras/geometries/circle_geometry.rb |
mittsu-0.3.1 | lib/mittsu/extras/geometries/circle_geometry.rb |
mittsu-0.3.0 | lib/mittsu/extras/geometries/circle_geometry.rb |