mittsu 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (203) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.travis.yml +3 -0
  4. data/CODE_OF_CONDUCT.md +13 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +39 -0
  8. data/Rakefile +7 -0
  9. data/bin/console +14 -0
  10. data/bin/setup +7 -0
  11. data/examples/01_-_Default1noCulling.png +0 -0
  12. data/examples/01_scene_example.rb +14 -0
  13. data/examples/02_box_mesh_example.rb +30 -0
  14. data/examples/02_sphere_mesh_example.rb +30 -0
  15. data/examples/03_complex_object_example.rb +52 -0
  16. data/examples/04_ambient_light_example.rb +33 -0
  17. data/examples/04_dir_light_example.rb +36 -0
  18. data/examples/04_hemi_light_example.rb +30 -0
  19. data/examples/04_point_light_example.rb +50 -0
  20. data/examples/04_spot_light_example.rb +44 -0
  21. data/examples/05_earth_example.rb +42 -0
  22. data/examples/05_earth_moon_example.rb +46 -0
  23. data/examples/05_texture_example.rb +32 -0
  24. data/examples/06_cube_texture_example.rb +36 -0
  25. data/examples/06_skybox_example.rb +60 -0
  26. data/examples/07_earth_normal_example.rb +36 -0
  27. data/examples/08_shadow_example.rb +87 -0
  28. data/examples/09_line_example.rb +52 -0
  29. data/examples/10_obj_loader_example.rb +68 -0
  30. data/examples/11_character_input_example.rb +18 -0
  31. data/examples/11_continuous_keyboard_input_example.rb +35 -0
  32. data/examples/11_keyboard_input_example.rb +43 -0
  33. data/examples/12_mouse_click_example.rb +38 -0
  34. data/examples/12_mouse_motion_example.rb +35 -0
  35. data/examples/12_mouse_scroll_example.rb +36 -0
  36. data/examples/12_orbit_zoom_example.rb +68 -0
  37. data/examples/13_joystick_example.rb +80 -0
  38. data/examples/cubemap/tron_bk.png +0 -0
  39. data/examples/cubemap/tron_dn.png +0 -0
  40. data/examples/cubemap/tron_ft.png +0 -0
  41. data/examples/cubemap/tron_lf.png +0 -0
  42. data/examples/cubemap/tron_rt.png +0 -0
  43. data/examples/cubemap/tron_up.png +0 -0
  44. data/examples/earth.png +0 -0
  45. data/examples/earth_normal.png +0 -0
  46. data/examples/example_helper.rb +2 -0
  47. data/examples/male-02-1noCulling.png +0 -0
  48. data/examples/male02.mtl +54 -0
  49. data/examples/male02.obj +13888 -0
  50. data/examples/moon.png +0 -0
  51. data/examples/orig_02_-_Defaul1noCulling.png +0 -0
  52. data/examples/texture.png +0 -0
  53. data/lib/mittsu.rb +15 -0
  54. data/lib/mittsu/cameras.rb +4 -0
  55. data/lib/mittsu/cameras/camera.rb +34 -0
  56. data/lib/mittsu/cameras/cube_camera.rb +74 -0
  57. data/lib/mittsu/cameras/orthographic_camera.rb +53 -0
  58. data/lib/mittsu/cameras/perspective_camera.rb +115 -0
  59. data/lib/mittsu/constants.rb +160 -0
  60. data/lib/mittsu/core.rb +10 -0
  61. data/lib/mittsu/core/buffer_attribute.rb +87 -0
  62. data/lib/mittsu/core/buffer_geometry.rb +694 -0
  63. data/lib/mittsu/core/clock.rb +44 -0
  64. data/lib/mittsu/core/dynamic_buffer_attribute.rb +16 -0
  65. data/lib/mittsu/core/event_dispatcher.rb +39 -0
  66. data/lib/mittsu/core/face3.rb +30 -0
  67. data/lib/mittsu/core/geometry.rb +596 -0
  68. data/lib/mittsu/core/hash_array.rb +36 -0
  69. data/lib/mittsu/core/hash_object.rb +19 -0
  70. data/lib/mittsu/core/object_3d.rb +421 -0
  71. data/lib/mittsu/core/raycaster.rb +78 -0
  72. data/lib/mittsu/extras.rb +3 -0
  73. data/lib/mittsu/extras/geometries.rb +2 -0
  74. data/lib/mittsu/extras/geometries/box_geometry.rb +108 -0
  75. data/lib/mittsu/extras/geometries/sphere_geometry.rb +88 -0
  76. data/lib/mittsu/extras/helpers.rb +1 -0
  77. data/lib/mittsu/extras/helpers/camera_helper.rb +155 -0
  78. data/lib/mittsu/extras/image.rb +3 -0
  79. data/lib/mittsu/extras/image_utils.rb +80 -0
  80. data/lib/mittsu/lights.rb +7 -0
  81. data/lib/mittsu/lights/ambient_light.rb +16 -0
  82. data/lib/mittsu/lights/area_light.rb +24 -0
  83. data/lib/mittsu/lights/directional_light.rb +131 -0
  84. data/lib/mittsu/lights/hemisphere_light.rb +29 -0
  85. data/lib/mittsu/lights/light.rb +21 -0
  86. data/lib/mittsu/lights/point_light.rb +27 -0
  87. data/lib/mittsu/lights/spot_light.rb +104 -0
  88. data/lib/mittsu/loaders.rb +7 -0
  89. data/lib/mittsu/loaders/cache.rb +53 -0
  90. data/lib/mittsu/loaders/file_loader.rb +22 -0
  91. data/lib/mittsu/loaders/image_loader.rb +32 -0
  92. data/lib/mittsu/loaders/loader.rb +212 -0
  93. data/lib/mittsu/loaders/loading_manager.rb +17 -0
  94. data/lib/mittsu/loaders/mtl_loader.rb +242 -0
  95. data/lib/mittsu/loaders/obj_mtl_loader.rb +225 -0
  96. data/lib/mittsu/materials.rb +7 -0
  97. data/lib/mittsu/materials/line_basic_material.rb +39 -0
  98. data/lib/mittsu/materials/material.rb +156 -0
  99. data/lib/mittsu/materials/mesh_basic_material.rb +122 -0
  100. data/lib/mittsu/materials/mesh_face_material.rb +30 -0
  101. data/lib/mittsu/materials/mesh_lambert_material.rb +126 -0
  102. data/lib/mittsu/materials/mesh_phong_material.rb +152 -0
  103. data/lib/mittsu/materials/shader_material.rb +108 -0
  104. data/lib/mittsu/math.rb +105 -0
  105. data/lib/mittsu/math/box2.rb +135 -0
  106. data/lib/mittsu/math/box3.rb +194 -0
  107. data/lib/mittsu/math/color.rb +252 -0
  108. data/lib/mittsu/math/color_keywords.rb +151 -0
  109. data/lib/mittsu/math/euler.rb +182 -0
  110. data/lib/mittsu/math/frustum.rb +106 -0
  111. data/lib/mittsu/math/line3.rb +76 -0
  112. data/lib/mittsu/math/matrix3.rb +163 -0
  113. data/lib/mittsu/math/matrix4.rb +581 -0
  114. data/lib/mittsu/math/plane.rb +128 -0
  115. data/lib/mittsu/math/quaternion.rb +309 -0
  116. data/lib/mittsu/math/ray.rb +292 -0
  117. data/lib/mittsu/math/sphere.rb +91 -0
  118. data/lib/mittsu/math/spline.rb +128 -0
  119. data/lib/mittsu/math/triangle.rb +121 -0
  120. data/lib/mittsu/math/vector2.rb +238 -0
  121. data/lib/mittsu/math/vector3.rb +491 -0
  122. data/lib/mittsu/math/vector4.rb +414 -0
  123. data/lib/mittsu/objects.rb +3 -0
  124. data/lib/mittsu/objects/group.rb +8 -0
  125. data/lib/mittsu/objects/line.rb +143 -0
  126. data/lib/mittsu/objects/mesh.rb +243 -0
  127. data/lib/mittsu/renderers.rb +1 -0
  128. data/lib/mittsu/renderers/glfw_window.rb +216 -0
  129. data/lib/mittsu/renderers/opengl/opengl_debug.rb +38 -0
  130. data/lib/mittsu/renderers/opengl/opengl_program.rb +402 -0
  131. data/lib/mittsu/renderers/opengl/opengl_shader.rb +58 -0
  132. data/lib/mittsu/renderers/opengl/opengl_state.rb +207 -0
  133. data/lib/mittsu/renderers/opengl/plugins/shadow_map_plugin.rb +416 -0
  134. data/lib/mittsu/renderers/opengl_render_target.rb +87 -0
  135. data/lib/mittsu/renderers/opengl_renderer.rb +3376 -0
  136. data/lib/mittsu/renderers/shaders/shader_chunk.rb +12 -0
  137. data/lib/mittsu/renderers/shaders/shader_chunk/alphamap_fragment.glsl +5 -0
  138. data/lib/mittsu/renderers/shaders/shader_chunk/alphamap_pars_fragment.glsl +5 -0
  139. data/lib/mittsu/renderers/shaders/shader_chunk/alphatest_fragment.glsl +5 -0
  140. data/lib/mittsu/renderers/shaders/shader_chunk/bumpmap_pars_fragment.glsl +40 -0
  141. data/lib/mittsu/renderers/shaders/shader_chunk/color_fragment.glsl +5 -0
  142. data/lib/mittsu/renderers/shaders/shader_chunk/color_pars_fragment.glsl +5 -0
  143. data/lib/mittsu/renderers/shaders/shader_chunk/color_pars_vertex.glsl +5 -0
  144. data/lib/mittsu/renderers/shaders/shader_chunk/color_vertex.glsl +5 -0
  145. data/lib/mittsu/renderers/shaders/shader_chunk/common.glsl +60 -0
  146. data/lib/mittsu/renderers/shaders/shader_chunk/default_vertex.glsl +15 -0
  147. data/lib/mittsu/renderers/shaders/shader_chunk/defaultnormal_vertex.glsl +21 -0
  148. data/lib/mittsu/renderers/shaders/shader_chunk/envmap_fragment.glsl +62 -0
  149. data/lib/mittsu/renderers/shaders/shader_chunk/envmap_pars_fragment.glsl +21 -0
  150. data/lib/mittsu/renderers/shaders/shader_chunk/envmap_pars_vertex.glsl +7 -0
  151. data/lib/mittsu/renderers/shaders/shader_chunk/envmap_vertex.glsl +17 -0
  152. data/lib/mittsu/renderers/shaders/shader_chunk/fog_fragment.glsl +26 -0
  153. data/lib/mittsu/renderers/shaders/shader_chunk/fog_pars_fragment.glsl +15 -0
  154. data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_fragment.glsl +5 -0
  155. data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_pars_fragment.glsl +6 -0
  156. data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_pars_vertex.glsl +5 -0
  157. data/lib/mittsu/renderers/shaders/shader_chunk/lightmap_vertex.glsl +5 -0
  158. data/lib/mittsu/renderers/shaders/shader_chunk/lights_lambert_pars_vertex.glsl +43 -0
  159. data/lib/mittsu/renderers/shaders/shader_chunk/lights_lambert_vertex.glsl +196 -0
  160. data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_fragment.glsl +243 -0
  161. data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_pars_fragment.glsl +58 -0
  162. data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_pars_vertex.glsl +5 -0
  163. data/lib/mittsu/renderers/shaders/shader_chunk/lights_phong_vertex.glsl +5 -0
  164. data/lib/mittsu/renderers/shaders/shader_chunk/linear_to_gamma_fragment.glsl +2 -0
  165. data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_fragment.glsl +5 -0
  166. data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_pars_fragment.glsl +12 -0
  167. data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_pars_vertex.glsl +11 -0
  168. data/lib/mittsu/renderers/shaders/shader_chunk/logdepthbuf_vertex.glsl +15 -0
  169. data/lib/mittsu/renderers/shaders/shader_chunk/map_fragment.glsl +9 -0
  170. data/lib/mittsu/renderers/shaders/shader_chunk/map_pars_fragment.glsl +11 -0
  171. data/lib/mittsu/renderers/shaders/shader_chunk/map_pars_vertex.glsl +6 -0
  172. data/lib/mittsu/renderers/shaders/shader_chunk/map_particle_fragment.glsl +5 -0
  173. data/lib/mittsu/renderers/shaders/shader_chunk/map_particle_pars_fragment.glsl +6 -0
  174. data/lib/mittsu/renderers/shaders/shader_chunk/map_vertex.glsl +5 -0
  175. data/lib/mittsu/renderers/shaders/shader_chunk/morphnormal_vertex.glsl +12 -0
  176. data/lib/mittsu/renderers/shaders/shader_chunk/morphtarget_pars_vertex.glsl +13 -0
  177. data/lib/mittsu/renderers/shaders/shader_chunk/morphtarget_vertex.glsl +20 -0
  178. data/lib/mittsu/renderers/shaders/shader_chunk/normalmap_pars_fragment.glsl +27 -0
  179. data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_fragment.glsl +217 -0
  180. data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_pars_fragment.glsl +19 -0
  181. data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_pars_vertex.glsl +6 -0
  182. data/lib/mittsu/renderers/shaders/shader_chunk/shadowmap_vertex.glsl +9 -0
  183. data/lib/mittsu/renderers/shaders/shader_chunk/skinbase_vertex.glsl +8 -0
  184. data/lib/mittsu/renderers/shaders/shader_chunk/skinning_pars_vertex.glsl +47 -0
  185. data/lib/mittsu/renderers/shaders/shader_chunk/skinning_vertex.glsl +20 -0
  186. data/lib/mittsu/renderers/shaders/shader_chunk/skinnormal_vertex.glsl +20 -0
  187. data/lib/mittsu/renderers/shaders/shader_chunk/specularmap_fragment.glsl +12 -0
  188. data/lib/mittsu/renderers/shaders/shader_chunk/specularmap_pars_fragment.glsl +5 -0
  189. data/lib/mittsu/renderers/shaders/shader_chunk/worldpos_vertex.glsl +17 -0
  190. data/lib/mittsu/renderers/shaders/shader_lib.rb +420 -0
  191. data/lib/mittsu/renderers/shaders/uniforms_lib.rb +107 -0
  192. data/lib/mittsu/renderers/shaders/uniforms_utils.rb +31 -0
  193. data/lib/mittsu/scenes.rb +1 -0
  194. data/lib/mittsu/scenes/scene.rb +27 -0
  195. data/lib/mittsu/textures.rb +5 -0
  196. data/lib/mittsu/textures/compressed_texture.rb +30 -0
  197. data/lib/mittsu/textures/cube_texture.rb +19 -0
  198. data/lib/mittsu/textures/data_texture.rb +17 -0
  199. data/lib/mittsu/textures/texture.rb +92 -0
  200. data/lib/mittsu/textures/video_texture.rb +17 -0
  201. data/lib/mittsu/version.rb +4 -0
  202. data/mittsu.gemspec +31 -0
  203. metadata +357 -0
@@ -0,0 +1,151 @@
1
+ module Mittsu
2
+ ColorKeywords = {
3
+ 'aliceblue' => 0xF0F8FF,
4
+ 'antiquewhite' => 0xFAEBD7,
5
+ 'aqua' => 0x00FFFF,
6
+ 'aquamarine' => 0x7FFFD4,
7
+ 'azure' => 0xF0FFFF,
8
+ 'beige' => 0xF5F5DC,
9
+ 'bisque' => 0xFFE4C4,
10
+ 'black' => 0x000000,
11
+ 'blanchedalmond' => 0xFFEBCD,
12
+ 'blue' => 0x0000FF,
13
+ 'blueviolet' => 0x8A2BE2,
14
+ 'brown' => 0xA52A2A,
15
+ 'burlywood' => 0xDEB887,
16
+ 'cadetblue' => 0x5F9EA0,
17
+ 'chartreuse' => 0x7FFF00,
18
+ 'chocolate' => 0xD2691E,
19
+ 'coral' => 0xFF7F50,
20
+ 'cornflowerblue' => 0x6495ED,
21
+ 'cornsilk' => 0xFFF8DC,
22
+ 'crimson' => 0xDC143C,
23
+ 'cyan' => 0x00FFFF,
24
+ 'darkblue' => 0x00008B,
25
+ 'darkcyan' => 0x008B8B,
26
+ 'darkgoldenrod' => 0xB8860B,
27
+ 'darkgray' => 0xA9A9A9,
28
+ 'darkgreen' => 0x006400,
29
+ 'darkgrey' => 0xA9A9A9,
30
+ 'darkkhaki' => 0xBDB76B,
31
+ 'darkmagenta' => 0x8B008B,
32
+ 'darkolivegreen' => 0x556B2F,
33
+ 'darkorange' => 0xFF8C00,
34
+ 'darkorchid' => 0x9932CC,
35
+ 'darkred' => 0x8B0000,
36
+ 'darksalmon' => 0xE9967A,
37
+ 'darkseagreen' => 0x8FBC8F,
38
+ 'darkslateblue' => 0x483D8B,
39
+ 'darkslategray' => 0x2F4F4F,
40
+ 'darkslategrey' => 0x2F4F4F,
41
+ 'darkturquoise' => 0x00CED1,
42
+ 'darkviolet' => 0x9400D3,
43
+ 'deeppink' => 0xFF1493,
44
+ 'deepskyblue' => 0x00BFFF,
45
+ 'dimgray' => 0x696969,
46
+ 'dimgrey' => 0x696969,
47
+ 'dodgerblue' => 0x1E90FF,
48
+ 'firebrick' => 0xB22222,
49
+ 'floralwhite' => 0xFFFAF0,
50
+ 'forestgreen' => 0x228B22,
51
+ 'fuchsia' => 0xFF00FF,
52
+ 'gainsboro' => 0xDCDCDC,
53
+ 'ghostwhite' => 0xF8F8FF,
54
+ 'gold' => 0xFFD700,
55
+ 'goldenrod' => 0xDAA520,
56
+ 'gray' => 0x808080,
57
+ 'green' => 0x008000,
58
+ 'greenyellow' => 0xADFF2F,
59
+ 'grey' => 0x808080,
60
+ 'honeydew' => 0xF0FFF0,
61
+ 'hotpink' => 0xFF69B4,
62
+ 'indianred' => 0xCD5C5C,
63
+ 'indigo' => 0x4B0082,
64
+ 'ivory' => 0xFFFFF0,
65
+ 'khaki' => 0xF0E68C,
66
+ 'lavender' => 0xE6E6FA,
67
+ 'lavenderblush' => 0xFFF0F5,
68
+ 'lawngreen' => 0x7CFC00,
69
+ 'lemonchiffon' => 0xFFFACD,
70
+ 'lightblue' => 0xADD8E6,
71
+ 'lightcoral' => 0xF08080,
72
+ 'lightcyan' => 0xE0FFFF,
73
+ 'lightgoldenrodyellow' => 0xFAFAD2,
74
+ 'lightgray' => 0xD3D3D3,
75
+ 'lightgreen' => 0x90EE90,
76
+ 'lightgrey' => 0xD3D3D3,
77
+ 'lightpink' => 0xFFB6C1,
78
+ 'lightsalmon' => 0xFFA07A,
79
+ 'lightseagreen' => 0x20B2AA,
80
+ 'lightskyblue' => 0x87CEFA,
81
+ 'lightslategray' => 0x778899,
82
+ 'lightslategrey' => 0x778899,
83
+ 'lightsteelblue' => 0xB0C4DE,
84
+ 'lightyellow' => 0xFFFFE0,
85
+ 'lime' => 0x00FF00,
86
+ 'limegreen' => 0x32CD32,
87
+ 'linen' => 0xFAF0E6,
88
+ 'magenta' => 0xFF00FF,
89
+ 'maroon' => 0x800000,
90
+ 'mediumaquamarine' => 0x66CDAA,
91
+ 'mediumblue' => 0x0000CD,
92
+ 'mediumorchid' => 0xBA55D3,
93
+ 'mediumpurple' => 0x9370DB,
94
+ 'mediumseagreen' => 0x3CB371,
95
+ 'mediumslateblue' => 0x7B68EE,
96
+ 'mediumspringgreen' => 0x00FA9A,
97
+ 'mediumturquoise' => 0x48D1CC,
98
+ 'mediumvioletred' => 0xC71585,
99
+ 'midnightblue' => 0x191970,
100
+ 'mintcream' => 0xF5FFFA,
101
+ 'mistyrose' => 0xFFE4E1,
102
+ 'moccasin' => 0xFFE4B5,
103
+ 'navajowhite' => 0xFFDEAD,
104
+ 'navy' => 0x000080,
105
+ 'oldlace' => 0xFDF5E6,
106
+ 'olive' => 0x808000,
107
+ 'olivedrab' => 0x6B8E23,
108
+ 'orange' => 0xFFA500,
109
+ 'orangered' => 0xFF4500,
110
+ 'orchid' => 0xDA70D6,
111
+ 'palegoldenrod' => 0xEEE8AA,
112
+ 'palegreen' => 0x98FB98,
113
+ 'paleturquoise' => 0xAFEEEE,
114
+ 'palevioletred' => 0xDB7093,
115
+ 'papayawhip' => 0xFFEFD5,
116
+ 'peachpuff' => 0xFFDAB9,
117
+ 'peru' => 0xCD853F,
118
+ 'pink' => 0xFFC0CB,
119
+ 'plum' => 0xDDA0DD,
120
+ 'powderblue' => 0xB0E0E6,
121
+ 'purple' => 0x800080,
122
+ 'red' => 0xFF0000,
123
+ 'rosybrown' => 0xBC8F8F,
124
+ 'royalblue' => 0x4169E1,
125
+ 'saddlebrown' => 0x8B4513,
126
+ 'salmon' => 0xFA8072,
127
+ 'sandybrown' => 0xF4A460,
128
+ 'seagreen' => 0x2E8B57,
129
+ 'seashell' => 0xFFF5EE,
130
+ 'sienna' => 0xA0522D,
131
+ 'silver' => 0xC0C0C0,
132
+ 'skyblue' => 0x87CEEB,
133
+ 'slateblue' => 0x6A5ACD,
134
+ 'slategray' => 0x708090,
135
+ 'slategrey' => 0x708090,
136
+ 'snow' => 0xFFFAFA,
137
+ 'springgreen' => 0x00FF7F,
138
+ 'steelblue' => 0x4682B4,
139
+ 'tan' => 0xD2B48C,
140
+ 'teal' => 0x008080,
141
+ 'thistle' => 0xD8BFD8,
142
+ 'tomato' => 0xFF6347,
143
+ 'turquoise' => 0x40E0D0,
144
+ 'violet' => 0xEE82EE,
145
+ 'wheat' => 0xF5DEB3,
146
+ 'white' => 0xFFFFFF,
147
+ 'whitesmoke' => 0xF5F5F5,
148
+ 'yellow' => 0xFFFF00,
149
+ 'yellowgreen' => 0x9ACD32
150
+ }
151
+ end
@@ -0,0 +1,182 @@
1
+ require 'mittsu/math'
2
+
3
+ module Mittsu
4
+ class Euler
5
+ RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ]
6
+ DefaultOrder = 'XYZ'
7
+
8
+ attr_reader :x, :y, :z, :order
9
+
10
+ def initialize(x = 0.0, y = 0.0, z = 0.0, order = DefaultOrder)
11
+ @x, @y, @z, @order = x.to_f, y.to_f, z.to_f, order
12
+ end
13
+
14
+ def set(x, y, z, order)
15
+ @x = x.to_f
16
+ @y = y.to_f
17
+ @z = z.to_f
18
+ @order = order || @order
19
+ self.on_change_callback
20
+ self
21
+ end
22
+
23
+ def x=(x)
24
+ @x = x.to_f
25
+ self.on_change_callback
26
+ end
27
+
28
+ def y=(y)
29
+ @y = y.to_f
30
+ self.on_change_callback
31
+ end
32
+
33
+ def z=(z)
34
+ @z = z.to_f
35
+ self.on_change_callback
36
+ end
37
+
38
+ def order=(order)
39
+ @order = order
40
+ self.on_change_callback
41
+ end
42
+
43
+ def copy(euler)
44
+ @x = euler.x
45
+ @y = euler.y
46
+ @z = euler.z
47
+ @order = euler.order
48
+ self.on_change_callback
49
+ self
50
+ end
51
+
52
+ def set_from_rotation_matrix(m, order, update = true)
53
+ # assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
54
+ te = m.elements
55
+ m11 = te[0]; m12 = te[4]; m13 = te[8]
56
+ m21 = te[1]; m22 = te[5]; m23 = te[9]
57
+ m31 = te[2]; m32 = te[6]; m33 = te[10]
58
+ order = order || @order
59
+ if order == 'XYZ'
60
+ @y = Math.asin(Math.clamp(m13, -1.0, 1.0))
61
+ if m13.abs < 0.99999
62
+ @x = Math.atan2(- m23, m33)
63
+ @z = Math.atan2(- m12, m11)
64
+ else
65
+ @x = Math.atan2(m32, m22)
66
+ @z = 0.0
67
+ end
68
+ elsif order == 'YXZ'
69
+ @x = Math.asin(- Math.clamp(m23, -1.0, 1.0))
70
+ if m23.abs < 0.99999
71
+ @y = Math.atan2(m13, m33)
72
+ @z = Math.atan2(m21, m22)
73
+ else
74
+ @y = Math.atan2(- m31, m11)
75
+ @z = 0.0
76
+ end
77
+ elsif order == 'ZXY'
78
+ @x = Math.asin(Math.clamp(m32, -1.0, 1.0))
79
+ if m32.abs < 0.99999
80
+ @y = Math.atan2(- m31, m33)
81
+ @z = Math.atan2(- m12, m22)
82
+ else
83
+ @y = 0.0
84
+ @z = Math.atan2(m21, m11)
85
+ end
86
+ elsif order == 'ZYX'
87
+ @y = Math.asin(- Math.clamp(m31, -1.0, 1.0))
88
+ if m31.abs < 0.99999
89
+ @x = Math.atan2(m32, m33)
90
+ @z = Math.atan2(m21, m11)
91
+ else
92
+ @x = 0.0
93
+ @z = Math.atan2(- m12, m22)
94
+ end
95
+ elsif order == 'YZX'
96
+ @z = Math.asin(Math.clamp(m21, -1.0, 1.0))
97
+ if m21.abs < 0.99999
98
+ @x = Math.atan2(- m23, m22)
99
+ @y = Math.atan2(- m31, m11)
100
+ else
101
+ @x = 0.0
102
+ @y = Math.atan2(m13, m33)
103
+ end
104
+ elsif order == 'XZY'
105
+ @z = Math.asin(- Math.clamp(m12, -1.0, 1.0))
106
+ if m12.abs < 0.99999
107
+ @x = Math.atan2(m32, m22)
108
+ @y = Math.atan2(m13, m11)
109
+ else
110
+ @x = Math.atan2(- m23, m33)
111
+ @y = 0.0
112
+ end
113
+ else
114
+ puts("WARNING: Mittsu::Euler#set_from_rotation_matrix given unsupported order: #{order}")
115
+ end
116
+ @order = order
117
+ self.on_change_callback if update
118
+ self
119
+ end
120
+
121
+ def set_from_quaternion(q, order, update = true)
122
+ matrix = Mittsu::Matrix4.new
123
+ matrix.make_rotation_from_quaternion(q)
124
+ self.set_from_rotation_matrix(matrix, order, update)
125
+ self
126
+ end
127
+
128
+ def set_from_vector3(v, order)
129
+ self.set(v.x, v.y, v.z, order || @order)
130
+ end
131
+
132
+ def reorder(new_order)
133
+ # WARNING: this discards revolution information -bhouston
134
+ q = Mittsu::Quaternion.new.set_from_euler(self)
135
+ self.set_from_quaternion(q, new_order)
136
+ end
137
+
138
+ def ==(euler)
139
+ (euler.x == @x) && (euler.y == @y) && (euler.z == @z) && (euler.order == @order)
140
+ end
141
+
142
+ def from_array(array)
143
+ @x = array[0]
144
+ @y = array[1]
145
+ @z = array[2]
146
+ @order = array[3] unless array[3].nil?
147
+ self.on_change_callback
148
+ self
149
+ end
150
+
151
+ def to_a(array = [], offset = 0)
152
+ array[offset] = @x
153
+ array[offset + 1] = @y
154
+ array[offset + 2] = @z
155
+ array[offset + 3] = @order
156
+ array
157
+ end
158
+
159
+ def to_vector3(optional_result = nil)
160
+ if optional_result
161
+ return optional_result.set(@x, @y, @z)
162
+ else
163
+ return Mittsu::Vector3.new(@x, @y, @z)
164
+ end
165
+ end
166
+
167
+ def on_change(&callback)
168
+ @on_change_callback = callback
169
+ self
170
+ end
171
+
172
+ def on_change_callback
173
+ return unless @on_change_callback
174
+ @on_change_callback.call
175
+ end
176
+
177
+ def clone
178
+ Mittsu::Euler.new(@x, @y, @z, @order)
179
+ end
180
+
181
+ end
182
+ end
@@ -0,0 +1,106 @@
1
+ require 'mittsu/math'
2
+
3
+ module Mittsu
4
+ class Frustum
5
+ attr_accessor :planes
6
+
7
+ def initialize(p0 = nil, p1 = nil, p2 = nil, p3 = nil, p4 = nil, p5 = nil)
8
+ @planes = [
9
+ p0 || Mittsu::Plane.new,
10
+ p1 || Mittsu::Plane.new,
11
+ p2 || Mittsu::Plane.new,
12
+ p3 || Mittsu::Plane.new,
13
+ p4 || Mittsu::Plane.new,
14
+ p5 || Mittsu::Plane.new
15
+ ]
16
+ end
17
+
18
+ def set(p0, p1, p2, p3, p4, p5)
19
+ planes = self.planes
20
+ planes[0].copy(p0)
21
+ planes[1].copy(p1)
22
+ planes[2].copy(p2)
23
+ planes[3].copy(p3)
24
+ planes[4].copy(p4)
25
+ planes[5].copy(p5)
26
+ self
27
+ end
28
+
29
+ def copy(frustum)
30
+ planes = self.planes
31
+ 6.times do |i|
32
+ planes[i].copy(frustum.planes[i])
33
+ end
34
+ self
35
+ end
36
+
37
+ def set_from_matrix(m)
38
+ planes = self.planes
39
+ me = m.elements
40
+ me0 = me[0]; me1 = me[1]; me2 = me[2]; me3 = me[3]
41
+ me4 = me[4]; me5 = me[5]; me6 = me[6]; me7 = me[7]
42
+ me8 = me[8]; me9 = me[9]; me10 = me[10]; me11 = me[11]
43
+ me12 = me[12]; me13 = me[13]; me14 = me[14]; me15 = me[15]
44
+ planes[0].set_components(me3 - me0, me7 - me4, me11 - me8, me15 - me12).normalize
45
+ planes[1].set_components(me3 + me0, me7 + me4, me11 + me8, me15 + me12).normalize
46
+ planes[2].set_components(me3 + me1, me7 + me5, me11 + me9, me15 + me13).normalize
47
+ planes[3].set_components(me3 - me1, me7 - me5, me11 - me9, me15 - me13).normalize
48
+ planes[4].set_components(me3 - me2, me7 - me6, me11 - me10, me15 - me14).normalize
49
+ planes[5].set_components(me3 + me2, me7 + me6, me11 + me10, me15 + me14).normalize
50
+ self
51
+ end
52
+
53
+ def intersects_object?(object)
54
+ sphere = Mittsu::Sphere.new
55
+ geometry = object.geometry
56
+ geometry.compute_bounding_sphere if geometry.bounding_sphere.nil?
57
+ sphere.copy(geometry.bounding_sphere)
58
+ sphere.apply_matrix4(object.matrix_world)
59
+ self.intersects_sphere?(sphere)
60
+ end
61
+
62
+ def intersects_sphere?(sphere)
63
+ planes = self.planes
64
+ center = sphere.center
65
+ negRadius = -sphere.radius
66
+ 6.times do |i|
67
+ distance = planes[i].distance_to_point(center)
68
+ return false if distance < negRadius
69
+ end
70
+ true
71
+ end
72
+
73
+ def intersects_box?(box)
74
+ p1 = Mittsu::Vector3.new
75
+ p2 = Mittsu::Vector3.new
76
+ planes = self.planes
77
+ 6.times do |i|
78
+ plane = planes[i]
79
+ p1.x = plane.normal.x > 0 ? box.min.x : box.max.x
80
+ p2.x = plane.normal.x > 0 ? box.max.x : box.min.x
81
+ p1.y = plane.normal.y > 0 ? box.min.y : box.max.y
82
+ p2.y = plane.normal.y > 0 ? box.max.y : box.min.y
83
+ p1.z = plane.normal.z > 0 ? box.min.z : box.max.z
84
+ p2.z = plane.normal.z > 0 ? box.max.z : box.min.z
85
+ d1 = plane.distance_to_point(p1)
86
+ d2 = plane.distance_to_point(p2)
87
+ # if both outside plane, no intersection
88
+ return false if d1 < 0 && d2 < 0
89
+ end
90
+ true
91
+ end
92
+
93
+ def contains_point?(point)
94
+ planes = self.planes
95
+ 6.times do |i|
96
+ return false if planes[i].distance_to_point(point) < 0
97
+ end
98
+ true
99
+ end
100
+
101
+ def clone
102
+ Mittsu::Frustum.new.copy(self)
103
+ end
104
+
105
+ end
106
+ end
@@ -0,0 +1,76 @@
1
+ require 'mittsu/math'
2
+
3
+ module Mittsu
4
+ class Line3
5
+ attr_accessor :start_point, :end_point
6
+
7
+ def initialize(start_point = Mittsu::Vector3.new, end_point = Mittsu::Vector3.new)
8
+ @start_point, @end_point = start_point, end_point
9
+ end
10
+
11
+ def set(start_point, end_point)
12
+ @start_point.copy(start_point)
13
+ @end_point.copy(end_point)
14
+ self
15
+ end
16
+
17
+ def copy(line)
18
+ @start_point.copy(line.start_point)
19
+ @end_point.copy(line.end_point)
20
+ self
21
+ end
22
+
23
+ def center(target = Mittsu::Vector3.new)
24
+ target.add_vectors(@start_point, @end_point).multiply_scalar(0.5)
25
+ end
26
+
27
+ def delta(target = Mittsu::Vector3.new)
28
+ target.sub_vectors(@end_point, @start_point)
29
+ end
30
+
31
+ def distance_sq
32
+ @start_point.distance_to_squared(@end_point)
33
+ end
34
+
35
+ def distance
36
+ @start_point.distance_to(@end_point)
37
+ end
38
+
39
+ def at(t, target = Mittsu::Vector3.new)
40
+ self.delta(target).multiply_scalar(t).add(self.start_point)
41
+ end
42
+
43
+ def closest_point_to_point_parameter(point, clamp_to_line)
44
+ start_p = Mittsu::Vector3.new
45
+ start_end = Mittsu::Vector3.new
46
+ start_p.sub_vectors(point, @start_point)
47
+ start_end.sub_vectors(@end_point, @start_point)
48
+ start_end2 = start_end.dot(start_end)
49
+ start_end_start_p = start_end.dot(start_p)
50
+ t = start_end_start_p / start_end2
51
+ if clamp_to_line
52
+ t = Math.clamp(t, 0.0, 1.0)
53
+ end
54
+ t
55
+ end
56
+
57
+ def closest_point_to_point(point, clamp_to_line, target = Mittsu::Vector3.new)
58
+ t = self.closest_point_to_point_parameter(point, clamp_to_line)
59
+ self.delta(target).multiply_scalar(t).add(self.start_point)
60
+ end
61
+
62
+ def apply_matrix4(matrix)
63
+ @start_point.apply_matrix4(matrix)
64
+ @end_point.apply_matrix4(matrix)
65
+ self
66
+ end
67
+
68
+ def equals(line)
69
+ line.start_point.equals(@start_point) && line.end_point.equals(@end_point)
70
+ end
71
+
72
+ def clone
73
+ Mittsu::Line3.new.copy(self)
74
+ end
75
+ end
76
+ end