mittsu 0.2.3 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build-workflow.yml +95 -0
- data/.gitignore +1 -0
- data/Gemfile +3 -2
- data/README.md +3 -7
- data/Rakefile +1 -0
- data/install-glfw.ps1 +13 -0
- data/lib/mittsu.rb +1 -16
- data/lib/mittsu/cameras/camera.rb +0 -2
- data/lib/mittsu/cameras/cube_camera.rb +0 -2
- data/lib/mittsu/cameras/orthographic_camera.rb +2 -4
- data/lib/mittsu/cameras/perspective_camera.rb +4 -5
- data/lib/mittsu/core/buffer_geometry.rb +3 -3
- data/lib/mittsu/core/geometry.rb +10 -9
- data/lib/mittsu/core/object_3d.rb +9 -7
- data/lib/mittsu/core/raycaster.rb +0 -2
- data/lib/mittsu/extras/geometries.rb +13 -0
- data/lib/mittsu/extras/geometries/circle_geometry.rb +48 -0
- data/lib/mittsu/extras/geometries/cylinder_geometry.rb +145 -0
- data/lib/mittsu/extras/geometries/dodecahedron_geometry.rb +56 -0
- data/lib/mittsu/extras/geometries/icosahedron_geometry.rb +33 -0
- data/lib/mittsu/extras/geometries/lathe_geometry.rb +78 -0
- data/lib/mittsu/extras/geometries/octahedron_geometry.rb +26 -0
- data/lib/mittsu/extras/geometries/parametric_buffer_geometry.rb +92 -0
- data/lib/mittsu/extras/geometries/parametric_geometry.rb +93 -0
- data/lib/mittsu/extras/geometries/plane_buffer_geometry.rb +81 -0
- data/lib/mittsu/extras/geometries/plane_geometry.rb +22 -0
- data/lib/mittsu/extras/geometries/polyhedron_geometry.rb +168 -0
- data/lib/mittsu/extras/geometries/ring_geometry.rb +80 -0
- data/lib/mittsu/extras/geometries/sphere_geometry.rb +4 -4
- data/lib/mittsu/extras/geometries/tetrahedron_geometry.rb +26 -0
- data/lib/mittsu/extras/geometries/torus_geometry.rb +63 -0
- data/lib/mittsu/extras/geometries/torus_knot_buffer_geometry.rb +120 -0
- data/lib/mittsu/extras/geometries/torus_knot_geometry.rb +25 -0
- data/lib/mittsu/extras/helpers/camera_helper.rb +38 -38
- data/lib/mittsu/extras/image_utils.rb +1 -1
- data/lib/mittsu/lights/directional_light.rb +9 -5
- data/lib/mittsu/lights/spot_light.rb +1 -1
- data/lib/mittsu/loaders/loader.rb +2 -2
- data/lib/mittsu/loaders/obj_loader.rb +4 -0
- data/lib/mittsu/materials/material.rb +6 -3
- data/lib/mittsu/math.rb +0 -5
- data/lib/mittsu/math/box2.rb +0 -2
- data/lib/mittsu/math/box3.rb +0 -2
- data/lib/mittsu/math/color.rb +3 -4
- data/lib/mittsu/math/euler.rb +25 -26
- data/lib/mittsu/math/frustum.rb +0 -2
- data/lib/mittsu/math/line3.rb +0 -2
- data/lib/mittsu/math/matrix3.rb +0 -2
- data/lib/mittsu/math/matrix4.rb +10 -12
- data/lib/mittsu/math/plane.rb +0 -2
- data/lib/mittsu/math/quaternion.rb +18 -20
- data/lib/mittsu/math/ray.rb +1 -3
- data/lib/mittsu/math/sphere.rb +1 -3
- data/lib/mittsu/math/spline.rb +0 -2
- data/lib/mittsu/math/triangle.rb +1 -3
- data/lib/mittsu/math/vector.rb +4 -4
- data/lib/mittsu/math/vector2.rb +0 -1
- data/lib/mittsu/math/vector3.rb +0 -1
- data/lib/mittsu/math/vector4.rb +8 -9
- data/lib/mittsu/objects/line.rb +0 -1
- data/lib/mittsu/renderers/glfw_lib.rb +1 -1
- data/lib/mittsu/renderers/glfw_window.rb +1 -1
- data/lib/mittsu/renderers/opengl/core/object_3d.rb +1 -1
- data/lib/mittsu/renderers/opengl/lights/spot_light.rb +1 -1
- data/lib/mittsu/renderers/opengl/opengl_geometry_group.rb +1 -0
- data/lib/mittsu/renderers/opengl/opengl_program.rb +1 -2
- data/lib/mittsu/renderers/opengl/textures/texture.rb +1 -1
- data/lib/mittsu/renderers/opengl_renderer.rb +5 -10
- data/lib/mittsu/scenes/scene.rb +0 -2
- data/lib/mittsu/textures/texture.rb +4 -2
- data/lib/mittsu/utils.rb +15 -0
- data/lib/mittsu/version.rb +1 -1
- data/mittsu.gemspec +10 -9
- metadata +75 -47
- data/.circleci/config.yml +0 -44
- data/.travis.yml +0 -20
- data/appveyor.yml +0 -23
- data/install_glfw.ps1 +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bce7b85c4911927e9f33bb5212d9011122a33356cc8811b33482af05577b9977
|
4
|
+
data.tar.gz: 23620dc7e242612382df2647df7b45f2a21364543deb0d64e389844d65a069c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 192b53dca3a2f7ecc79c22cdeae9410d7ce5dcf4af30803d9f0242bdc9caa10cef93cc8a1948932da102cbfe049e6d67951ce983e27ed40f20809fa18b044897
|
7
|
+
data.tar.gz: d08903f9f798c488b35f52f991e311bdbd2f95427094c10b55c5c6d67570d4956c8616d52ad025b9507945e57a5e3ecbff876c50472317493e778d6819286d8e
|
@@ -0,0 +1,95 @@
|
|
1
|
+
name: Build
|
2
|
+
on:
|
3
|
+
push:
|
4
|
+
branches:
|
5
|
+
- main
|
6
|
+
pull_request:
|
7
|
+
branches:
|
8
|
+
- main
|
9
|
+
|
10
|
+
jobs:
|
11
|
+
linux:
|
12
|
+
name: Linux
|
13
|
+
runs-on: ubuntu-latest
|
14
|
+
strategy:
|
15
|
+
matrix:
|
16
|
+
ruby: ['2.5.x', '2.6.x', '2.7.x', '3.0.x']
|
17
|
+
steps:
|
18
|
+
- uses: actions/checkout@v1
|
19
|
+
- name: Cache gems
|
20
|
+
uses: actions/cache@v1
|
21
|
+
with:
|
22
|
+
path: vendor/bundle
|
23
|
+
key: gems-v1-${{ runner.os }}-${{ hashFiles('**/Gemfile') }}-${{ hashFiles('**/*.gemspec') }}-
|
24
|
+
restore-keys: |
|
25
|
+
gems-v1-${{ runner.os }}-${{ hashFiles('**/Gemfile') }}-${{ hashFiles('**/*.gemspec') }}-
|
26
|
+
gems-v1-${{ runner.os }}-${{ hashFiles('**/Gemfile') }}-
|
27
|
+
gems-v1-${{ runner.os }}-
|
28
|
+
- uses: actions/setup-ruby@v1
|
29
|
+
with:
|
30
|
+
ruby-version: ${{ matrix.ruby }}
|
31
|
+
- run: sudo apt-get update; sudo apt-get install cmake xorg-dev libgl1-mesa-dev
|
32
|
+
- run: bash install-glfw.sh
|
33
|
+
- run: gem install bundler
|
34
|
+
- run: bundle install --path vendor/bundle
|
35
|
+
- name: Test & publish code coverage
|
36
|
+
uses: paambaati/codeclimate-action@v2.2.1
|
37
|
+
if: github.event_name == 'push'
|
38
|
+
env:
|
39
|
+
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
|
40
|
+
with:
|
41
|
+
coverageCommand: bundle exec rake test
|
42
|
+
- name: Test
|
43
|
+
if: github.event_name != 'push'
|
44
|
+
run: bundle exec rake test
|
45
|
+
|
46
|
+
macos:
|
47
|
+
name: macOS
|
48
|
+
runs-on: macos-latest
|
49
|
+
strategy:
|
50
|
+
matrix:
|
51
|
+
ruby: ['2.5.x', '2.6.x', '2.7.x', '3.0.x']
|
52
|
+
steps:
|
53
|
+
- uses: actions/checkout@v1
|
54
|
+
- name: Cache gems
|
55
|
+
uses: actions/cache@v1
|
56
|
+
with:
|
57
|
+
path: vendor/bundle
|
58
|
+
key: gems-v1-${{ runner.os }}-${{ hashFiles('**/Gemfile') }}-${{ hashFiles('**/*.gemspec') }}-
|
59
|
+
restore-keys: |
|
60
|
+
gems-v1-${{ runner.os }}-${{ hashFiles('**/Gemfile') }}-${{ hashFiles('**/*.gemspec') }}-
|
61
|
+
gems-v1-${{ runner.os }}-${{ hashFiles('**/Gemfile') }}-
|
62
|
+
gems-v1-${{ runner.os }}-
|
63
|
+
- uses: actions/setup-ruby@v1
|
64
|
+
with:
|
65
|
+
ruby-version: ${{ matrix.ruby }}
|
66
|
+
- run: brew install glfw
|
67
|
+
- run: bundle install --path vendor/bundle
|
68
|
+
- run: bundle exec rake test
|
69
|
+
|
70
|
+
windows:
|
71
|
+
name: Windows
|
72
|
+
runs-on: windows-latest
|
73
|
+
env:
|
74
|
+
MITTSU_LIBGLFW_FILE: c:\projects\mittsu\glfw-3.3.1.bin.WIN32\lib-mingw\glfw3.dll
|
75
|
+
strategy:
|
76
|
+
matrix:
|
77
|
+
ruby: ['2.5.x', '2.6.x', '2.7.x', '3.0.x']
|
78
|
+
steps:
|
79
|
+
- uses: actions/checkout@v1
|
80
|
+
- name: Cache gems
|
81
|
+
uses: actions/cache@v1
|
82
|
+
with:
|
83
|
+
path: vendor/bundle
|
84
|
+
key: gems-v1-${{ runner.os }}-${{ hashFiles('**/Gemfile') }}-${{ hashFiles('**/*.gemspec') }}-
|
85
|
+
restore-keys: |
|
86
|
+
gems-v1-${{ runner.os }}-${{ hashFiles('**/Gemfile') }}-${{ hashFiles('**/*.gemspec') }}-
|
87
|
+
gems-v1-${{ runner.os }}-${{ hashFiles('**/Gemfile') }}-
|
88
|
+
gems-v1-${{ runner.os }}-
|
89
|
+
- uses: actions/setup-ruby@v1
|
90
|
+
with:
|
91
|
+
ruby-version: ${{ matrix.ruby }}
|
92
|
+
- run: .\install-glfw.ps1
|
93
|
+
- run: gem install bundler
|
94
|
+
- run: bundle install --path vendor/bundle
|
95
|
+
- run: bundle exec rake test
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,13 +1,9 @@
|
|
1
1
|
# Mittsu
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/mittsu.svg)](https://badge.fury.io/rb/mittsu)
|
4
|
-
[![
|
5
|
-
[![
|
6
|
-
[![
|
7
|
-
|
8
|
-
🍎 [![Circle CI Build Status (macOS)](https://circleci.com/gh/jellymann/mittsu/tree/master.svg?style=shield)](https://circleci.com/gh/jellymann/mittsu/tree/master)
|
9
|
-
🐧 [![Travis Build Status (Ubuntu)](https://travis-ci.org/jellymann/mittsu.svg?branch=master)](https://travis-ci.org/jellymann/mittsu)
|
10
|
-
🖼 [![AppVeyor Build status (Windows)](https://ci.appveyor.com/api/projects/status/x7k8r95m5f5fg9cu/branch/master?svg=true)](https://ci.appveyor.com/project/jellymann/mittsu/branch/master)
|
4
|
+
[![Test Coverage](https://api.codeclimate.com/v1/badges/22be300984d81fa10af8/test_coverage)](https://codeclimate.com/github/jellymann/mittsu/test_coverage)
|
5
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/22be300984d81fa10af8/maintainability)](https://codeclimate.com/github/jellymann/mittsu/maintainability)
|
6
|
+
[![Build Status](https://github.com/jellymann/mittsu/workflows/Build/badge.svg)](https://github.com/jellymann/mittsu/actions?query=workflow%3A%22Build%22)
|
11
7
|
|
12
8
|
3D Graphics Library for Ruby
|
13
9
|
|
data/Rakefile
CHANGED
data/install-glfw.ps1
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
$glfwversion="3.3.1"
|
2
|
+
|
3
|
+
Invoke-WebRequest "https://github.com/glfw/glfw/releases/download/$glfwversion/glfw-$glfwversion.bin.WIN32.zip" -OutFile "$pwd\glfw-$glfwversion.bin.WIN32.zip"
|
4
|
+
|
5
|
+
Add-Type -AssemblyName System.IO.Compression.FileSystem
|
6
|
+
function Unzip
|
7
|
+
{
|
8
|
+
param([string]$zipfile, [string]$outpath)
|
9
|
+
|
10
|
+
[System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)
|
11
|
+
}
|
12
|
+
|
13
|
+
Unzip "$pwd\glfw-$glfwversion.bin.WIN32.zip" "$pwd"
|
data/lib/mittsu.rb
CHANGED
@@ -1,19 +1,4 @@
|
|
1
|
-
|
2
|
-
DEBUG = ENV["DEBUG"] == "true"
|
3
|
-
|
4
|
-
def self.debug?
|
5
|
-
DEBUG
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.env
|
9
|
-
ENV["MITTSU_ENV"]
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.test?
|
13
|
-
env == 'test'
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
1
|
+
require "mittsu/utils"
|
17
2
|
require "mittsu/version"
|
18
3
|
require "mittsu/math"
|
19
4
|
require "mittsu/core"
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'mittsu'
|
2
|
-
|
3
1
|
module Mittsu
|
4
2
|
class OrthographicCamera < Camera
|
5
3
|
attr_accessor :zoom, :left, :right, :top, :bottom, :near, :far
|
@@ -25,8 +23,8 @@ module Mittsu
|
|
25
23
|
def update_projection_matrix
|
26
24
|
dx = (right - left) / (2.0 * zoom)
|
27
25
|
dy = (top - bottom) / (2.0 * zoom)
|
28
|
-
cx = (right
|
29
|
-
cy = (top
|
26
|
+
cx = (right + left) / 2.0
|
27
|
+
cy = (top + bottom) / 2.0
|
30
28
|
|
31
29
|
projection_matrix.make_orthographic(cx - dx, cx + dx, cy + dy, cy - dy, near, far)
|
32
30
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'mittsu'
|
2
|
-
|
3
1
|
module Mittsu
|
4
2
|
class PerspectiveCamera < Camera
|
5
3
|
attr_accessor :zoom, :fov, :aspect, :near, :far
|
@@ -15,6 +13,7 @@ module Mittsu
|
|
15
13
|
@aspect = aspect.to_f
|
16
14
|
@near = near.to_f
|
17
15
|
@far = far.to_f
|
16
|
+
@full_width = nil
|
18
17
|
|
19
18
|
update_projection_matrix
|
20
19
|
end
|
@@ -23,7 +22,7 @@ module Mittsu
|
|
23
22
|
# 35mm (fullframe) camera is used if frame size is not specified;
|
24
23
|
# Formula based on http://www.bobatkins.com/photography/technical/field_of_view.html
|
25
24
|
def set_lens(focal_length, frame_height = 24.0)
|
26
|
-
@fov = 2.0 * Math.rad_to_deg(Math.atan(frame_height / (focal_length * 2.0)))
|
25
|
+
@fov = 2.0 * Math.rad_to_deg(::Math.atan(frame_height / (focal_length * 2.0)))
|
27
26
|
update_projection_matrix
|
28
27
|
end
|
29
28
|
|
@@ -73,11 +72,11 @@ module Mittsu
|
|
73
72
|
end
|
74
73
|
|
75
74
|
def update_projection_matrix
|
76
|
-
new_fov = Math.rad_to_deg(2.0 * Math.atan(Math.tan(Math.deg_to_rad(@fov) * 0.5) / @zoom))
|
75
|
+
new_fov = Math.rad_to_deg(2.0 * ::Math.atan(::Math.tan(Math.deg_to_rad(@fov) * 0.5) / @zoom))
|
77
76
|
|
78
77
|
if @full_width
|
79
78
|
aspect = @full_width / @full_height
|
80
|
-
top = Math.tan(Math.deg_to_rad(new_fov * 0.5)) * @near
|
79
|
+
top = ::Math.tan(Math.deg_to_rad(new_fov * 0.5)) * @near
|
81
80
|
bottom = -top
|
82
81
|
left = aspect * bottom
|
83
82
|
right = aspect * top
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'securerandom'
|
2
|
-
require 'mittsu'
|
3
2
|
require 'mittsu/core/event_dispatcher'
|
4
3
|
|
5
4
|
module Mittsu
|
@@ -21,6 +20,7 @@ module Mittsu
|
|
21
20
|
@attributes = {}
|
22
21
|
|
23
22
|
@draw_calls = []
|
23
|
+
@_listeners = {}
|
24
24
|
end
|
25
25
|
|
26
26
|
def keys
|
@@ -179,7 +179,7 @@ module Mittsu
|
|
179
179
|
max_radius_sq = [max_radius_sq, center.distance_to_squared(vector)].max
|
180
180
|
end
|
181
181
|
|
182
|
-
@bounding_sphere.radius = Math.sqrt(max_radius_sq)
|
182
|
+
@bounding_sphere.radius = ::Math.sqrt(max_radius_sq)
|
183
183
|
|
184
184
|
if @bounding_radius.nan?
|
185
185
|
puts 'ERROR: Mittsu::BufferGeometry#computeBoundingSphere: Computed radius is NaN. The "position" attribute is likely to have NaN values.'
|
@@ -558,7 +558,7 @@ module Mittsu
|
|
558
558
|
normals.each_slice(3).with_index do |normal, i|
|
559
559
|
x, y, z = *normal
|
560
560
|
|
561
|
-
n = 1.0 / Math.sqrt(x * x + y * y + z * z)
|
561
|
+
n = 1.0 / ::Math.sqrt(x * x + y * y + z * z)
|
562
562
|
|
563
563
|
i *= 3
|
564
564
|
normals[i] *= n
|
data/lib/mittsu/core/geometry.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'securerandom'
|
2
|
-
require 'mittsu'
|
3
2
|
|
4
3
|
module Mittsu
|
5
4
|
class Geometry
|
@@ -19,6 +18,8 @@ module Mittsu
|
|
19
18
|
|
20
19
|
@id = (@@id ||= 1).tap { @@id += 1 }
|
21
20
|
|
21
|
+
@uuid = SecureRandom.uuid
|
22
|
+
|
22
23
|
@name = ''
|
23
24
|
@type = 'Geometry'
|
24
25
|
|
@@ -49,6 +50,8 @@ module Mittsu
|
|
49
50
|
@colors_need_update = false
|
50
51
|
@line_distances_need_update = false
|
51
52
|
@groups_need_update = false
|
53
|
+
|
54
|
+
@_listeners = {}
|
52
55
|
end
|
53
56
|
|
54
57
|
def apply_matrix(matrix)
|
@@ -105,7 +108,7 @@ module Mittsu
|
|
105
108
|
}
|
106
109
|
if indices
|
107
110
|
draw_calls = geometry.draw_calls
|
108
|
-
if !draw_calls.
|
111
|
+
if !draw_calls.empty?
|
109
112
|
draw_calls.each do |draw_call|
|
110
113
|
start = draw_call.start
|
111
114
|
count = draw_call.count
|
@@ -119,7 +122,7 @@ module Mittsu
|
|
119
122
|
end
|
120
123
|
else
|
121
124
|
indices.each_slice(3).with_index do |index|
|
122
|
-
add_face
|
125
|
+
add_face[*index]
|
123
126
|
end
|
124
127
|
end
|
125
128
|
else
|
@@ -130,10 +133,10 @@ module Mittsu
|
|
130
133
|
end
|
131
134
|
end
|
132
135
|
self.compute_face_normals
|
133
|
-
if geometry.
|
136
|
+
if geometry.bounding_box
|
134
137
|
@bounding_box = geometry.bounding_box.clone
|
135
138
|
end
|
136
|
-
if geometry.
|
139
|
+
if geometry.bounding_sphere
|
137
140
|
@bounding_sphere = geometry.bounding_sphere.clone
|
138
141
|
end
|
139
142
|
self
|
@@ -160,12 +163,12 @@ module Mittsu
|
|
160
163
|
end
|
161
164
|
end
|
162
165
|
|
163
|
-
def compute_vertex_normals(
|
166
|
+
def compute_vertex_normals(area_weighted = false)
|
164
167
|
vertices = Array.new(@vertices.length)
|
165
168
|
@vertices.length.times do |v|
|
166
169
|
vertices[v] = Mittsu::Vector3.new
|
167
170
|
end
|
168
|
-
if
|
171
|
+
if area_weighted
|
169
172
|
# vertex normals weighted by triangle areas
|
170
173
|
# http:#www.iquilezles.org/www/articles/normals/normals.htm
|
171
174
|
cb = Mittsu::Vector3.new, ab = Mittsu::Vector3.new
|
@@ -426,12 +429,10 @@ module Mittsu
|
|
426
429
|
face.b = changes[face.b]
|
427
430
|
face.c = changes[face.c]
|
428
431
|
indices = [face.a, face.b, face.c]
|
429
|
-
dup_index = -1
|
430
432
|
# if any duplicate vertices are found in a Face3
|
431
433
|
# we have to remove the face as nothing can be saved
|
432
434
|
3.times do |n|
|
433
435
|
if indices[n] == indices[(n + 1) % 3]
|
434
|
-
dup_index = n
|
435
436
|
face_indices_to_remove << i
|
436
437
|
break
|
437
438
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'securerandom'
|
2
|
-
require 'mittsu'
|
3
2
|
|
4
3
|
module Mittsu
|
5
4
|
class Object3D
|
@@ -22,6 +21,8 @@ module Mittsu
|
|
22
21
|
@type = 'Object3D'
|
23
22
|
|
24
23
|
@children = []
|
24
|
+
@parent = nil
|
25
|
+
@name = nil
|
25
26
|
|
26
27
|
@up = DefaultUp.clone
|
27
28
|
|
@@ -55,6 +56,7 @@ module Mittsu
|
|
55
56
|
@render_order = 0
|
56
57
|
|
57
58
|
@user_data = {}
|
59
|
+
@_listeners = {}
|
58
60
|
end
|
59
61
|
|
60
62
|
def name
|
@@ -95,18 +97,18 @@ module Mittsu
|
|
95
97
|
end
|
96
98
|
|
97
99
|
def rotate_x(angle)
|
98
|
-
@
|
99
|
-
self.rotate_on_axis(@
|
100
|
+
@_x_axis ||= Vector3.new(1, 0, 0)
|
101
|
+
self.rotate_on_axis(@_x_axis, angle)
|
100
102
|
end
|
101
103
|
|
102
104
|
def rotate_y(angle)
|
103
|
-
@
|
104
|
-
self.rotate_on_axis(@
|
105
|
+
@_y_axis ||= Vector3.new(0, 1, 0)
|
106
|
+
self.rotate_on_axis(@_y_axis, angle)
|
105
107
|
end
|
106
108
|
|
107
109
|
def rotate_z(angle)
|
108
|
-
@
|
109
|
-
self.rotate_on_axis(@
|
110
|
+
@_z_axis ||= Vector3.new(0, 0, 1)
|
111
|
+
self.rotate_on_axis(@_z_axis, angle)
|
110
112
|
end
|
111
113
|
|
112
114
|
def translate_on_axis(axis, distance)
|
@@ -1,2 +1,15 @@
|
|
1
1
|
require 'mittsu/extras/geometries/box_geometry'
|
2
2
|
require 'mittsu/extras/geometries/sphere_geometry'
|
3
|
+
require 'mittsu/extras/geometries/ring_geometry'
|
4
|
+
require 'mittsu/extras/geometries/circle_geometry'
|
5
|
+
require 'mittsu/extras/geometries/cylinder_geometry'
|
6
|
+
require 'mittsu/extras/geometries/dodecahedron_geometry'
|
7
|
+
require 'mittsu/extras/geometries/icosahedron_geometry'
|
8
|
+
require 'mittsu/extras/geometries/octahedron_geometry'
|
9
|
+
require 'mittsu/extras/geometries/tetrahedron_geometry'
|
10
|
+
require 'mittsu/extras/geometries/plane_buffer_geometry'
|
11
|
+
require 'mittsu/extras/geometries/plane_geometry'
|
12
|
+
require 'mittsu/extras/geometries/torus_geometry'
|
13
|
+
require 'mittsu/extras/geometries/torus_knot_geometry'
|
14
|
+
require 'mittsu/extras/geometries/parametric_geometry'
|
15
|
+
require 'mittsu/extras/geometries/lathe_geometry'
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'mittsu/core'
|
2
|
+
require 'mittsu/math'
|
3
|
+
|
4
|
+
module Mittsu
|
5
|
+
class CircleGeometry < Geometry
|
6
|
+
def initialize(radius = 50.0, segments = 8, theta_start = 0.0, theta_length = (::Math::PI * 2.0))
|
7
|
+
super()
|
8
|
+
|
9
|
+
@type = 'CircleGeometry'
|
10
|
+
|
11
|
+
@parameters = {
|
12
|
+
radius: radius,
|
13
|
+
segments: segments,
|
14
|
+
theta_start: theta_start,
|
15
|
+
theta_length: theta_length
|
16
|
+
}
|
17
|
+
|
18
|
+
segments = [3, segments].max
|
19
|
+
|
20
|
+
center = Vector3.new
|
21
|
+
center_uv = Vector2.new(0.5, 0.5)
|
22
|
+
|
23
|
+
@vertices << center
|
24
|
+
uvs = [center_uv]
|
25
|
+
|
26
|
+
for i in 0..segments do
|
27
|
+
vertex = Vector3.new
|
28
|
+
segment = theta_start + i.to_f / segments.to_f * theta_length
|
29
|
+
|
30
|
+
vertex.x = radius * ::Math.cos(segment)
|
31
|
+
vertex.y = radius * ::Math.sin(segment)
|
32
|
+
|
33
|
+
@vertices << vertex
|
34
|
+
uvs << Vector2.new((vertex.x / radius + 1.0) / 2.0, (vertex.y / radius + 1.0) / 2.0)
|
35
|
+
end
|
36
|
+
|
37
|
+
n = Vector3.new
|
38
|
+
|
39
|
+
for i in 1..segments do
|
40
|
+
@faces << Face3.new(i, i + 1, 0, [n.clone, n.clone, n.clone])
|
41
|
+
@face_vertex_uvs[0] << [uvs[i].clone, uvs[i + 1].clone, center_uv.clone]
|
42
|
+
end
|
43
|
+
|
44
|
+
compute_face_normals
|
45
|
+
@bounding_sphere = Sphere.new(Vector3.new, radius)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|