mittsu 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build-workflow.yml +71 -0
  3. data/.gitignore +1 -0
  4. data/Gemfile +0 -3
  5. data/LICENSE.txt +1 -1
  6. data/README.md +6 -8
  7. data/Rakefile +1 -0
  8. data/install-glfw.ps1 +13 -0
  9. data/lib/mittsu/cameras/camera.rb +0 -2
  10. data/lib/mittsu/cameras/cube_camera.rb +0 -2
  11. data/lib/mittsu/cameras/orthographic_camera.rb +2 -4
  12. data/lib/mittsu/cameras/perspective_camera.rb +4 -5
  13. data/lib/mittsu/core/buffer_attribute.rb +12 -0
  14. data/lib/mittsu/core/buffer_geometry.rb +3 -3
  15. data/lib/mittsu/core/geometry.rb +2 -4
  16. data/lib/mittsu/core/object_3d.rb +9 -7
  17. data/lib/mittsu/core/raycaster.rb +0 -2
  18. data/lib/mittsu/extras/geometries/circle_geometry.rb +3 -3
  19. data/lib/mittsu/extras/geometries/cylinder_geometry.rb +5 -5
  20. data/lib/mittsu/extras/geometries/dodecahedron_geometry.rb +2 -2
  21. data/lib/mittsu/extras/geometries/icosahedron_geometry.rb +2 -2
  22. data/lib/mittsu/extras/geometries/lathe_geometry.rb +3 -3
  23. data/lib/mittsu/extras/geometries/parametric_geometry.rb +19 -19
  24. data/lib/mittsu/extras/geometries/polyhedron_geometry.rb +6 -7
  25. data/lib/mittsu/extras/geometries/ring_geometry.rb +4 -4
  26. data/lib/mittsu/extras/geometries/sphere_geometry.rb +4 -4
  27. data/lib/mittsu/extras/geometries/torus_geometry.rb +7 -7
  28. data/lib/mittsu/extras/geometries/torus_knot_buffer_geometry.rb +9 -9
  29. data/lib/mittsu/extras/helpers/camera_helper.rb +38 -38
  30. data/lib/mittsu/extras/image_utils.rb +1 -1
  31. data/lib/mittsu/lights/directional_light.rb +9 -5
  32. data/lib/mittsu/lights/spot_light.rb +1 -1
  33. data/lib/mittsu/loaders/loader.rb +2 -2
  34. data/lib/mittsu/loaders/obj_loader.rb +4 -0
  35. data/lib/mittsu/materials/material.rb +6 -3
  36. data/lib/mittsu/math/box2.rb +0 -2
  37. data/lib/mittsu/math/box3.rb +0 -2
  38. data/lib/mittsu/math/color.rb +3 -4
  39. data/lib/mittsu/math/euler.rb +25 -26
  40. data/lib/mittsu/math/frustum.rb +0 -2
  41. data/lib/mittsu/math/line3.rb +0 -2
  42. data/lib/mittsu/math/matrix3.rb +0 -2
  43. data/lib/mittsu/math/matrix4.rb +10 -12
  44. data/lib/mittsu/math/plane.rb +0 -2
  45. data/lib/mittsu/math/quaternion.rb +18 -20
  46. data/lib/mittsu/math/ray.rb +1 -3
  47. data/lib/mittsu/math/sphere.rb +1 -3
  48. data/lib/mittsu/math/spline.rb +0 -2
  49. data/lib/mittsu/math/triangle.rb +1 -3
  50. data/lib/mittsu/math/vector.rb +3 -3
  51. data/lib/mittsu/math/vector2.rb +0 -1
  52. data/lib/mittsu/math/vector3.rb +108 -1
  53. data/lib/mittsu/math/vector4.rb +8 -9
  54. data/lib/mittsu/math.rb +0 -5
  55. data/lib/mittsu/objects/line.rb +0 -1
  56. data/lib/mittsu/renderers/glfw_lib.rb +24 -3
  57. data/lib/mittsu/renderers/glfw_window.rb +6 -2
  58. data/lib/mittsu/renderers/opengl/core/object_3d.rb +1 -1
  59. data/lib/mittsu/renderers/opengl/lights/spot_light.rb +1 -1
  60. data/lib/mittsu/renderers/opengl/opengl_geometry_group.rb +1 -0
  61. data/lib/mittsu/renderers/opengl/opengl_program.rb +1 -2
  62. data/lib/mittsu/renderers/opengl/textures/texture.rb +2 -2
  63. data/lib/mittsu/renderers/opengl_renderer.rb +9 -14
  64. data/lib/mittsu/scenes/scene.rb +0 -2
  65. data/lib/mittsu/textures/texture.rb +4 -2
  66. data/lib/mittsu/utils.rb +15 -0
  67. data/lib/mittsu/version.rb +1 -2
  68. data/lib/mittsu.rb +1 -16
  69. data/mittsu.gemspec +14 -13
  70. metadata +60 -47
  71. data/.circleci/config.yml +0 -87
  72. data/.circleci/images/primary/Dockerfile +0 -10
  73. data/appveyor.yml +0 -23
  74. data/install_glfw.ps1 +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ea48bdfaa8b34b8c6d166802481b25ae996b723c8154f582e15aa84309235a9d
4
- data.tar.gz: b46f1cdbbb0f1c5f0e0cd59c9b07eddc003e3ae00f4e87a0600bc8d846778256
3
+ metadata.gz: e3a8c66b2c63737be22e4495e20bc62888391dc63907e604d31eb8cbbf5fa432
4
+ data.tar.gz: f88e54369ac3e9c2b0534135f485310469d5dd37889504cf049eb23223cf0f2a
5
5
  SHA512:
6
- metadata.gz: 2fd7361fe37318f8ebe6c3ae1e079af6591a857a93693313fcfdfbae98f3b1e505252f828f37bd3badf9d9e4f19577bb186bd24482a3820f986706af939da2e5
7
- data.tar.gz: 8b961390454531b18fe57484411e43f78862bf410012e06b6983d42f6976bfa62d3239070884e33643db0c90186ef30dab92f6e189713e9ffe25ad38876f47ec
6
+ metadata.gz: ea2ee4ab085e40061f432ed835f8f40948557467f85f33b7b4238a2d18cc4756ac43bb052d6631e4d8707f62d1ebce382cf5790727c28b257b73f71a08446458
7
+ data.tar.gz: fb77a518a9002b201a52590be84e13b9b57c1716b2e13d5c38b0d81265c6c26d8e440fb700d92e3759f8bfbd5323435c28dd780497da133fba4a09023800b3fd
@@ -0,0 +1,71 @@
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.6', '2.7', '3.0', '3.1', 'head']
17
+ steps:
18
+ - uses: actions/checkout@v1
19
+ - uses: ruby/setup-ruby@v1
20
+ with:
21
+ ruby-version: ${{ matrix.ruby }}
22
+ bundler-cache: true
23
+ - run: sudo apt-get update; sudo apt-get install cmake xorg-dev libgl1-mesa-dev
24
+ - run: bash install-glfw.sh
25
+ - run: gem install bundler
26
+ - run: bundle install --path vendor/bundle
27
+ - name: Test & publish code coverage
28
+ uses: paambaati/codeclimate-action@v2.2.1
29
+ if: github.event_name == 'push'
30
+ env:
31
+ CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
32
+ with:
33
+ coverageCommand: bundle exec rake test
34
+ - name: Test
35
+ if: github.event_name != 'push'
36
+ run: bundle exec rake test
37
+
38
+ macos:
39
+ name: macOS
40
+ runs-on: macos-latest
41
+ strategy:
42
+ matrix:
43
+ ruby: ['2.6', '2.7', '3.0', '3.1', 'head']
44
+ steps:
45
+ - uses: actions/checkout@v1
46
+ - uses: ruby/setup-ruby@v1
47
+ with:
48
+ ruby-version: ${{ matrix.ruby }}
49
+ bundler-cache: true
50
+ - run: brew install glfw
51
+ - run: bundle install --path vendor/bundle
52
+ - run: bundle exec rake test
53
+
54
+ windows:
55
+ name: Windows
56
+ runs-on: windows-latest
57
+ env:
58
+ MITTSU_LIBGLFW_PATH: c:\projects\mittsu\glfw-3.3.1.bin.WIN32\lib-mingw
59
+ strategy:
60
+ matrix:
61
+ ruby: ['2.6', '2.7', '3.0', '3.1', 'head']
62
+ steps:
63
+ - uses: actions/checkout@v1
64
+ - uses: ruby/setup-ruby@v1
65
+ with:
66
+ ruby-version: ${{ matrix.ruby }}
67
+ bundler-cache: true
68
+ - run: .\install-glfw.ps1
69
+ - run: gem install bundler
70
+ - run: bundle install --path vendor/bundle
71
+ - run: bundle exec rake test
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
  /tmp/
10
10
  /test/reports
11
11
  *.gem
12
+ .tool-versions
data/Gemfile CHANGED
@@ -2,9 +2,6 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- gem "codeclimate-test-reporter", group: :test, require: false
6
- gem 'coveralls', group: :test, require: false
7
-
8
5
  if /darwin/ === RUBY_PLATFORM
9
6
  gem 'ffi', '~> 1.9', '!= 1.11.1'
10
7
  end
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2016 Daniel Smith
3
+ Copyright (c) 2015-2022 Danielle Smith
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,12 +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
- [![Coverage Status](https://coveralls.io/repos/github/jellymann/mittsu/badge.svg?branch=master)](https://coveralls.io/github/jellymann/mittsu?branch=master)
5
- [![Code Climate](https://codeclimate.com/github/jellymann/mittsu/badges/gpa.svg)](https://codeclimate.com/github/jellymann/mittsu)
6
-
7
- 🍎 [![Circle CI Build Status (macOS)](https://circleci.com/gh/jellymann/mittsu/tree/master.svg?style=shield)](https://circleci.com/gh/jellymann/mittsu/tree/master)
8
-   🐧 [![Travis Build Status (Ubuntu)](https://travis-ci.org/jellymann/mittsu.svg?branch=master)](https://travis-ci.org/jellymann/mittsu)
9
-   🖼 [![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/danini-the-panini/mittsu/test_coverage)
5
+ [![Maintainability](https://api.codeclimate.com/v1/badges/22be300984d81fa10af8/maintainability)](https://codeclimate.com/github/danini-the-panini/mittsu/maintainability)
6
+ [![Build Status](https://github.com/danini-the-panini/mittsu/workflows/Build/badge.svg)](https://github.com/danini-the-panini/mittsu/actions?query=workflow%3A%22Build%22)
10
7
 
11
8
  3D Graphics Library for Ruby
12
9
 
@@ -18,7 +15,7 @@ Mittsu makes 3D graphics easier by providing an abstraction over OpenGL, and is
18
15
  ![Point Light](https://cloud.githubusercontent.com/assets/1171825/18411861/4531bb4c-7781-11e6-92b4-b6ebda60e2c9.gif)
19
16
  ![Tank Demo](https://cloud.githubusercontent.com/assets/1171825/18411862/4531fe9a-7781-11e6-9665-b172df1a3645.gif)
20
17
 
21
- (You can find the source for the Tank Demo [here](https://github.com/jellymann/mittsu-tank-demo))
18
+ (You can find the source for the Tank Demo [here](https://github.com/danini-the-panini/mittsu-tank-demo))
22
19
 
23
20
  ## Installation
24
21
 
@@ -37,6 +34,7 @@ $ sudo apt-get install libglfw3
37
34
  **NOTE:** On Windows, you will have to manually specify the glfw3.dll path in an environment variable
38
35
  (you can download it [here](http://www.glfw.org/download.html))
39
36
  ```bash
37
+ # ex) set MITTSU_LIBGLFW_PATH=C:\Users\username\lib-mingw-w64
40
38
  > set MITTSU_LIBGLFW_PATH=C:\path\to\glfw3.dll
41
39
  > ruby your_awesome_mittsu_app.rb
42
40
  ```
@@ -215,7 +213,7 @@ If you just want to see what Mittsu can do and how to do it, take a peek inside
215
213
 
216
214
  ## Contributing
217
215
 
218
- 1. Fork it ( https://github.com/jellymann/mittsu/fork )
216
+ 1. Fork it ( https://github.com/danini-the-panini/mittsu/fork )
219
217
  2. Create your feature branch (`git checkout -b my-new-feature`)
220
218
  3. Commit your changes (`git commit -am 'Add some feature'`)
221
219
  4. Push to the branch (`git push origin my-new-feature`)
data/Rakefile CHANGED
@@ -4,4 +4,5 @@ require 'rake/testtask'
4
4
  Rake::TestTask.new do |t|
5
5
  t.libs << "test"
6
6
  t.pattern = "test/**/test_*.rb"
7
+ t.warning = false
7
8
  end
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"
@@ -1,5 +1,3 @@
1
- require 'mittsu'
2
-
3
1
  module Mittsu
4
2
  class Camera < Object3D
5
3
  attr_accessor :projection_matrix, :matrix_world_inverse
@@ -1,5 +1,3 @@
1
- require 'mittsu'
2
-
3
1
  module Mittsu
4
2
  class CubeCamera < Object3D
5
3
  attr_accessor :render_target
@@ -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 - left) / 2.0
29
- cy = (top - bottom) / 2.0
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
@@ -50,6 +50,18 @@ module Mittsu
50
50
  self
51
51
  end
52
52
 
53
+ def get_x(index)
54
+ @array[index * @item_size]
55
+ end
56
+
57
+ def get_y(index)
58
+ @array[index * @item_size + 1]
59
+ end
60
+
61
+ def get_z(index)
62
+ @array[index * @item_size + 2]
63
+ end
64
+
53
65
  def set_xy(index, x, y)
54
66
  index *= @item_size
55
67
 
@@ -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
@@ -1,6 +1,4 @@
1
1
  require 'securerandom'
2
- require 'mittsu'
3
- require 'securerandom'
4
2
 
5
3
  module Mittsu
6
4
  class Geometry
@@ -52,6 +50,8 @@ module Mittsu
52
50
  @colors_need_update = false
53
51
  @line_distances_need_update = false
54
52
  @groups_need_update = false
53
+
54
+ @_listeners = {}
55
55
  end
56
56
 
57
57
  def apply_matrix(matrix)
@@ -429,12 +429,10 @@ module Mittsu
429
429
  face.b = changes[face.b]
430
430
  face.c = changes[face.c]
431
431
  indices = [face.a, face.b, face.c]
432
- dup_index = -1
433
432
  # if any duplicate vertices are found in a Face3
434
433
  # we have to remove the face as nothing can be saved
435
434
  3.times do |n|
436
435
  if indices[n] == indices[(n + 1) % 3]
437
- dup_index = n
438
436
  face_indices_to_remove << i
439
437
  break
440
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
- @_v1 ||= Vector3.new(1, 0, 0)
99
- self.rotate_on_axis(@_v1, angle)
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
- @_v1 ||= Vector3.new(0, 1, 0)
104
- self.rotate_on_axis(@_v1, angle)
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
- @_v1 ||= Vector3.new(0, 0, 1)
109
- self.rotate_on_axis(@_v1, angle)
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,5 +1,3 @@
1
- require 'mittsu'
2
-
3
1
  module Mittsu
4
2
  class Raycaster
5
3
  attr_accessor :near, :far, :ray, :params, :precision
@@ -3,7 +3,7 @@ require 'mittsu/math'
3
3
 
4
4
  module Mittsu
5
5
  class CircleGeometry < Geometry
6
- def initialize(radius = 50.0, segments = 8, theta_start = 0.0, theta_length = (Math::PI * 2.0))
6
+ def initialize(radius = 50.0, segments = 8, theta_start = 0.0, theta_length = (::Math::PI * 2.0))
7
7
  super()
8
8
 
9
9
  @type = 'CircleGeometry'
@@ -27,8 +27,8 @@ module Mittsu
27
27
  vertex = Vector3.new
28
28
  segment = theta_start + i.to_f / segments.to_f * theta_length
29
29
 
30
- vertex.x = radius * Math.cos(segment)
31
- vertex.y = radius * Math.sin(segment)
30
+ vertex.x = radius * ::Math.cos(segment)
31
+ vertex.y = radius * ::Math.sin(segment)
32
32
 
33
33
  @vertices << vertex
34
34
  uvs << Vector2.new((vertex.x / radius + 1.0) / 2.0, (vertex.y / radius + 1.0) / 2.0)
@@ -3,7 +3,7 @@ require 'mittsu/math'
3
3
 
4
4
  module Mittsu
5
5
  class CylinderGeometry < Geometry
6
- def initialize(radius_top = 20.0, radius_bottom = 20.0, height = 100.0, radial_segments = 8, height_segments = 1, open_ended = false, theta_start = 0.0, theta_length = (Math::PI * 2.0))
6
+ def initialize(radius_top = 20.0, radius_bottom = 20.0, height = 100.0, radial_segments = 8, height_segments = 1, open_ended = false, theta_start = 0.0, theta_length = (::Math::PI * 2.0))
7
7
  super()
8
8
 
9
9
  @type = 'CylinderGeometry'
@@ -35,9 +35,9 @@ module Mittsu
35
35
  u = x.to_f / radial_segments
36
36
 
37
37
  vertex = Vector3.new
38
- vertex.x = radius * Math.sin(u * theta_length + theta_start)
38
+ vertex.x = radius * ::Math.sin(u * theta_length + theta_start)
39
39
  vertex.y = -v * height + height_half
40
- vertex.z = radius * Math.cos(u * theta_length + theta_start)
40
+ vertex.z = radius * ::Math.cos(u * theta_length + theta_start)
41
41
 
42
42
  @vertices << vertex
43
43
 
@@ -63,10 +63,10 @@ module Mittsu
63
63
  nb = @vertices[index_rows[1][x + 1]].clone
64
64
  end
65
65
 
66
- na.y = Math.sqrt(na.x * na.x + na.z * na.z) * tan_theta
66
+ na.y = ::Math.sqrt(na.x * na.x + na.z * na.z) * tan_theta
67
67
  na.normalize
68
68
 
69
- nb.y = Math.sqrt(nb.x * nb.x + nb.z * nb.z) * tan_theta
69
+ nb.y = ::Math.sqrt(nb.x * nb.x + nb.z * nb.z) * tan_theta
70
70
  nb.normalize
71
71
 
72
72
  for y in 0...height_segments do
@@ -5,7 +5,7 @@ require 'mittsu/extras/geometries/polyhedron_geometry'
5
5
  module Mittsu
6
6
  class DodecahedronGeometry < PolyhedronGeometry
7
7
  def initialize(radius = 1.0, detail = 0)
8
- t = (1.0 + Math.sqrt(5.0)) / 2.0
8
+ t = (1.0 + ::Math.sqrt(5.0)) / 2.0
9
9
  r = 1.0 / t
10
10
 
11
11
  vertices = [
@@ -53,4 +53,4 @@ module Mittsu
53
53
  }
54
54
  end
55
55
  end
56
- end
56
+ end
@@ -5,7 +5,7 @@ require 'mittsu/extras/geometries/polyhedron_geometry'
5
5
  module Mittsu
6
6
  class IcosahedronGeometry < PolyhedronGeometry
7
7
  def initialize(radius = 1.0, detail = 0)
8
- t = (1.0 + Math.sqrt(5)) / 2.0
8
+ t = (1.0 + ::Math.sqrt(5)) / 2.0
9
9
 
10
10
  vertices = [
11
11
  - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
@@ -30,4 +30,4 @@ module Mittsu
30
30
  }
31
31
  end
32
32
  end
33
- end
33
+ end
@@ -3,7 +3,7 @@ require 'mittsu/math'
3
3
 
4
4
  module Mittsu
5
5
  class LatheGeometry < Geometry
6
- def initialize(points, segments = 12, phi_start = 0.0, phi_length = (Math::PI * 2.0))
6
+ def initialize(points, segments = 12, phi_start = 0.0, phi_length = (::Math::PI * 2.0))
7
7
  super()
8
8
 
9
9
  @type = 'LatheGeometry'
@@ -21,8 +21,8 @@ module Mittsu
21
21
  for i in 0..segments do
22
22
  phi = phi_start + i.to_f * inverse_segments * phi_length
23
23
 
24
- c = Math.cos(phi)
25
- s = Math.sin(phi)
24
+ c = ::Math.cos(phi)
25
+ s = ::Math.sin(phi)
26
26
 
27
27
  for j in 0...points.length do
28
28
  pt = points[j]
@@ -19,23 +19,23 @@ module Mittsu
19
19
 
20
20
  def self.klein
21
21
  -> (v, u, target = Vector3.new) {
22
- u *= Math::PI
23
- v *= 2.0 * Math::PI
22
+ u *= ::Math::PI
23
+ v *= 2.0 * ::Math::PI
24
24
 
25
25
  u = u * 2.0
26
26
  x = nil
27
27
  y = nil
28
28
  z = nil
29
29
 
30
- if u < Math::PI
31
- x = 3.0 * Math.cos(u) * (1.0 + Math.sin(u)) + (2.0 * (1.0 - Math.cos(u) / 2.0)) * Math.cos(u) * Math.cos(v)
32
- z = -8.0 * Math.sin(u) - 2.0 * (1.0 - Math.cos(u) / 2.0) * Math.sin(u) * Math.cos(v)
30
+ if u < ::Math::PI
31
+ x = 3.0 * ::Math.cos(u) * (1.0 + ::Math.sin(u)) + (2.0 * (1.0 - ::Math.cos(u) / 2.0)) * ::Math.cos(u) * ::Math.cos(v)
32
+ z = -8.0 * ::Math.sin(u) - 2.0 * (1.0 - ::Math.cos(u) / 2.0) * ::Math.sin(u) * ::Math.cos(v)
33
33
  else
34
- x = 3.0 * Math.cos(u) * (1.0 + Math.sin(u)) + (2.0 * (1.0 - Math.cos(u) / 2.0)) * Math.cos(v + Math::PI)
35
- z = -8.0 * Math.sin(u)
34
+ x = 3.0 * ::Math.cos(u) * (1.0 + ::Math.sin(u)) + (2.0 * (1.0 - ::Math.cos(u) / 2.0)) * ::Math.cos(v + ::Math::PI)
35
+ z = -8.0 * ::Math.sin(u)
36
36
  end
37
37
 
38
- y = -2.0 * (1.0 - Math.cos(u) / 2.0) * Math.sin(v)
38
+ y = -2.0 * (1.0 - ::Math.cos(u) / 2.0) * ::Math.sin(v)
39
39
 
40
40
  target.set(x, y, z)
41
41
  }
@@ -56,13 +56,13 @@ module Mittsu
56
56
  # flat mobius strip
57
57
  # http://www.wolframalpha.com/input/?i=M%C3%B6bius+strip+parametric+equations&lk=1&a=ClashPrefs_*Surface.MoebiusStrip.SurfaceProperty.ParametricEquations-
58
58
  u = u - 0.5
59
- v = 2.0 * Math::PI * t
59
+ v = 2.0 * ::Math::PI * t
60
60
 
61
61
  a = 2.0
62
62
 
63
- x = Math.cos(v) * (a + u * Math.cos(v / 2.0))
64
- y = Math.sin(v) * (a + u * Math.cos(v / 2.0))
65
- z = u * Math.sin(v / 2)
63
+ x = ::Math.cos(v) * (a + u * ::Math.cos(v / 2.0))
64
+ y = ::Math.sin(v) * (a + u * ::Math.cos(v / 2.0))
65
+ z = u * ::Math.sin(v / 2)
66
66
 
67
67
  target.set(x, y, z)
68
68
  }
@@ -72,8 +72,8 @@ module Mittsu
72
72
  -> (u, t, target = Vector3.new) {
73
73
  # volumetric mobius strip
74
74
 
75
- u *= Math::PI
76
- t *= 2.0 * Math::PI
75
+ u *= ::Math::PI
76
+ t *= 2.0 * ::Math::PI
77
77
 
78
78
  u = u * 2.0
79
79
  phi = u / 2.0
@@ -81,13 +81,13 @@ module Mittsu
81
81
  a = 0.125
82
82
  b = 0.65
83
83
 
84
- x = a * Math.cos(t) * Math.cos(phi) - b * Math.sin(t) * Math.sin(phi)
85
- z = a * Math.cos(t) * Math.sin(phi) + b * Math.sin(t) * Math.cos(phi)
86
- y = (major + x) * Math.sin(u)
87
- x = (major + x) * Math.cos(u)
84
+ x = a * ::Math.cos(t) * ::Math.cos(phi) - b * ::Math.sin(t) * ::Math.sin(phi)
85
+ z = a * ::Math.cos(t) * ::Math.sin(phi) + b * ::Math.sin(t) * ::Math.cos(phi)
86
+ y = (major + x) * ::Math.sin(u)
87
+ x = (major + x) * ::Math.cos(u)
88
88
 
89
89
  target.set(x, y, z)
90
90
  }
91
91
  end
92
92
  end
93
- end
93
+ end
@@ -27,7 +27,6 @@ module Mittsu
27
27
  v1 = @vertices[indices[i]]
28
28
  v2 = @vertices[indices[i + 1]]
29
29
  v3 = @vertices[indices[i + 2]]
30
- binding.irb if v1.nil? || v2.nil? || v3.nil?
31
30
 
32
31
  faces[j] = Face3.new(v1.index, v2.index, v3.index, [v1.clone, v2.clone, v3.clone])
33
32
 
@@ -78,8 +77,8 @@ module Mittsu
78
77
  vertex.index = @vertices.push(vertex).length - 1
79
78
 
80
79
  # Texture coords are equivalent to map coords, calculate angle and convert to fraction of a circle.
81
- u = azimuth(vector) / 2.0 / Math::PI + 0.5
82
- v = inclination(vector) / Math::PI + 0.5
80
+ u = azimuth(vector) / 2.0 / ::Math::PI + 0.5
81
+ v = inclination(vector) / ::Math::PI + 0.5
83
82
  vertex.uv = Vector2.new(u, 1.0 - v)
84
83
 
85
84
  vertex
@@ -150,19 +149,19 @@ module Mittsu
150
149
 
151
150
  # Angle around the Y axis, counter-clockwise when looking from above.
152
151
  def azimuth(vector)
153
- Math.atan2(vector.z, -vector.x)
152
+ ::Math.atan2(vector.z, -vector.x)
154
153
  end
155
154
 
156
155
  # Angle above the XZ plane.
157
156
  def inclination(vector)
158
- Math.atan2(-vector.y, Math.sqrt(vector.x * vector.x + vector.z * vector.z))
157
+ ::Math.atan2(-vector.y, ::Math.sqrt(vector.x * vector.x + vector.z * vector.z))
159
158
  end
160
159
 
161
160
  # Texture fixing helper. Spheres have some odd behaviours.
162
161
  def correct_uv(uv, vector, azimuth)
163
162
  return Vector2.new(uv.x - 1.0, uv.y) if azimuth < 0
164
- return Vector2.new(azimuth / 2.0 / Math::PI + 0.5, uv.y) if vector.x.zero? && vector.z.zero?
163
+ return Vector2.new(azimuth / 2.0 / ::Math::PI + 0.5, uv.y) if vector.x.zero? && vector.z.zero?
165
164
  uv.clone
166
165
  end
167
166
  end
168
- end
167
+ end
@@ -3,7 +3,7 @@ require 'mittsu/math'
3
3
 
4
4
  module Mittsu
5
5
  class RingGeometry < Geometry
6
- def initialize(inner_radius = 0.0, outer_radius = 50.0, theta_segments = 8, phi_segments = 8, theta_start = 0.0, theta_length = (Math::PI * 2.0))
6
+ def initialize(inner_radius = 0.0, outer_radius = 50.0, theta_segments = 8, phi_segments = 8, theta_start = 0.0, theta_length = (::Math::PI * 2.0))
7
7
  super()
8
8
 
9
9
  @type = 'RingGeometry'
@@ -28,8 +28,8 @@ module Mittsu
28
28
  for o in 0..theta_segments do # number of segments per circle
29
29
  vertex = Vector3.new
30
30
  segment = theta_start + o.to_f / theta_segments.to_f * theta_length
31
- vertex.x = radius * Math.cos(segment)
32
- vertex.y = radius * Math.sin(segment)
31
+ vertex.x = radius * ::Math.cos(segment)
32
+ vertex.y = radius * ::Math.sin(segment)
33
33
 
34
34
  @vertices << vertex
35
35
  uvs << Vector2.new((vertex.x / outer_radius + 1.0) / 2.0, (vertex.y / outer_radius + 1.0) / 2.0)
@@ -77,4 +77,4 @@ module Mittsu
77
77
  )
78
78
  end
79
79
  end
80
- end
80
+ end
@@ -3,7 +3,7 @@ require 'mittsu/math'
3
3
 
4
4
  module Mittsu
5
5
  class SphereGeometry < Geometry
6
- def initialize(radius = 50.0, width_segments = 8, height_segments = 6, phi_start = 0.0, phi_length = (Math::PI * 2.0), theta_start = 0.0, theta_length = Math::PI)
6
+ def initialize(radius = 50.0, width_segments = 8, height_segments = 6, phi_start = 0.0, phi_length = (::Math::PI * 2.0), theta_start = 0.0, theta_length = ::Math::PI)
7
7
  super()
8
8
 
9
9
  @type = 'SphereGeometry'
@@ -33,9 +33,9 @@ module Mittsu
33
33
  v = y / height_segments.to_f
34
34
 
35
35
  vertex = Vector3.new
36
- vertex.x = -radius * Math.cos(phi_start + u * phi_length) * Math.sin(theta_start + v * theta_length)
37
- vertex.y = radius * Math.cos(theta_start + v * theta_length)
38
- vertex.z = radius * Math.sin(phi_start + u * phi_length) * Math.sin(theta_start + v * theta_length)
36
+ vertex.x = -radius * ::Math.cos(phi_start + u * phi_length) * ::Math.sin(theta_start + v * theta_length)
37
+ vertex.y = radius * ::Math.cos(theta_start + v * theta_length)
38
+ vertex.z = radius * ::Math.sin(phi_start + u * phi_length) * ::Math.sin(theta_start + v * theta_length)
39
39
 
40
40
  @vertices << vertex
41
41