jax 1.1.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (473) hide show
  1. data/.gitignore +4 -0
  2. data/.rvmrc +2 -3
  3. data/.travis.yml +8 -22
  4. data/README.md +2 -2
  5. data/Rakefile +128 -96
  6. data/app/assets/javascripts/jax/controller-list.js.coffee +22 -0
  7. data/app/assets/javascripts/jax/dom-helpers.js.coffee +17 -0
  8. data/app/assets/javascripts/jax/jasmine_runner.js +177 -0
  9. data/app/assets/javascripts/jax/runtime.js +6 -0
  10. data/app/assets/javascripts/jax/shader_editor.js.coffee +33 -0
  11. data/app/assets/stylesheets/jax/controller-list.css +5 -0
  12. data/app/assets/stylesheets/jax/jasmine.css +16 -0
  13. data/app/assets/stylesheets/jax/nav.css +41 -0
  14. data/app/assets/stylesheets/jax/runtime.css +47 -0
  15. data/app/assets/stylesheets/jax/shader_editor.css +3 -0
  16. data/app/assets/stylesheets/jax/suite.css +82 -0
  17. data/app/controllers/jax/suite_controller.rb +48 -0
  18. data/app/views/jax/suite/jasmine.html.erb +38 -0
  19. data/app/views/jax/suite/run_webgl.html.erb +49 -0
  20. data/app/views/jax/suite/shader_editor.html.erb +24 -0
  21. data/app/views/layouts/jax.html.erb +40 -0
  22. data/bin/jax +8 -4
  23. data/config/routes.rb +2 -0
  24. data/config.ru +5 -0
  25. data/features/rails/resources.feature +45 -0
  26. data/features/rails/shaders.feature +13 -0
  27. data/features/rails/specs.feature +24 -0
  28. data/features/runtime.feature +15 -0
  29. data/features/step_definitions/environment_steps.rb +15 -0
  30. data/features/step_definitions/response_steps.rb +13 -0
  31. data/features/step_definitions/runtime.rb +11 -0
  32. data/features/step_definitions/web_steps.rb +223 -0
  33. data/features/support/env.rb +75 -0
  34. data/features/support/paths.rb +30 -0
  35. data/features/support/rails_environment.rb +3 -0
  36. data/features/support/selectors.rb +39 -0
  37. data/features/support/setup.rb +17 -0
  38. data/jax.gemspec +22 -16
  39. data/lib/assets/javascripts/jax/anim_frame.js +64 -0
  40. data/lib/assets/javascripts/jax/application.js +16 -0
  41. data/lib/assets/javascripts/jax/builtin/all.js +21 -0
  42. data/lib/assets/javascripts/jax/builtin/meshes/cube.js +83 -0
  43. data/lib/assets/javascripts/jax/builtin/meshes/plane.js +67 -0
  44. data/lib/assets/javascripts/jax/builtin/meshes/quad.js +89 -0
  45. data/lib/assets/javascripts/jax/builtin/meshes/sphere.js +65 -0
  46. data/lib/assets/javascripts/jax/builtin/meshes/teapot.js +48 -0
  47. data/lib/assets/javascripts/jax/builtin/meshes/torus.js +64 -0
  48. data/lib/assets/javascripts/jax/compatibility.js +312 -0
  49. data/lib/assets/javascripts/jax/context.js +741 -0
  50. data/lib/assets/javascripts/jax/core/base.js +69 -0
  51. data/lib/assets/javascripts/jax/core/glMatrix_ext/mat3.js +20 -0
  52. data/lib/assets/javascripts/jax/core/glMatrix_ext/mat4.js +10 -0
  53. data/lib/assets/javascripts/jax/core/glMatrix_ext/quat4.js +148 -0
  54. data/lib/assets/javascripts/jax/core/glMatrix_ext/vec2.js +25 -0
  55. data/lib/assets/javascripts/jax/core/glMatrix_ext/vec3.js +86 -0
  56. data/lib/assets/javascripts/jax/core/glMatrix_ext/vec4.js +28 -0
  57. data/lib/assets/javascripts/jax/core/helper.js +44 -0
  58. data/lib/assets/javascripts/jax/core/math.js +61 -0
  59. data/lib/assets/javascripts/jax/core/matrix_stack.js +310 -0
  60. data/lib/assets/javascripts/jax/core/util.js +271 -0
  61. data/lib/assets/javascripts/jax/core.js +43 -0
  62. data/lib/assets/javascripts/jax/events.js +304 -0
  63. data/lib/assets/javascripts/jax/geometry/line.js +185 -0
  64. data/lib/assets/javascripts/jax/geometry/plane.js +371 -0
  65. data/lib/assets/javascripts/jax/geometry/triangle/inliner.rb +94 -0
  66. data/lib/assets/javascripts/jax/geometry/triangle/slow_tri_tri_intersect.js +20 -0
  67. data/lib/assets/javascripts/jax/geometry/triangle/tri_tri_intersect.js +281 -0
  68. data/lib/assets/javascripts/jax/geometry/triangle/tri_tri_intersect_optimized.js +564 -0
  69. data/lib/assets/javascripts/jax/geometry/triangle.js +311 -0
  70. data/lib/assets/javascripts/jax/geometry.js +14 -0
  71. data/lib/assets/javascripts/jax/mvc/controller.js +188 -0
  72. data/lib/assets/javascripts/jax/mvc/model.js +302 -0
  73. data/lib/assets/javascripts/jax/mvc/route_set.js +148 -0
  74. data/lib/assets/javascripts/jax/mvc/view.js +43 -0
  75. data/lib/assets/javascripts/jax/mvc/view_manager.js +65 -0
  76. data/lib/assets/javascripts/jax/noise.js +251 -0
  77. data/lib/assets/javascripts/jax/prototype/class.js +81 -0
  78. data/lib/assets/javascripts/jax/prototype/core.js +112 -0
  79. data/lib/assets/javascripts/jax/prototype/extensions.js +142 -0
  80. data/lib/assets/javascripts/jax/vendor/ejs.js +1 -0
  81. data/lib/assets/javascripts/jax/vendor/glMatrix.js +7 -0
  82. data/lib/assets/javascripts/jax/webgl/camera.js +697 -0
  83. data/lib/assets/javascripts/jax/webgl/cleanup.js +1 -0
  84. data/lib/assets/javascripts/jax/webgl/core/buffer.js +292 -0
  85. data/lib/assets/javascripts/jax/webgl/core/data_region.js +184 -0
  86. data/lib/assets/javascripts/jax/webgl/core/data_segment.js +255 -0
  87. data/lib/assets/javascripts/jax/webgl/core/events.js +99 -0
  88. data/lib/assets/javascripts/jax/webgl/core/framebuffer.js +316 -0
  89. data/lib/assets/javascripts/jax/webgl/core.js +6 -0
  90. data/lib/assets/javascripts/jax/webgl/material.js +381 -0
  91. data/lib/assets/javascripts/jax/webgl/mesh/normals.js +37 -0
  92. data/lib/assets/javascripts/jax/webgl/mesh/support.js +104 -0
  93. data/lib/assets/javascripts/jax/webgl/mesh/tangent_space.js +111 -0
  94. data/lib/assets/javascripts/jax/webgl/mesh.js +440 -0
  95. data/lib/assets/javascripts/jax/webgl/scene/frustum.js +422 -0
  96. data/lib/assets/javascripts/jax/webgl/scene/light_manager.js +141 -0
  97. data/lib/assets/javascripts/jax/webgl/scene/light_source.js +300 -0
  98. data/lib/assets/javascripts/jax/webgl/scene.js +16 -0
  99. data/lib/assets/javascripts/jax/webgl/shader/delegator/attribute.js +53 -0
  100. data/lib/assets/javascripts/jax/webgl/shader/delegator/uniform.js +71 -0
  101. data/lib/assets/javascripts/jax/webgl/shader/delegator.js +13 -0
  102. data/lib/assets/javascripts/jax/webgl/shader/manifest.js +70 -0
  103. data/lib/assets/javascripts/jax/webgl/shader/program.js +138 -0
  104. data/lib/assets/javascripts/jax/webgl/shader.js +299 -0
  105. data/lib/assets/javascripts/jax/webgl/shader_chain.js +267 -0
  106. data/lib/assets/javascripts/jax/webgl/texture.js +506 -0
  107. data/lib/assets/javascripts/jax/webgl/world.js +279 -0
  108. data/lib/assets/javascripts/jax/webgl.js +109 -0
  109. data/lib/assets/javascripts/jax.js +136 -0
  110. data/{builtin/app/shaders/basic/common.ejs → lib/assets/javascripts/shaders/basic/common.glsl} +0 -0
  111. data/{builtin/app/shaders/basic/fragment.ejs → lib/assets/javascripts/shaders/basic/fragment.glsl} +0 -0
  112. data/{builtin/app/shaders/basic/vertex.ejs → lib/assets/javascripts/shaders/basic/vertex.glsl} +1 -1
  113. data/{builtin/app/shaders/depthmap/common.ejs → lib/assets/javascripts/shaders/depthmap/common.glsl} +0 -0
  114. data/{builtin/app/shaders/depthmap/fragment.ejs → lib/assets/javascripts/shaders/depthmap/fragment.glsl} +1 -1
  115. data/{builtin/app → lib/assets/javascripts}/shaders/depthmap/material.js +0 -0
  116. data/{builtin/app/shaders/depthmap/vertex.ejs → lib/assets/javascripts/shaders/depthmap/vertex.glsl} +0 -0
  117. data/{builtin/app/shaders/fog/common.ejs → lib/assets/javascripts/shaders/fog/common.glsl} +0 -0
  118. data/{builtin/app/shaders/fog/fragment.ejs → lib/assets/javascripts/shaders/fog/fragment.glsl} +0 -0
  119. data/{builtin/app → lib/assets/javascripts}/shaders/fog/manifest.yml +0 -0
  120. data/{builtin/app → lib/assets/javascripts}/shaders/fog/material.js +6 -8
  121. data/{builtin/app/shaders/fog/vertex.ejs → lib/assets/javascripts/shaders/fog/vertex.glsl} +0 -0
  122. data/{builtin/app/shaders/functions/depth_map.ejs → lib/assets/javascripts/shaders/functions/depth_map.glsl} +0 -0
  123. data/{builtin/app/shaders/functions/lights.ejs → lib/assets/javascripts/shaders/functions/lights.glsl} +0 -0
  124. data/{builtin/app/shaders/functions/noise.ejs → lib/assets/javascripts/shaders/functions/noise.glsl} +0 -0
  125. data/lib/assets/javascripts/shaders/lighting/common.glsl +5 -0
  126. data/{builtin/app/shaders/lighting/fragment.ejs → lib/assets/javascripts/shaders/lighting/fragment.glsl} +0 -0
  127. data/{builtin/app → lib/assets/javascripts}/shaders/lighting/manifest.yml +0 -0
  128. data/{builtin/app → lib/assets/javascripts}/shaders/lighting/material.js +2 -4
  129. data/{builtin/app/shaders/lighting/vertex.ejs → lib/assets/javascripts/shaders/lighting/vertex.glsl} +0 -0
  130. data/{builtin/app/shaders/normal_map/common.ejs → lib/assets/javascripts/shaders/normal_map/common.glsl} +1 -1
  131. data/{builtin/app/shaders/normal_map/fragment.ejs → lib/assets/javascripts/shaders/normal_map/fragment.glsl} +0 -0
  132. data/{builtin/app → lib/assets/javascripts}/shaders/normal_map/manifest.yml +0 -0
  133. data/lib/assets/javascripts/shaders/normal_map/material.js +11 -0
  134. data/{builtin/app/shaders/normal_map/vertex.ejs → lib/assets/javascripts/shaders/normal_map/vertex.glsl} +0 -0
  135. data/{builtin/app/shaders/paraboloid/common.ejs → lib/assets/javascripts/shaders/paraboloid/common.glsl} +0 -0
  136. data/{builtin/app/shaders/paraboloid/fragment.ejs → lib/assets/javascripts/shaders/paraboloid/fragment.glsl} +0 -0
  137. data/{builtin/app → lib/assets/javascripts}/shaders/paraboloid/manifest.yml +0 -0
  138. data/{builtin/app → lib/assets/javascripts}/shaders/paraboloid/material.js +2 -4
  139. data/{builtin/app/shaders/paraboloid/vertex.ejs → lib/assets/javascripts/shaders/paraboloid/vertex.glsl} +0 -0
  140. data/{builtin/app/shaders/picking/common.ejs → lib/assets/javascripts/shaders/picking/common.glsl} +0 -0
  141. data/{builtin/app/shaders/picking/fragment.ejs → lib/assets/javascripts/shaders/picking/fragment.glsl} +0 -0
  142. data/{builtin/app → lib/assets/javascripts}/shaders/picking/material.js +2 -4
  143. data/{builtin/app/shaders/picking/vertex.ejs → lib/assets/javascripts/shaders/picking/vertex.glsl} +0 -0
  144. data/{builtin/app/shaders/shadow_map/common.ejs → lib/assets/javascripts/shaders/shadow_map/common.glsl} +2 -1
  145. data/{builtin/app/shaders/shadow_map/fragment.ejs → lib/assets/javascripts/shaders/shadow_map/fragment.glsl} +1 -1
  146. data/{builtin/app → lib/assets/javascripts}/shaders/shadow_map/manifest.yml +0 -0
  147. data/{builtin/app → lib/assets/javascripts}/shaders/shadow_map/material.js +4 -6
  148. data/{builtin/app/shaders/shadow_map/vertex.ejs → lib/assets/javascripts/shaders/shadow_map/vertex.glsl} +0 -0
  149. data/{builtin/app/shaders/texture/common.ejs → lib/assets/javascripts/shaders/texture/common.glsl} +0 -0
  150. data/{builtin/app/shaders/texture/fragment.ejs → lib/assets/javascripts/shaders/texture/fragment.glsl} +0 -0
  151. data/{builtin/app → lib/assets/javascripts}/shaders/texture/manifest.yml +0 -0
  152. data/lib/assets/javascripts/shaders/texture/material.js +17 -0
  153. data/{builtin/app/shaders/texture/vertex.ejs → lib/assets/javascripts/shaders/texture/vertex.glsl} +0 -0
  154. data/lib/generators/jax/all.rb +16 -0
  155. data/lib/generators/jax/application/application_generator.rb +48 -0
  156. data/lib/generators/jax/base/actions.rb +52 -0
  157. data/lib/generators/jax/base/coffee_generator.rb +30 -0
  158. data/lib/generators/jax/base/named_base.rb +17 -0
  159. data/lib/generators/jax/base/plugin_base.rb +108 -0
  160. data/lib/generators/jax/base/plugin_credentials.rb +99 -0
  161. data/lib/generators/jax/base/plugin_manifest.rb +75 -0
  162. data/lib/generators/jax/base/rails_base.rb +30 -0
  163. data/lib/generators/jax/base/source_root.rb +5 -0
  164. data/lib/generators/jax/controller/controller_generator.rb +37 -0
  165. data/lib/generators/jax/helper/helper_generator.rb +30 -0
  166. data/lib/generators/jax/install/install_generator.rb +27 -0
  167. data/lib/generators/jax/jax_generator.rb +13 -0
  168. data/lib/generators/jax/light/light_generator.rb +23 -0
  169. data/lib/{jax/generators → generators/jax}/material/USAGE +4 -8
  170. data/lib/generators/jax/material/material_generator.rb +112 -0
  171. data/lib/generators/jax/model/model_generator.rb +24 -0
  172. data/lib/generators/jax/plugin/plugin_generator.rb +72 -0
  173. data/lib/generators/jax/scaffold/scaffold_generator.rb +35 -0
  174. data/lib/generators/jax/shader/shader_generator.rb +38 -0
  175. data/lib/jax/commands/plugin_manager.rb +240 -0
  176. data/lib/jax/commands.rb +69 -0
  177. data/lib/jax/configuration.rb +64 -0
  178. data/lib/jax/directive_processor.rb +53 -0
  179. data/lib/jax/engine.rb +38 -54
  180. data/lib/jax/helper_methods.rb +3 -0
  181. data/lib/jax/rails/application.rb +34 -0
  182. data/lib/jax/resource_file.rb +29 -0
  183. data/lib/jax/script_loader.rb +68 -0
  184. data/lib/jax/server.rb +87 -0
  185. data/lib/jax/shader.rb +70 -172
  186. data/lib/jax/testing/rails_environment.rb +94 -0
  187. data/lib/jax/util/tar.rb +75 -0
  188. data/lib/jax/util.rb +3 -0
  189. data/lib/jax/version.rb +7 -8
  190. data/lib/jax.rb +23 -41
  191. data/spec/bin/jax_spec.rb +149 -0
  192. data/{lib/jax/generators/app/templates/app/models/.empty_directory → spec/fixtures/public/favicon.ico} +0 -0
  193. data/spec/fixtures/public/textures/brickwall.jpg +0 -0
  194. data/spec/fixtures/public/textures/jacks.jpg +0 -0
  195. data/spec/fixtures/public/textures/normal_map.jpg +0 -0
  196. data/spec/fixtures/public/textures/rock.png +0 -0
  197. data/spec/fixtures/public/textures/rock_normal.png +0 -0
  198. data/spec/fixtures/public/textures/rss.png +0 -0
  199. data/spec/generators/jax/application_generator_spec.rb +18 -0
  200. data/spec/generators/jax/controller_generator_spec.rb +102 -0
  201. data/spec/generators/jax/helper_generator_spec.rb +55 -0
  202. data/spec/generators/jax/install_generator_spec.rb +30 -0
  203. data/spec/generators/jax/jax_generator_spec.rb +21 -0
  204. data/spec/generators/jax/light_generator_spec.rb +27 -0
  205. data/spec/generators/jax/material_generator_spec.rb +62 -0
  206. data/spec/generators/jax/model_generator_spec.rb +72 -0
  207. data/spec/generators/jax/plugin_generator_spec.rb +143 -0
  208. data/spec/generators/jax/scaffold_generator_spec.rb +35 -0
  209. data/spec/generators/jax/shader_generator_spec.rb +37 -0
  210. data/spec/javascripts/helpers/jasmine_webgl_helper.js +13 -0
  211. data/{lib/jax/generators/app/templates/spec/javascripts/support/spec_helpers → spec/javascripts/helpers}/jax_spec_environment_helper.js +7 -2
  212. data/{lib/jax/generators/app/templates/spec/javascripts/support/spec_helpers → spec/javascripts/helpers}/jax_spec_helper.js +0 -0
  213. data/spec/javascripts/jax/builtin/meshes/cube_spec.js +10 -0
  214. data/spec/javascripts/jax/builtin/meshes/plane_spec.js +8 -0
  215. data/spec/javascripts/jax/builtin/meshes/quad_spec.js +8 -0
  216. data/spec/javascripts/jax/builtin/meshes/sphere_spec.js +8 -0
  217. data/spec/javascripts/jax/builtin/meshes/teapot_spec.js +8 -0
  218. data/spec/javascripts/jax/builtin/meshes/torus_spec.js +8 -0
  219. data/spec/javascripts/jax/compatibility_spec.js +46 -0
  220. data/spec/javascripts/jax/context_events_spec.js +212 -0
  221. data/spec/javascripts/jax/context_spec.js +305 -0
  222. data/spec/javascripts/jax/core/data_region_spec.js +118 -0
  223. data/spec/javascripts/jax/core/data_segment_spec.js +96 -0
  224. data/spec/javascripts/jax/core/delegation_spec.js +48 -0
  225. data/spec/javascripts/jax/core/events_spec.js +17 -0
  226. data/spec/javascripts/jax/core/glMatrix_extensions_spec.js +8 -0
  227. data/spec/javascripts/jax/core/helper_spec.js +61 -0
  228. data/spec/javascripts/jax/core/matrix_stack_spec.js +28 -0
  229. data/spec/javascripts/jax/core/utils_spec.js +275 -0
  230. data/spec/javascripts/jax/geometry/line_spec.js +20 -0
  231. data/spec/javascripts/jax/geometry/plane_spec.js +181 -0
  232. data/spec/javascripts/jax/geometry/triangle_spec.js +105 -0
  233. data/spec/javascripts/jax/mvc/controller_spec.js +156 -0
  234. data/spec/javascripts/jax/mvc/model_spec.js +93 -0
  235. data/spec/javascripts/jax/mvc/route_set_spec.js +49 -0
  236. data/spec/javascripts/jax/mvc/view_manager_spec.js +17 -0
  237. data/spec/javascripts/jax/noise_spec.js +50 -0
  238. data/spec/javascripts/jax/optimizations/material_limitations_spec.js +85 -0
  239. data/spec/javascripts/jax/optimizations/shaders/basic_spec.js +65 -0
  240. data/spec/javascripts/jax/prototype/extensions_spec.js +34 -0
  241. data/spec/javascripts/jax/webgl/camera_spec.js +237 -0
  242. data/spec/javascripts/jax/webgl/core/events_spec.js +47 -0
  243. data/spec/javascripts/jax/webgl/framebuffer_spec.js +44 -0
  244. data/spec/javascripts/jax/webgl/lighting_spec.js +108 -0
  245. data/spec/javascripts/jax/webgl/material_spec.js +117 -0
  246. data/spec/javascripts/jax/webgl/mesh_spec.js +228 -0
  247. data/spec/javascripts/jax/webgl/shader/manifest_spec.js +57 -0
  248. data/spec/javascripts/jax/webgl/shader_chain_spec.js +211 -0
  249. data/spec/javascripts/jax/webgl/shader_spec.js +276 -0
  250. data/spec/javascripts/jax/webgl/tangent_space_spec.js +142 -0
  251. data/spec/javascripts/jax/webgl/texture_spec.js +159 -0
  252. data/spec/javascripts/jax/webgl_spec.js +5 -0
  253. data/spec/javascripts/jax/world_spec.js +175 -0
  254. data/spec/javascripts/jax_spec.js +14 -0
  255. data/spec/javascripts/node/mocks/webgl.js +159 -0
  256. data/spec/javascripts/node_helper.js +51 -0
  257. data/spec/javascripts/shaders/core_materials_spec.js +38 -0
  258. data/spec/javascripts/shaders/fog_spec.js +15 -0
  259. data/spec/javascripts/shaders/lighting_spec.js +15 -0
  260. data/spec/javascripts/shaders/normal_map_spec.js +15 -0
  261. data/spec/javascripts/shaders/paraboloid_spec.js +33 -0
  262. data/spec/javascripts/shaders/preprocessor_spec.js +45 -0
  263. data/spec/javascripts/shaders/shadow_map_spec.js +15 -0
  264. data/spec/javascripts/shaders/texture_spec.js +37 -0
  265. data/spec/javascripts/suite/controller_select_spec.js.coffee +24 -0
  266. data/spec/lib/jax/commands/plugin_manager/credentials_spec.rb +56 -0
  267. data/spec/lib/jax/commands/plugin_manager/push_spec.rb +62 -0
  268. data/spec/lib/jax/commands/plugin_manager_spec.rb +204 -0
  269. data/spec/lib/jax/rails/application_spec.rb +23 -0
  270. data/spec/lib/jax/shader_spec.rb +67 -0
  271. data/spec/lib/jax/util/tar_spec.rb +26 -0
  272. data/spec/{test_helper.rb → spec_helper.rb} +37 -28
  273. data/spec/support/test_model_generator.rb +14 -0
  274. data/templates/app/Gemfile.tt +17 -0
  275. data/templates/app/Rakefile +4 -0
  276. data/templates/app/config/application.rb +16 -0
  277. data/{lib/jax/generators/app/templates → templates/app}/config/boot.rb +0 -0
  278. data/templates/app/config/environment.rb +5 -0
  279. data/templates/app/config/environments/production.rb +4 -0
  280. data/templates/app/config.ru +6 -0
  281. data/{lib/jax/generators/app/templates/app/resources → templates/app/public}/.empty_directory +0 -0
  282. data/templates/app/script/jax +8 -0
  283. data/{lib/jax/generators/app/templates/app/views → templates/app/spec}/.empty_directory +0 -0
  284. data/templates/application_controller.js.coffee.erb +3 -0
  285. data/templates/application_controller.js.erb +6 -0
  286. data/templates/application_helper.js.coffee.erb +3 -0
  287. data/templates/application_helper.js.erb +3 -0
  288. data/templates/controller.js.coffee.erb +9 -0
  289. data/templates/controller.js.erb +15 -0
  290. data/templates/controller_spec.js.coffee.erb +9 -0
  291. data/templates/controller_spec.js.erb +12 -0
  292. data/templates/helper.js.coffee.erb +2 -0
  293. data/templates/helper.js.erb +3 -0
  294. data/templates/helper_spec.js.coffee.erb +8 -0
  295. data/templates/helper_spec.js.erb +12 -0
  296. data/{lib/jax/generators/light_source/templates/light.yml.tt → templates/light_source.resource.erb} +3 -3
  297. data/{lib/jax/generators/material/templates/material.yml.tt → templates/material.resource.erb} +0 -9
  298. data/templates/model.js.coffee.erb +3 -0
  299. data/templates/model.js.erb +5 -0
  300. data/templates/model_defaults.resource.erb +5 -0
  301. data/templates/model_spec.js.coffee.erb +16 -0
  302. data/templates/model_spec.js.erb +18 -0
  303. data/{lib/jax/generators/plugin/templates/new_plugin/app → templates/new_plugin/app/assets/jax}/controllers/.empty_directory +0 -0
  304. data/{lib/jax/generators/plugin/templates/new_plugin/app → templates/new_plugin/app/assets/jax}/helpers/.empty_directory +0 -0
  305. data/{lib/jax/generators/plugin/templates/new_plugin/app → templates/new_plugin/app/assets/jax}/models/.empty_directory +0 -0
  306. data/{lib/jax/generators/plugin/templates/new_plugin/app → templates/new_plugin/app/assets/jax}/resources/.empty_directory +0 -0
  307. data/{lib/jax/generators/plugin/templates/new_plugin/app → templates/new_plugin/app/assets/jax}/views/.empty_directory +0 -0
  308. data/{lib/jax/generators/plugin/templates → templates}/new_plugin/init.rb +0 -0
  309. data/{lib/jax/generators/plugin/templates → templates}/new_plugin/install.rb +0 -0
  310. data/{lib/jax/generators/plugin/templates/new_plugin/public → templates/new_plugin/spec}/.empty_directory +0 -0
  311. data/{lib/jax/generators/plugin/templates → templates}/new_plugin/uninstall.rb +0 -0
  312. data/{lib/jax/generators/shader/templates/common.ejs.tt → templates/shader_common.glsl.erb} +0 -0
  313. data/{lib/jax/generators/shader/templates/fragment.ejs.tt → templates/shader_fragment.glsl.erb} +0 -0
  314. data/{lib/jax/generators/shader/templates/manifest.yml.tt → templates/shader_manifest.yml.erb} +0 -0
  315. data/templates/shader_material.js.coffee.erb +22 -0
  316. data/{lib/jax/generators/shader/templates/material.js.tt → templates/shader_material.js.erb} +0 -0
  317. data/templates/shader_spec.js.coffee.erb +16 -0
  318. data/{lib/jax/generators/shader/templates/spec.js.tt → templates/shader_spec.js.erb} +1 -1
  319. data/{lib/jax/generators/shader/templates/vertex.ejs.tt → templates/shader_vertex.glsl.erb} +0 -0
  320. data/templates/view.js.coffee.erb +3 -0
  321. data/{lib/jax/generators/controller/templates/view.js.tt → templates/view.js.erb} +1 -1
  322. data/vendor/assets/javascripts/ejs.js +505 -0
  323. data/vendor/assets/javascripts/glMatrix.js +1772 -0
  324. data/vendor/assets/javascripts/jasmine.js +2476 -0
  325. data/vendor/assets/stylesheets/jasmine.css +166 -0
  326. data/vendor/pdoc_template/html/assets/images/pdoc/alias.png +0 -0
  327. data/vendor/pdoc_template/html/assets/images/pdoc/class.png +0 -0
  328. data/vendor/pdoc_template/html/assets/images/pdoc/class_deprecated.png +0 -0
  329. data/vendor/pdoc_template/html/assets/images/pdoc/class_method.png +0 -0
  330. data/vendor/pdoc_template/html/assets/images/pdoc/class_property.png +0 -0
  331. data/vendor/pdoc_template/html/assets/images/pdoc/constant.png +0 -0
  332. data/vendor/pdoc_template/html/assets/images/pdoc/constructor.png +0 -0
  333. data/vendor/pdoc_template/html/assets/images/pdoc/deprecated.png +0 -0
  334. data/vendor/pdoc_template/html/assets/images/pdoc/description.png +0 -0
  335. data/vendor/pdoc_template/html/assets/images/pdoc/information.png +0 -0
  336. data/vendor/pdoc_template/html/assets/images/pdoc/instance_method.png +0 -0
  337. data/vendor/pdoc_template/html/assets/images/pdoc/instance_property.png +0 -0
  338. data/vendor/pdoc_template/html/assets/images/pdoc/method.png +0 -0
  339. data/vendor/pdoc_template/html/assets/images/pdoc/method_deprecated.png +0 -0
  340. data/vendor/pdoc_template/html/assets/images/pdoc/mixin.png +0 -0
  341. data/vendor/pdoc_template/html/assets/images/pdoc/namespace.png +0 -0
  342. data/vendor/pdoc_template/html/assets/images/pdoc/property.png +0 -0
  343. data/vendor/pdoc_template/html/assets/images/pdoc/related_to.png +0 -0
  344. data/vendor/pdoc_template/html/assets/images/pdoc/search-background.png +0 -0
  345. data/vendor/pdoc_template/html/assets/images/pdoc/section-background.png +0 -0
  346. data/vendor/pdoc_template/html/assets/images/pdoc/section.png +0 -0
  347. data/vendor/pdoc_template/html/assets/images/pdoc/selected-section-background.png +0 -0
  348. data/vendor/pdoc_template/html/assets/images/pdoc/subclass.png +0 -0
  349. data/vendor/pdoc_template/html/assets/images/pdoc/superclass.png +0 -0
  350. data/vendor/pdoc_template/html/assets/images/pdoc/utility.png +0 -0
  351. data/vendor/pdoc_template/html/assets/javascripts/pdoc/application.js +478 -0
  352. data/vendor/pdoc_template/html/assets/javascripts/pdoc/prototype.js +4874 -0
  353. data/vendor/pdoc_template/html/assets/javascripts/pdoc/tabs.js +506 -0
  354. data/vendor/pdoc_template/html/assets/stylesheets/jax.css +30 -0
  355. data/vendor/pdoc_template/html/assets/stylesheets/pdoc/api.css +681 -0
  356. data/vendor/pdoc_template/html/assets/stylesheets/pdoc/pygments.css +62 -0
  357. data/vendor/pdoc_template/html/helpers.rb +35 -0
  358. data/vendor/pdoc_template/html/index.erb +18 -0
  359. data/vendor/pdoc_template/html/item_index.js.erb +6 -0
  360. data/vendor/pdoc_template/html/layout.erb +67 -0
  361. data/vendor/pdoc_template/html/leaf.erb +22 -0
  362. data/vendor/pdoc_template/html/node.erb +30 -0
  363. data/vendor/pdoc_template/html/partials/class_relationships.erb +19 -0
  364. data/vendor/pdoc_template/html/partials/classes.erb +7 -0
  365. data/vendor/pdoc_template/html/partials/constructor.erb +5 -0
  366. data/vendor/pdoc_template/html/partials/description.erb +5 -0
  367. data/vendor/pdoc_template/html/partials/link_list.erb +1 -0
  368. data/vendor/pdoc_template/html/partials/method_signatures.erb +14 -0
  369. data/vendor/pdoc_template/html/partials/methodized_note.erb +9 -0
  370. data/vendor/pdoc_template/html/partials/mixins.erb +7 -0
  371. data/vendor/pdoc_template/html/partials/namespaces.erb +7 -0
  372. data/vendor/pdoc_template/html/partials/related_utilities.erb +5 -0
  373. data/vendor/pdoc_template/html/partials/relationships.erb +11 -0
  374. data/vendor/pdoc_template/html/partials/short_description_list.erb +7 -0
  375. data/vendor/pdoc_template/html/partials/title.erb +24 -0
  376. data/vendor/pdoc_template/html/section.erb +18 -0
  377. metadata +635 -332
  378. data/builtin/app/shaders/lighting/common.ejs +0 -5
  379. data/builtin/app/shaders/normal_map/material.js +0 -16
  380. data/builtin/app/shaders/texture/material.js +0 -18
  381. data/jax.gems +0 -1
  382. data/lib/jax/application/builtin/configurable.rb +0 -5
  383. data/lib/jax/application/builtin/configuration.rb +0 -5
  384. data/lib/jax/application/builtin.rb +0 -12
  385. data/lib/jax/application/configurable.rb +0 -19
  386. data/lib/jax/application/configuration.rb +0 -60
  387. data/lib/jax/application/railties.rb +0 -26
  388. data/lib/jax/application.rb +0 -149
  389. data/lib/jax/core_ext/kernel.rb +0 -7
  390. data/lib/jax/engine/configurable.rb +0 -19
  391. data/lib/jax/engine/configuration.rb +0 -49
  392. data/lib/jax/generators/app/app_generator.rb +0 -96
  393. data/lib/jax/generators/app/templates/Gemfile.tt +0 -3
  394. data/lib/jax/generators/app/templates/Rakefile +0 -6
  395. data/lib/jax/generators/app/templates/app/controllers/application_controller.js.tt +0 -5
  396. data/lib/jax/generators/app/templates/app/helpers/application_helper.js.tt +0 -3
  397. data/lib/jax/generators/app/templates/config/application.rb.tt +0 -6
  398. data/lib/jax/generators/app/templates/config/environment.rb.tt +0 -5
  399. data/lib/jax/generators/app/templates/config/routes.rb.tt +0 -5
  400. data/lib/jax/generators/app/templates/public/index.html.tt +0 -26
  401. data/lib/jax/generators/app/templates/public/javascripts/jax.js +0 -9462
  402. data/lib/jax/generators/app/templates/public/stylesheets/%file_name%.css.tt +0 -11
  403. data/lib/jax/generators/app/templates/public/webgl_not_supported.html +0 -26
  404. data/lib/jax/generators/app/templates/script/jax +0 -7
  405. data/lib/jax/generators/app/templates/spec/javascripts/controllers/application_controller_spec.js +0 -11
  406. data/lib/jax/generators/app/templates/spec/javascripts/helpers/application_helper_spec.js +0 -12
  407. data/lib/jax/generators/app/templates/spec/javascripts/support/jasmine.yml +0 -91
  408. data/lib/jax/generators/app/templates/spec/javascripts/support/jasmine_config.rb +0 -23
  409. data/lib/jax/generators/app/templates/spec/javascripts/support/jasmine_runner.rb +0 -32
  410. data/lib/jax/generators/app/templates/spec/javascripts/support/spec_layout.html.erb +0 -104
  411. data/lib/jax/generators/app.rb +0 -18
  412. data/lib/jax/generators/commands.rb +0 -220
  413. data/lib/jax/generators/controller/USAGE +0 -9
  414. data/lib/jax/generators/controller/controller_generator.rb +0 -66
  415. data/lib/jax/generators/controller/templates/controller_source.js.tt +0 -16
  416. data/lib/jax/generators/controller/templates/controller_test.js.tt +0 -11
  417. data/lib/jax/generators/controller/templates/helper.js.tt +0 -3
  418. data/lib/jax/generators/controller/templates/helper_test.js.tt +0 -12
  419. data/lib/jax/generators/interactions.rb +0 -56
  420. data/lib/jax/generators/light_source/USAGE +0 -14
  421. data/lib/jax/generators/light_source/light_source_generator.rb +0 -46
  422. data/lib/jax/generators/material/material_generator.rb +0 -80
  423. data/lib/jax/generators/material/templates/append.yml.tt +0 -7
  424. data/lib/jax/generators/model/USAGE +0 -5
  425. data/lib/jax/generators/model/model_generator.rb +0 -40
  426. data/lib/jax/generators/model/templates/model.js.tt +0 -11
  427. data/lib/jax/generators/model/templates/test.js.tt +0 -11
  428. data/lib/jax/generators/packager/package_generator.rb +0 -32
  429. data/lib/jax/generators/plugin/USAGE +0 -4
  430. data/lib/jax/generators/plugin/all.rb +0 -113
  431. data/lib/jax/generators/plugin/credentials.rb +0 -108
  432. data/lib/jax/generators/plugin/plugin_generator.rb +0 -72
  433. data/lib/jax/generators/plugin/plugin_manager.rb +0 -254
  434. data/lib/jax/generators/plugin/templates/new_plugin/config/routes.rb +0 -3
  435. data/lib/jax/generators/plugin/templates/new_plugin/spec/.empty_directory +0 -0
  436. data/lib/jax/generators/script_jax_loader.rb +0 -49
  437. data/lib/jax/generators/shader/USAGE +0 -4
  438. data/lib/jax/generators/shader/shader_generator.rb +0 -70
  439. data/lib/jax/monkeypatch/jasmine/config.rb +0 -45
  440. data/lib/jax/monkeypatch/jasmine/server.rb +0 -50
  441. data/lib/jax/monkeypatch/jasmine.rb +0 -3
  442. data/lib/jax/packager/sprockets_template.rb +0 -77
  443. data/lib/jax/packager.rb +0 -59
  444. data/lib/jax/plugin/manifest.rb +0 -71
  445. data/lib/jax/plugin.rb +0 -49
  446. data/lib/jax/resource_compiler.rb +0 -60
  447. data/lib/jax/routes.rb +0 -62
  448. data/lib/jax/tasks/rake.rb +0 -38
  449. data/spec/benchmark.htm +0 -93
  450. data/spec/generators/app_generator_test.rb +0 -42
  451. data/spec/generators/controller_generator_test.rb +0 -47
  452. data/spec/generators/light_generator_test.rb +0 -37
  453. data/spec/generators/material_generator_test.rb +0 -22
  454. data/spec/generators/model_generator_test.rb +0 -26
  455. data/spec/generators/plugin_generator_test.rb +0 -114
  456. data/spec/generators/plugin_manager/push_test.rb +0 -59
  457. data/spec/generators/plugin_manager_test.rb +0 -192
  458. data/spec/generators/shader_generator_test.rb +0 -38
  459. data/spec/javascripts/support/jasmine.yml +0 -85
  460. data/spec/javascripts/support/jasmine_runner.rb +0 -32
  461. data/spec/lib/jax/application_test.rb +0 -18
  462. data/spec/lib/jax/generators/plugin/credentials_test.rb +0 -72
  463. data/spec/lib/jax/packager_test.rb +0 -87
  464. data/spec/lib/jax/plugin_test.rb +0 -27
  465. data/spec/lib/jax/reloading_test.rb +0 -23
  466. data/spec/lib/jax/routes_test.rb +0 -28
  467. data/spec/lib/jax/shader_test.rb +0 -29
  468. data/spec/lib/jax/tasks/jax_rake_test.rb +0 -85
  469. data/spec/support/bases/generator_test_case.rb +0 -108
  470. data/spec/support/bases/isolated_test_case.rb +0 -148
  471. data/spec/support/file_exist_matcher.rb +0 -23
  472. data/spec/support/spec_shell.rb +0 -110
  473. data/spec/test_app.rb +0 -3
@@ -0,0 +1,1772 @@
1
+ /*
2
+ * glMatrix.js - High performance matrix and vector operations for WebGL
3
+ * version 0.9.5
4
+ */
5
+
6
+ /*
7
+ * Copyright (c) 2010 Brandon Jones
8
+ *
9
+ * This software is provided 'as-is', without any express or implied
10
+ * warranty. In no event will the authors be held liable for any damages
11
+ * arising from the use of this software.
12
+ *
13
+ * Permission is granted to anyone to use this software for any purpose,
14
+ * including commercial applications, and to alter it and redistribute it
15
+ * freely, subject to the following restrictions:
16
+ *
17
+ * 1. The origin of this software must not be misrepresented; you must not
18
+ * claim that you wrote the original software. If you use this software
19
+ * in a product, an acknowledgment in the product documentation would be
20
+ * appreciated but is not required.
21
+ *
22
+ * 2. Altered source versions must be plainly marked as such, and must not
23
+ * be misrepresented as being the original software.
24
+ *
25
+ * 3. This notice may not be removed or altered from any source
26
+ * distribution.
27
+ */
28
+
29
+ // Fallback for systems that don't support WebGL
30
+ if(typeof Float32Array != 'undefined') {
31
+ glMatrixArrayType = Float32Array;
32
+ } else if(typeof WebGLFloatArray != 'undefined') {
33
+ glMatrixArrayType = WebGLFloatArray; // This is officially deprecated and should dissapear in future revisions.
34
+ } else {
35
+ glMatrixArrayType = Array;
36
+ }
37
+
38
+ /**
39
+ * vec3
40
+ * 3 Dimensional Vector
41
+ **/
42
+ var vec3 = {};
43
+
44
+ /**
45
+ * vec3.create([vec]) -> vec3
46
+ * - vec (vec3): optional vec3 containing values to initialize with
47
+ *
48
+ * Creates a new instance of a vec3 using the default array type
49
+ * Any javascript array containing at least 3 numeric elements can serve as a vec3
50
+ *
51
+ * Returns:
52
+ * New vec3
53
+ **/
54
+ vec3.create = function(vec) {
55
+ var dest = new glMatrixArrayType(3);
56
+
57
+ if(vec) {
58
+ dest[0] = vec[0];
59
+ dest[1] = vec[1];
60
+ dest[2] = vec[2];
61
+ }
62
+
63
+ return dest;
64
+ };
65
+
66
+ /**
67
+ * vec3.set(vec, dest) -> vec3
68
+ * - vec (vec3) : vec3 containing values to copy
69
+ * - dest (vec3) : vec3 receiving copied values
70
+ *
71
+ * Copies the values of one vec3 to another
72
+ *
73
+ * Returns:
74
+ * dest
75
+ **/
76
+ vec3.set = function(vec, dest) {
77
+ dest[0] = vec[0];
78
+ dest[1] = vec[1];
79
+ dest[2] = vec[2];
80
+
81
+ return dest;
82
+ };
83
+
84
+ /**
85
+ * vec3.add(vec, vec2[, dest]) -> vec3
86
+ * - vec (vec3) : first operand
87
+ * - vec2 (vec3) : second operand
88
+ * - dest (vec3) : optional vec3 receiving operation result. If not specified, result is written to +vec+.
89
+ *
90
+ * Performs a vector addition
91
+ *
92
+ * Returns:
93
+ * dest if specified, vec otherwise
94
+ **/
95
+ vec3.add = function(vec, vec2, dest) {
96
+ if(!dest || vec == dest) {
97
+ vec[0] += vec2[0];
98
+ vec[1] += vec2[1];
99
+ vec[2] += vec2[2];
100
+ return vec;
101
+ }
102
+
103
+ dest[0] = vec[0] + vec2[0];
104
+ dest[1] = vec[1] + vec2[1];
105
+ dest[2] = vec[2] + vec2[2];
106
+ return dest;
107
+ };
108
+
109
+ /**
110
+ * vec3.subtract(vec, vec2[, dest]) -> vec3
111
+ * - vec (vec3) : first operand
112
+ * - vec2 (vec3) : second operand
113
+ * - dest (vec3) : optional vec3 receiving operation result. If not specified, result is written to +vec+.
114
+ *
115
+ * Performs a vector subtraction
116
+ *
117
+ * Returns:
118
+ * dest if specified, vec otherwise
119
+ **/
120
+ vec3.subtract = function(vec, vec2, dest) {
121
+ if(!dest || vec == dest) {
122
+ vec[0] -= vec2[0];
123
+ vec[1] -= vec2[1];
124
+ vec[2] -= vec2[2];
125
+ return vec;
126
+ }
127
+
128
+ dest[0] = vec[0] - vec2[0];
129
+ dest[1] = vec[1] - vec2[1];
130
+ dest[2] = vec[2] - vec2[2];
131
+ return dest;
132
+ };
133
+
134
+ /**
135
+ * vec3.negate(vec[, dest]) -> vec3
136
+ * - vec (vec3) : vec3 to negate
137
+ * - dest (vec3) : optional vec3 receiving operation result. If not specified, result is written to +vec+.
138
+ *
139
+ * Negates the components of a vec3
140
+ *
141
+ * Returns:
142
+ * dest if specified, vec otherwise
143
+ **/
144
+ vec3.negate = function(vec, dest) {
145
+ if(!dest) { dest = vec; }
146
+
147
+ dest[0] = -vec[0];
148
+ dest[1] = -vec[1];
149
+ dest[2] = -vec[2];
150
+ return dest;
151
+ };
152
+
153
+ /**
154
+ * vec3.scale(vec, val[, dest]) -> vec3
155
+ * - vec (vec3) : vec3 to scale
156
+ * - val (Number) : numeric value to scale by
157
+ * - dest (vec3) : optional vec3 receiving operation result. If not specified, result is written to +vec+.
158
+ *
159
+ * Multiplies the components of a vec3 by a scalar value
160
+ *
161
+ * Returns:
162
+ * dest if specified, vec otherwise
163
+ **/
164
+ vec3.scale = function(vec, val, dest) {
165
+ if(!dest || vec == dest) {
166
+ vec[0] *= val;
167
+ vec[1] *= val;
168
+ vec[2] *= val;
169
+ return vec;
170
+ }
171
+
172
+ dest[0] = vec[0]*val;
173
+ dest[1] = vec[1]*val;
174
+ dest[2] = vec[2]*val;
175
+ return dest;
176
+ };
177
+
178
+ /**
179
+ * vec3.normalize(vec[, dest]) -> vec3
180
+ * - vec (vec3) : vec3 to normalize
181
+ * - dest (vec3) : optional vec3 receiving operation result. If not specified, result is written to +vec+.
182
+ *
183
+ * Generates a unit vector of the same direction as the provided vec3
184
+ * If vector length is 0, returns [0, 0, 0]
185
+ *
186
+ * Returns:
187
+ * dest if specified, vec otherwise
188
+ **/
189
+ vec3.normalize = function(vec, dest) {
190
+ if(!dest) { dest = vec; }
191
+
192
+ var x = vec[0], y = vec[1], z = vec[2];
193
+ var len = Math.sqrt(x*x + y*y + z*z);
194
+
195
+ if (!len) {
196
+ dest[0] = 0;
197
+ dest[1] = 0;
198
+ dest[2] = 0;
199
+ return dest;
200
+ } else if (len == 1) {
201
+ dest[0] = x;
202
+ dest[1] = y;
203
+ dest[2] = z;
204
+ return dest;
205
+ }
206
+
207
+ len = 1 / len;
208
+ dest[0] = x*len;
209
+ dest[1] = y*len;
210
+ dest[2] = z*len;
211
+ return dest;
212
+ };
213
+
214
+ /**
215
+ * vec3.cross(vec, vec2[, dest]) -> vec3
216
+ * - vec (vec3) : first operand
217
+ * - vec2 (vec3) : second operand
218
+ * - dest (vec3) : optional vec3 receiving operation result. If not specified, result is written to +vec+.
219
+ *
220
+ * Generates the cross product of two vec3s
221
+ *
222
+ * Returns:
223
+ * dest if specified, vec otherwise
224
+ **/
225
+ vec3.cross = function(vec, vec2, dest){
226
+ if(!dest) { dest = vec; }
227
+
228
+ var x = vec[0], y = vec[1], z = vec[2];
229
+ var x2 = vec2[0], y2 = vec2[1], z2 = vec2[2];
230
+
231
+ dest[0] = y*z2 - z*y2;
232
+ dest[1] = z*x2 - x*z2;
233
+ dest[2] = x*y2 - y*x2;
234
+ return dest;
235
+ };
236
+
237
+ /**
238
+ * vec3.length(vec) -> Number
239
+ * - vec (vec3) : vec3 to calculate length of
240
+ *
241
+ * Caclulates the length of a vec3
242
+ *
243
+ * Returns:
244
+ * Length of vec
245
+ **/
246
+ vec3.length = function(vec){
247
+ var x = vec[0], y = vec[1], z = vec[2];
248
+ return Math.sqrt(x*x + y*y + z*z);
249
+ };
250
+
251
+ /**
252
+ * vec3.dot(vec, vec2) -> Number
253
+ * - vec (vec3) : first operand
254
+ * - vec2 (vec3) : second operand
255
+ *
256
+ * Caclulates the dot product of two vec3s
257
+ *
258
+ * Returns:
259
+ * Dot product of vec and vec2
260
+ **/
261
+ vec3.dot = function(vec, vec2){
262
+ return vec[0]*vec2[0] + vec[1]*vec2[1] + vec[2]*vec2[2];
263
+ };
264
+
265
+ /**
266
+ * vec3.direction(vec, vec2[, dest]) -> vec3
267
+ * - vec (vec3) : origin vec3
268
+ * - vec2 (vec3) : vec3 to point to
269
+ * - dest (vec3) : optional vec3 receiving operation result. If not specified, result is written to +vec+.
270
+ *
271
+ * Generates a unit vector pointing from one vector to another
272
+ *
273
+ * Returns:
274
+ * dest if specified, vec otherwise
275
+ **/
276
+ vec3.direction = function(vec, vec2, dest) {
277
+ if(!dest) { dest = vec; }
278
+
279
+ var x = vec[0] - vec2[0];
280
+ var y = vec[1] - vec2[1];
281
+ var z = vec[2] - vec2[2];
282
+
283
+ var len = Math.sqrt(x*x + y*y + z*z);
284
+ if (!len) {
285
+ dest[0] = 0;
286
+ dest[1] = 0;
287
+ dest[2] = 0;
288
+ return dest;
289
+ }
290
+
291
+ len = 1 / len;
292
+ dest[0] = x * len;
293
+ dest[1] = y * len;
294
+ dest[2] = z * len;
295
+ return dest;
296
+ };
297
+
298
+ /**
299
+ * vec3.lerp(vec, vec2, lerp[, dest]) -> vec3
300
+ * - vec (vec3) : first vector
301
+ * - vec2 (vec3) : second vector
302
+ * - lerp (Number) : interpolation amount between the two inputs
303
+ * - dest (vec3) : optional vec3 receiving operation result. If not specified, result is written to +vec+.
304
+ *
305
+ * Performs a linear interpolation between two vec3
306
+ *
307
+ * Returns:
308
+ * dest if specified, vec otherwise
309
+ **/
310
+ vec3.lerp = function(vec, vec2, lerp, dest){
311
+ if(!dest) { dest = vec; }
312
+
313
+ dest[0] = vec[0] + lerp * (vec2[0] - vec[0]);
314
+ dest[1] = vec[1] + lerp * (vec2[1] - vec[1]);
315
+ dest[2] = vec[2] + lerp * (vec2[2] - vec[2]);
316
+
317
+ return dest;
318
+ }
319
+
320
+ /**
321
+ * vec3.str(vec) -> String
322
+ * - vec (vec3) : vec3 to represent as a string
323
+ *
324
+ * Returns a string representation of a vector
325
+ *
326
+ * Returns:
327
+ * string representation of vec
328
+ **/
329
+ vec3.str = function(vec) {
330
+ return '[' + vec[0] + ', ' + vec[1] + ', ' + vec[2] + ']';
331
+ };
332
+
333
+ /**
334
+ * mat3
335
+ * 3x3 Matrix
336
+ **/
337
+ var mat3 = {};
338
+
339
+ /**
340
+ * mat3.create([mat]) -> mat3
341
+ * - mat (mat3) : optional mat3 containing values to initialize with
342
+ *
343
+ * Creates a new instance of a mat3 using the default array type
344
+ * Any javascript array containing at least 9 numeric elements can serve as a mat3
345
+ *
346
+ * Returns:
347
+ * New mat3
348
+ **/
349
+ mat3.create = function(mat) {
350
+ var dest = new glMatrixArrayType(9);
351
+
352
+ if(mat) {
353
+ dest[0] = mat[0];
354
+ dest[1] = mat[1];
355
+ dest[2] = mat[2];
356
+ dest[3] = mat[3];
357
+ dest[4] = mat[4];
358
+ dest[5] = mat[5];
359
+ dest[6] = mat[6];
360
+ dest[7] = mat[7];
361
+ dest[8] = mat[8];
362
+ dest[9] = mat[9];
363
+ }
364
+
365
+ return dest;
366
+ };
367
+
368
+ /**
369
+ * mat3.set(mat, dest) -> mat3
370
+ * - mat (mat3) : mat3 containing values to copy
371
+ * - dest (mat3) : mat3 receiving copied values
372
+ *
373
+ * Copies the values of one mat3 to another
374
+ *
375
+ * Returns:
376
+ * dest
377
+ **/
378
+ mat3.set = function(mat, dest) {
379
+ dest[0] = mat[0];
380
+ dest[1] = mat[1];
381
+ dest[2] = mat[2];
382
+ dest[3] = mat[3];
383
+ dest[4] = mat[4];
384
+ dest[5] = mat[5];
385
+ dest[6] = mat[6];
386
+ dest[7] = mat[7];
387
+ dest[8] = mat[8];
388
+ return dest;
389
+ };
390
+
391
+ /**
392
+ * mat3.identity(dest) -> mat3
393
+ * - dest (mat3) : mat3 to set
394
+ *
395
+ * Sets a mat3 to an identity matrix
396
+ *
397
+ * Returns:
398
+ * dest
399
+ **/
400
+ mat3.identity = function(dest) {
401
+ dest[0] = 1;
402
+ dest[1] = 0;
403
+ dest[2] = 0;
404
+ dest[3] = 0;
405
+ dest[4] = 1;
406
+ dest[5] = 0;
407
+ dest[6] = 0;
408
+ dest[7] = 0;
409
+ dest[8] = 1;
410
+ return dest;
411
+ };
412
+
413
+ /**
414
+ * mat3.transpose(mat[, dest]) -> mat3
415
+ * - mat (mat3) : mat3 to transpose
416
+ * - dest (mat3) : optional mat3 receiving operation result. If not specified, result is written to +mat+.
417
+ *
418
+ * Transposes a mat3 (flips the values over the diagonal)
419
+ *
420
+ * Returns:
421
+ * dest if specified, mat otherwise
422
+ **/
423
+ mat3.transpose = function(mat, dest) {
424
+ // If we are transposing ourselves we can skip a few steps but have to cache some values
425
+ if(!dest || mat == dest) {
426
+ var a01 = mat[1], a02 = mat[2];
427
+ var a12 = mat[5];
428
+
429
+ mat[1] = mat[3];
430
+ mat[2] = mat[6];
431
+ mat[3] = a01;
432
+ mat[5] = mat[7];
433
+ mat[6] = a02;
434
+ mat[7] = a12;
435
+ return mat;
436
+ }
437
+
438
+ dest[0] = mat[0];
439
+ dest[1] = mat[3];
440
+ dest[2] = mat[6];
441
+ dest[3] = mat[1];
442
+ dest[4] = mat[4];
443
+ dest[5] = mat[7];
444
+ dest[6] = mat[2];
445
+ dest[7] = mat[5];
446
+ dest[8] = mat[8];
447
+ return dest;
448
+ };
449
+
450
+ /**
451
+ * mat3.toMat4(mat[, dest]) -> mat4
452
+ * - mat (mat3) : mat3 containing values to copy
453
+ * - dest (mat4) : optional mat4 receiving operation result. If not specified, result is written to a new mat4.
454
+ *
455
+ * Copies the elements of a mat3 into the upper 3x3 elements of a mat4
456
+ *
457
+ * Returns:
458
+ * dest if specified, a new mat4 otherwise
459
+ **/
460
+ mat3.toMat4 = function(mat, dest) {
461
+ if(!dest) { dest = mat4.create(); }
462
+
463
+ dest[0] = mat[0];
464
+ dest[1] = mat[1];
465
+ dest[2] = mat[2];
466
+ dest[3] = 0;
467
+
468
+ dest[4] = mat[3];
469
+ dest[5] = mat[4];
470
+ dest[6] = mat[5];
471
+ dest[7] = 0;
472
+
473
+ dest[8] = mat[6];
474
+ dest[9] = mat[7];
475
+ dest[10] = mat[8];
476
+ dest[11] = 0;
477
+
478
+ dest[12] = 0;
479
+ dest[13] = 0;
480
+ dest[14] = 0;
481
+ dest[15] = 1;
482
+
483
+ return dest;
484
+ }
485
+
486
+ /**
487
+ * mat3.str(mat) -> String
488
+ * - mat (mat3) : mat3 to represent as a string
489
+ *
490
+ * Returns a string representation of a mat3
491
+ *
492
+ * Returns:
493
+ * string representation of mat
494
+ **/
495
+ mat3.str = function(mat) {
496
+ return '[' + mat[0] + ', ' + mat[1] + ', ' + mat[2] +
497
+ ', ' + mat[3] + ', '+ mat[4] + ', ' + mat[5] +
498
+ ', ' + mat[6] + ', ' + mat[7] + ', '+ mat[8] + ']';
499
+ };
500
+
501
+ /**
502
+ * mat4
503
+ * 4x4 Matrix
504
+ **/
505
+ var mat4 = {};
506
+
507
+ /**
508
+ * mat4.create([mat]) -> mat4
509
+ * - mat (mat4) : optional mat4 containing values to initialize with
510
+ *
511
+ * Creates a new instance of a mat4 using the default array type
512
+ * Any javascript array containing at least 16 numeric elements can serve as a mat4
513
+ *
514
+ * Returns:
515
+ * New mat4
516
+ **/
517
+ mat4.create = function(mat) {
518
+ var dest = new glMatrixArrayType(16);
519
+
520
+ if(mat) {
521
+ dest[0] = mat[0];
522
+ dest[1] = mat[1];
523
+ dest[2] = mat[2];
524
+ dest[3] = mat[3];
525
+ dest[4] = mat[4];
526
+ dest[5] = mat[5];
527
+ dest[6] = mat[6];
528
+ dest[7] = mat[7];
529
+ dest[8] = mat[8];
530
+ dest[9] = mat[9];
531
+ dest[10] = mat[10];
532
+ dest[11] = mat[11];
533
+ dest[12] = mat[12];
534
+ dest[13] = mat[13];
535
+ dest[14] = mat[14];
536
+ dest[15] = mat[15];
537
+ }
538
+
539
+ return dest;
540
+ };
541
+
542
+ /**
543
+ * mat4.set(mat, dest) -> mat4
544
+ * - mat (mat4) : mat4 containing values to copy
545
+ * - dest (mat4) : mat4 receiving copied values
546
+ *
547
+ * Copies the values of one mat4 to another
548
+ *
549
+ * Returns:
550
+ * dest
551
+ **/
552
+ mat4.set = function(mat, dest) {
553
+ dest[0] = mat[0];
554
+ dest[1] = mat[1];
555
+ dest[2] = mat[2];
556
+ dest[3] = mat[3];
557
+ dest[4] = mat[4];
558
+ dest[5] = mat[5];
559
+ dest[6] = mat[6];
560
+ dest[7] = mat[7];
561
+ dest[8] = mat[8];
562
+ dest[9] = mat[9];
563
+ dest[10] = mat[10];
564
+ dest[11] = mat[11];
565
+ dest[12] = mat[12];
566
+ dest[13] = mat[13];
567
+ dest[14] = mat[14];
568
+ dest[15] = mat[15];
569
+ return dest;
570
+ };
571
+
572
+ /**
573
+ * mat4.identity(dest) -> mat4
574
+ * - dest (mat4) : mat4 to set
575
+ *
576
+ * Sets a mat4 to an identity matrix
577
+ *
578
+ * Returns:
579
+ * dest
580
+ **/
581
+ mat4.identity = function(dest) {
582
+ dest[0] = 1;
583
+ dest[1] = 0;
584
+ dest[2] = 0;
585
+ dest[3] = 0;
586
+ dest[4] = 0;
587
+ dest[5] = 1;
588
+ dest[6] = 0;
589
+ dest[7] = 0;
590
+ dest[8] = 0;
591
+ dest[9] = 0;
592
+ dest[10] = 1;
593
+ dest[11] = 0;
594
+ dest[12] = 0;
595
+ dest[13] = 0;
596
+ dest[14] = 0;
597
+ dest[15] = 1;
598
+ return dest;
599
+ };
600
+
601
+ /**
602
+ * mat4.transpose(mat[, dest]) -> mat4
603
+ * - mat (mat4) : mat4 to transpose
604
+ * - dest (mat4) : optional mat4 receiving operation result. If not specified, result is written to +mat+.
605
+ *
606
+ * Transposes a mat4 (flips the values over the diagonal)
607
+ *
608
+ * Returns:
609
+ * dest is specified, mat otherwise
610
+ **/
611
+ mat4.transpose = function(mat, dest) {
612
+ // If we are transposing ourselves we can skip a few steps but have to cache some values
613
+ if(!dest || mat == dest) {
614
+ var a01 = mat[1], a02 = mat[2], a03 = mat[3];
615
+ var a12 = mat[6], a13 = mat[7];
616
+ var a23 = mat[11];
617
+
618
+ mat[1] = mat[4];
619
+ mat[2] = mat[8];
620
+ mat[3] = mat[12];
621
+ mat[4] = a01;
622
+ mat[6] = mat[9];
623
+ mat[7] = mat[13];
624
+ mat[8] = a02;
625
+ mat[9] = a12;
626
+ mat[11] = mat[14];
627
+ mat[12] = a03;
628
+ mat[13] = a13;
629
+ mat[14] = a23;
630
+ return mat;
631
+ }
632
+
633
+ dest[0] = mat[0];
634
+ dest[1] = mat[4];
635
+ dest[2] = mat[8];
636
+ dest[3] = mat[12];
637
+ dest[4] = mat[1];
638
+ dest[5] = mat[5];
639
+ dest[6] = mat[9];
640
+ dest[7] = mat[13];
641
+ dest[8] = mat[2];
642
+ dest[9] = mat[6];
643
+ dest[10] = mat[10];
644
+ dest[11] = mat[14];
645
+ dest[12] = mat[3];
646
+ dest[13] = mat[7];
647
+ dest[14] = mat[11];
648
+ dest[15] = mat[15];
649
+ return dest;
650
+ };
651
+
652
+ /**
653
+ * mat4.determinant(mat) -> mat4
654
+ * - mat (mat4) : mat4 to calculate determinant of
655
+ *
656
+ * Calculates the determinant of a mat4
657
+ *
658
+ * Returns:
659
+ * determinant of mat
660
+ **/
661
+ mat4.determinant = function(mat) {
662
+ // Cache the matrix values (makes for huge speed increases!)
663
+ var a00 = mat[0], a01 = mat[1], a02 = mat[2], a03 = mat[3];
664
+ var a10 = mat[4], a11 = mat[5], a12 = mat[6], a13 = mat[7];
665
+ var a20 = mat[8], a21 = mat[9], a22 = mat[10], a23 = mat[11];
666
+ var a30 = mat[12], a31 = mat[13], a32 = mat[14], a33 = mat[15];
667
+
668
+ return a30*a21*a12*a03 - a20*a31*a12*a03 - a30*a11*a22*a03 + a10*a31*a22*a03 +
669
+ a20*a11*a32*a03 - a10*a21*a32*a03 - a30*a21*a02*a13 + a20*a31*a02*a13 +
670
+ a30*a01*a22*a13 - a00*a31*a22*a13 - a20*a01*a32*a13 + a00*a21*a32*a13 +
671
+ a30*a11*a02*a23 - a10*a31*a02*a23 - a30*a01*a12*a23 + a00*a31*a12*a23 +
672
+ a10*a01*a32*a23 - a00*a11*a32*a23 - a20*a11*a02*a33 + a10*a21*a02*a33 +
673
+ a20*a01*a12*a33 - a00*a21*a12*a33 - a10*a01*a22*a33 + a00*a11*a22*a33;
674
+ };
675
+
676
+ /**
677
+ * mat4.inverse(mat[, dest]) -> mat4
678
+ * - mat (mat4) : mat4 to calculate inverse of
679
+ * - dest (mat4) : optional mat4 receiving inverse matrix. If not specified, result is written to +mat+.
680
+ *
681
+ * Calculates the inverse matrix of a mat4
682
+ *
683
+ * Returns:
684
+ * dest is specified, mat otherwise
685
+ **/
686
+ mat4.inverse = function(mat, dest) {
687
+ if(!dest) { dest = mat; }
688
+
689
+ // Cache the matrix values (makes for huge speed increases!)
690
+ var a00 = mat[0], a01 = mat[1], a02 = mat[2], a03 = mat[3];
691
+ var a10 = mat[4], a11 = mat[5], a12 = mat[6], a13 = mat[7];
692
+ var a20 = mat[8], a21 = mat[9], a22 = mat[10], a23 = mat[11];
693
+ var a30 = mat[12], a31 = mat[13], a32 = mat[14], a33 = mat[15];
694
+
695
+ var b00 = a00*a11 - a01*a10;
696
+ var b01 = a00*a12 - a02*a10;
697
+ var b02 = a00*a13 - a03*a10;
698
+ var b03 = a01*a12 - a02*a11;
699
+ var b04 = a01*a13 - a03*a11;
700
+ var b05 = a02*a13 - a03*a12;
701
+ var b06 = a20*a31 - a21*a30;
702
+ var b07 = a20*a32 - a22*a30;
703
+ var b08 = a20*a33 - a23*a30;
704
+ var b09 = a21*a32 - a22*a31;
705
+ var b10 = a21*a33 - a23*a31;
706
+ var b11 = a22*a33 - a23*a32;
707
+
708
+ // Calculate the determinant (inlined to avoid double-caching)
709
+ var invDet = 1/(b00*b11 - b01*b10 + b02*b09 + b03*b08 - b04*b07 + b05*b06);
710
+
711
+ dest[0] = (a11*b11 - a12*b10 + a13*b09)*invDet;
712
+ dest[1] = (-a01*b11 + a02*b10 - a03*b09)*invDet;
713
+ dest[2] = (a31*b05 - a32*b04 + a33*b03)*invDet;
714
+ dest[3] = (-a21*b05 + a22*b04 - a23*b03)*invDet;
715
+ dest[4] = (-a10*b11 + a12*b08 - a13*b07)*invDet;
716
+ dest[5] = (a00*b11 - a02*b08 + a03*b07)*invDet;
717
+ dest[6] = (-a30*b05 + a32*b02 - a33*b01)*invDet;
718
+ dest[7] = (a20*b05 - a22*b02 + a23*b01)*invDet;
719
+ dest[8] = (a10*b10 - a11*b08 + a13*b06)*invDet;
720
+ dest[9] = (-a00*b10 + a01*b08 - a03*b06)*invDet;
721
+ dest[10] = (a30*b04 - a31*b02 + a33*b00)*invDet;
722
+ dest[11] = (-a20*b04 + a21*b02 - a23*b00)*invDet;
723
+ dest[12] = (-a10*b09 + a11*b07 - a12*b06)*invDet;
724
+ dest[13] = (a00*b09 - a01*b07 + a02*b06)*invDet;
725
+ dest[14] = (-a30*b03 + a31*b01 - a32*b00)*invDet;
726
+ dest[15] = (a20*b03 - a21*b01 + a22*b00)*invDet;
727
+
728
+ return dest;
729
+ };
730
+
731
+ /**
732
+ * mat4.toRotationMat(mat[, dest]) -> mat4
733
+ * - mat (mat4) : mat4 containing values to copy
734
+ * - dest (mat4) : optional mat4 receiving copied values. If not specified, result is written to +mat+.
735
+ *
736
+ * Copies the upper 3x3 elements of a mat4 into another mat4
737
+ *
738
+ * Returns:
739
+ * dest is specified, a new mat4 otherwise
740
+ **/
741
+ mat4.toRotationMat = function(mat, dest) {
742
+ if(!dest) { dest = mat4.create(); }
743
+
744
+ dest[0] = mat[0];
745
+ dest[1] = mat[1];
746
+ dest[2] = mat[2];
747
+ dest[3] = mat[3];
748
+ dest[4] = mat[4];
749
+ dest[5] = mat[5];
750
+ dest[6] = mat[6];
751
+ dest[7] = mat[7];
752
+ dest[8] = mat[8];
753
+ dest[9] = mat[9];
754
+ dest[10] = mat[10];
755
+ dest[11] = mat[11];
756
+ dest[12] = 0;
757
+ dest[13] = 0;
758
+ dest[14] = 0;
759
+ dest[15] = 1;
760
+
761
+ return dest;
762
+ };
763
+
764
+ /**
765
+ * mat4.toMat3(mat[, dest]) -> mat3
766
+ * - mat (mat4) : mat4 containing values to copy
767
+ * - dest (mat3) : optional mat3 receiving copied values. If not specified, a new mat3 is created.
768
+ *
769
+ * Copies the upper 3x3 elements of a mat4 into a mat3
770
+ *
771
+ * Returns:
772
+ * dest is specified, a new mat3 otherwise
773
+ **/
774
+ mat4.toMat3 = function(mat, dest) {
775
+ if(!dest) { dest = mat3.create(); }
776
+
777
+ dest[0] = mat[0];
778
+ dest[1] = mat[1];
779
+ dest[2] = mat[2];
780
+ dest[3] = mat[4];
781
+ dest[4] = mat[5];
782
+ dest[5] = mat[6];
783
+ dest[6] = mat[8];
784
+ dest[7] = mat[9];
785
+ dest[8] = mat[10];
786
+
787
+ return dest;
788
+ };
789
+
790
+ /**
791
+ * mat4.toInverseMat3(mat[, dest]) -> mat3
792
+ * - mat (mat4) : mat4 containing values to invert and copy
793
+ * - dest (mat3) : optional mat3 receiving values
794
+ *
795
+ * Calculates the inverse of the upper 3x3 elements of a mat4 and copies the result into a mat3
796
+ * The resulting matrix is useful for calculating transformed normals
797
+ *
798
+ * Returns:
799
+ * dest is specified, a new mat3 otherwise
800
+ **/
801
+ mat4.toInverseMat3 = function(mat, dest) {
802
+ // Cache the matrix values (makes for huge speed increases!)
803
+ var a00 = mat[0], a01 = mat[1], a02 = mat[2];
804
+ var a10 = mat[4], a11 = mat[5], a12 = mat[6];
805
+ var a20 = mat[8], a21 = mat[9], a22 = mat[10];
806
+
807
+ var b01 = a22*a11-a12*a21;
808
+ var b11 = -a22*a10+a12*a20;
809
+ var b21 = a21*a10-a11*a20;
810
+
811
+ var d = a00*b01 + a01*b11 + a02*b21;
812
+ if (!d) { return null; }
813
+ var id = 1/d;
814
+
815
+ if(!dest) { dest = mat3.create(); }
816
+
817
+ dest[0] = b01*id;
818
+ dest[1] = (-a22*a01 + a02*a21)*id;
819
+ dest[2] = (a12*a01 - a02*a11)*id;
820
+ dest[3] = b11*id;
821
+ dest[4] = (a22*a00 - a02*a20)*id;
822
+ dest[5] = (-a12*a00 + a02*a10)*id;
823
+ dest[6] = b21*id;
824
+ dest[7] = (-a21*a00 + a01*a20)*id;
825
+ dest[8] = (a11*a00 - a01*a10)*id;
826
+
827
+ return dest;
828
+ };
829
+
830
+ /**
831
+ * mat4.multiply(mat, mat2[, dest]) -> mat4
832
+ * - mat (mat4) : first operand
833
+ * - mat2 (mat4) : second operand
834
+ * - dest (mat4) : optional mat4 receiving operation result. If not specified, result is written to +mat+.
835
+ *
836
+ * Performs a matrix multiplication
837
+ *
838
+ * Returns:
839
+ * dest if specified, mat otherwise
840
+ **/
841
+ mat4.multiply = function(mat, mat2, dest) {
842
+ if(!dest) { dest = mat }
843
+
844
+ // Cache the matrix values (makes for huge speed increases!)
845
+ var a00 = mat[0], a01 = mat[1], a02 = mat[2], a03 = mat[3];
846
+ var a10 = mat[4], a11 = mat[5], a12 = mat[6], a13 = mat[7];
847
+ var a20 = mat[8], a21 = mat[9], a22 = mat[10], a23 = mat[11];
848
+ var a30 = mat[12], a31 = mat[13], a32 = mat[14], a33 = mat[15];
849
+
850
+ var b00 = mat2[0], b01 = mat2[1], b02 = mat2[2], b03 = mat2[3];
851
+ var b10 = mat2[4], b11 = mat2[5], b12 = mat2[6], b13 = mat2[7];
852
+ var b20 = mat2[8], b21 = mat2[9], b22 = mat2[10], b23 = mat2[11];
853
+ var b30 = mat2[12], b31 = mat2[13], b32 = mat2[14], b33 = mat2[15];
854
+
855
+ dest[0] = b00*a00 + b01*a10 + b02*a20 + b03*a30;
856
+ dest[1] = b00*a01 + b01*a11 + b02*a21 + b03*a31;
857
+ dest[2] = b00*a02 + b01*a12 + b02*a22 + b03*a32;
858
+ dest[3] = b00*a03 + b01*a13 + b02*a23 + b03*a33;
859
+ dest[4] = b10*a00 + b11*a10 + b12*a20 + b13*a30;
860
+ dest[5] = b10*a01 + b11*a11 + b12*a21 + b13*a31;
861
+ dest[6] = b10*a02 + b11*a12 + b12*a22 + b13*a32;
862
+ dest[7] = b10*a03 + b11*a13 + b12*a23 + b13*a33;
863
+ dest[8] = b20*a00 + b21*a10 + b22*a20 + b23*a30;
864
+ dest[9] = b20*a01 + b21*a11 + b22*a21 + b23*a31;
865
+ dest[10] = b20*a02 + b21*a12 + b22*a22 + b23*a32;
866
+ dest[11] = b20*a03 + b21*a13 + b22*a23 + b23*a33;
867
+ dest[12] = b30*a00 + b31*a10 + b32*a20 + b33*a30;
868
+ dest[13] = b30*a01 + b31*a11 + b32*a21 + b33*a31;
869
+ dest[14] = b30*a02 + b31*a12 + b32*a22 + b33*a32;
870
+ dest[15] = b30*a03 + b31*a13 + b32*a23 + b33*a33;
871
+
872
+ return dest;
873
+ };
874
+
875
+ /**
876
+ * mat4.multiplyVec3(mat, vec[, dest]) -> vec3
877
+ * - mat (mat4) : mat4 to transform the vector with
878
+ * - vec (vec3) : vec3 to transform
879
+ * - dest (vec3) : optional vec3 receiving operation result. If not specified, result is written to +vec+.
880
+ *
881
+ * Transforms a vec3 with the given matrix
882
+ * 4th vector component is implicitly '1'
883
+ *
884
+ * Returns:
885
+ * dest if specified, vec3 otherwise
886
+ **/
887
+ mat4.multiplyVec3 = function(mat, vec, dest) {
888
+ if(!dest) { dest = vec }
889
+
890
+ var x = vec[0], y = vec[1], z = vec[2];
891
+
892
+ dest[0] = mat[0]*x + mat[4]*y + mat[8]*z + mat[12];
893
+ dest[1] = mat[1]*x + mat[5]*y + mat[9]*z + mat[13];
894
+ dest[2] = mat[2]*x + mat[6]*y + mat[10]*z + mat[14];
895
+
896
+ return dest;
897
+ };
898
+
899
+ /**
900
+ * mat4.multiplyVec4(mat, vec[, dest]) -> vec4
901
+ * - mat (mat4) : mat4 to transform the vector with
902
+ * - vec (vec4) : vec4 to transform
903
+ * - dest (vec4) : optional vec4 receiving operation result. If not specified, result is written to +vec+.
904
+ *
905
+ * Transforms a vec4 with the given matrix
906
+ *
907
+ * Returns:
908
+ * dest if specified, vec otherwise
909
+ **/
910
+ mat4.multiplyVec4 = function(mat, vec, dest) {
911
+ if(!dest) { dest = vec }
912
+
913
+ var x = vec[0], y = vec[1], z = vec[2], w = vec[3];
914
+
915
+ dest[0] = mat[0]*x + mat[4]*y + mat[8]*z + mat[12]*w;
916
+ dest[1] = mat[1]*x + mat[5]*y + mat[9]*z + mat[13]*w;
917
+ dest[2] = mat[2]*x + mat[6]*y + mat[10]*z + mat[14]*w;
918
+ dest[3] = mat[3]*x + mat[7]*y + mat[11]*z + mat[15]*w;
919
+
920
+ return dest;
921
+ };
922
+
923
+ /**
924
+ * mat4.translate(mat, vec[, dest]) -> mat4
925
+ * - mat (mat4) : mat4 to translate
926
+ * - vec (vec3) : vec3 specifying the translation
927
+ * - dest (mat4) : optional mat4 receiving operation result. If not specified, result is written to +mat+.
928
+ *
929
+ * Translates a matrix by the given vector
930
+ *
931
+ * Returns:
932
+ * dest if specified, mat otherwise
933
+ **/
934
+ mat4.translate = function(mat, vec, dest) {
935
+ var x = vec[0], y = vec[1], z = vec[2];
936
+
937
+ if(!dest || mat == dest) {
938
+ mat[12] = mat[0]*x + mat[4]*y + mat[8]*z + mat[12];
939
+ mat[13] = mat[1]*x + mat[5]*y + mat[9]*z + mat[13];
940
+ mat[14] = mat[2]*x + mat[6]*y + mat[10]*z + mat[14];
941
+ mat[15] = mat[3]*x + mat[7]*y + mat[11]*z + mat[15];
942
+ return mat;
943
+ }
944
+
945
+ var a00 = mat[0], a01 = mat[1], a02 = mat[2], a03 = mat[3];
946
+ var a10 = mat[4], a11 = mat[5], a12 = mat[6], a13 = mat[7];
947
+ var a20 = mat[8], a21 = mat[9], a22 = mat[10], a23 = mat[11];
948
+
949
+ dest[0] = a00;
950
+ dest[1] = a01;
951
+ dest[2] = a02;
952
+ dest[3] = a03;
953
+ dest[4] = a10;
954
+ dest[5] = a11;
955
+ dest[6] = a12;
956
+ dest[7] = a13;
957
+ dest[8] = a20;
958
+ dest[9] = a21;
959
+ dest[10] = a22;
960
+ dest[11] = a23;
961
+
962
+ dest[12] = a00*x + a10*y + a20*z + mat[12];
963
+ dest[13] = a01*x + a11*y + a21*z + mat[13];
964
+ dest[14] = a02*x + a12*y + a22*z + mat[14];
965
+ dest[15] = a03*x + a13*y + a23*z + mat[15];
966
+ return dest;
967
+ };
968
+
969
+ /**
970
+ * mat4.scale(mat, vec[, dest]) -> mat4
971
+ * - mat (mat4) : mat4 to scale
972
+ * - vec (vec3) : vec3 specifying the scale for each axis
973
+ * - dest (mat4) : optional mat4 receiving operation result. If not specified, result is written to +mat+.
974
+ *
975
+ * Scales a matrix by the given vector
976
+ *
977
+ * Returns:
978
+ * dest if specified, mat otherwise
979
+ **/
980
+ mat4.scale = function(mat, vec, dest) {
981
+ var x = vec[0], y = vec[1], z = vec[2];
982
+
983
+ if(!dest || mat == dest) {
984
+ mat[0] *= x;
985
+ mat[1] *= x;
986
+ mat[2] *= x;
987
+ mat[3] *= x;
988
+ mat[4] *= y;
989
+ mat[5] *= y;
990
+ mat[6] *= y;
991
+ mat[7] *= y;
992
+ mat[8] *= z;
993
+ mat[9] *= z;
994
+ mat[10] *= z;
995
+ mat[11] *= z;
996
+ return mat;
997
+ }
998
+
999
+ dest[0] = mat[0]*x;
1000
+ dest[1] = mat[1]*x;
1001
+ dest[2] = mat[2]*x;
1002
+ dest[3] = mat[3]*x;
1003
+ dest[4] = mat[4]*y;
1004
+ dest[5] = mat[5]*y;
1005
+ dest[6] = mat[6]*y;
1006
+ dest[7] = mat[7]*y;
1007
+ dest[8] = mat[8]*z;
1008
+ dest[9] = mat[9]*z;
1009
+ dest[10] = mat[10]*z;
1010
+ dest[11] = mat[11]*z;
1011
+ dest[12] = mat[12];
1012
+ dest[13] = mat[13];
1013
+ dest[14] = mat[14];
1014
+ dest[15] = mat[15];
1015
+ return dest;
1016
+ };
1017
+
1018
+ /**
1019
+ * mat4.rotate(mat, angle, axis[, dest]) -> mat4
1020
+ * - mat (mat4) : mat4 to rotate
1021
+ * - angle (Number) : angle (in radians) to rotate
1022
+ * - axis (vec3) : vec3 representing the axis to rotate around
1023
+ * - dest (mat4) : optional mat4 receiving operation result. If not specified, result is written to +mat+.
1024
+ *
1025
+ * Rotates a matrix by the given angle around the specified axis
1026
+ * If rotating around a primary axis (X,Y,Z) one of the specialized rotation functions should be used instead for performance
1027
+ *
1028
+ * Returns:
1029
+ * dest if specified, mat otherwise
1030
+ **/
1031
+ mat4.rotate = function(mat, angle, axis, dest) {
1032
+ var x = axis[0], y = axis[1], z = axis[2];
1033
+ var len = Math.sqrt(x*x + y*y + z*z);
1034
+ if (!len) { return null; }
1035
+ if (len != 1) {
1036
+ len = 1 / len;
1037
+ x *= len;
1038
+ y *= len;
1039
+ z *= len;
1040
+ }
1041
+
1042
+ var s = Math.sin(angle);
1043
+ var c = Math.cos(angle);
1044
+ var t = 1-c;
1045
+
1046
+ // Cache the matrix values (makes for huge speed increases!)
1047
+ var a00 = mat[0], a01 = mat[1], a02 = mat[2], a03 = mat[3];
1048
+ var a10 = mat[4], a11 = mat[5], a12 = mat[6], a13 = mat[7];
1049
+ var a20 = mat[8], a21 = mat[9], a22 = mat[10], a23 = mat[11];
1050
+
1051
+ // Construct the elements of the rotation matrix
1052
+ var b00 = x*x*t + c, b01 = y*x*t + z*s, b02 = z*x*t - y*s;
1053
+ var b10 = x*y*t - z*s, b11 = y*y*t + c, b12 = z*y*t + x*s;
1054
+ var b20 = x*z*t + y*s, b21 = y*z*t - x*s, b22 = z*z*t + c;
1055
+
1056
+ if(!dest) {
1057
+ dest = mat
1058
+ } else if(mat != dest) { // If the source and destination differ, copy the unchanged last row
1059
+ dest[12] = mat[12];
1060
+ dest[13] = mat[13];
1061
+ dest[14] = mat[14];
1062
+ dest[15] = mat[15];
1063
+ }
1064
+
1065
+ // Perform rotation-specific matrix multiplication
1066
+ dest[0] = a00*b00 + a10*b01 + a20*b02;
1067
+ dest[1] = a01*b00 + a11*b01 + a21*b02;
1068
+ dest[2] = a02*b00 + a12*b01 + a22*b02;
1069
+ dest[3] = a03*b00 + a13*b01 + a23*b02;
1070
+
1071
+ dest[4] = a00*b10 + a10*b11 + a20*b12;
1072
+ dest[5] = a01*b10 + a11*b11 + a21*b12;
1073
+ dest[6] = a02*b10 + a12*b11 + a22*b12;
1074
+ dest[7] = a03*b10 + a13*b11 + a23*b12;
1075
+
1076
+ dest[8] = a00*b20 + a10*b21 + a20*b22;
1077
+ dest[9] = a01*b20 + a11*b21 + a21*b22;
1078
+ dest[10] = a02*b20 + a12*b21 + a22*b22;
1079
+ dest[11] = a03*b20 + a13*b21 + a23*b22;
1080
+ return dest;
1081
+ };
1082
+
1083
+ /**
1084
+ * mat4.rotateX(mat, angle[, dest]) -> mat4
1085
+ * - mat (mat4) : mat4 to rotate
1086
+ * - angle (Number) : angle (in radians) to rotate
1087
+ * - dest (mat4) : optional mat4 receiving operation result. If not specified, result is written to +mat+.
1088
+ *
1089
+ * Rotates a matrix by the given angle around the X axis
1090
+ *
1091
+ * Returns:
1092
+ * dest if specified, mat otherwise
1093
+ **/
1094
+ mat4.rotateX = function(mat, angle, dest) {
1095
+ var s = Math.sin(angle);
1096
+ var c = Math.cos(angle);
1097
+
1098
+ // Cache the matrix values (makes for huge speed increases!)
1099
+ var a10 = mat[4], a11 = mat[5], a12 = mat[6], a13 = mat[7];
1100
+ var a20 = mat[8], a21 = mat[9], a22 = mat[10], a23 = mat[11];
1101
+
1102
+ if(!dest) {
1103
+ dest = mat
1104
+ } else if(mat != dest) { // If the source and destination differ, copy the unchanged rows
1105
+ dest[0] = mat[0];
1106
+ dest[1] = mat[1];
1107
+ dest[2] = mat[2];
1108
+ dest[3] = mat[3];
1109
+
1110
+ dest[12] = mat[12];
1111
+ dest[13] = mat[13];
1112
+ dest[14] = mat[14];
1113
+ dest[15] = mat[15];
1114
+ }
1115
+
1116
+ // Perform axis-specific matrix multiplication
1117
+ dest[4] = a10*c + a20*s;
1118
+ dest[5] = a11*c + a21*s;
1119
+ dest[6] = a12*c + a22*s;
1120
+ dest[7] = a13*c + a23*s;
1121
+
1122
+ dest[8] = a10*-s + a20*c;
1123
+ dest[9] = a11*-s + a21*c;
1124
+ dest[10] = a12*-s + a22*c;
1125
+ dest[11] = a13*-s + a23*c;
1126
+ return dest;
1127
+ };
1128
+
1129
+ /**
1130
+ * mat4.rotateY(mat, angle[, dest]) -> mat4
1131
+ * - mat (mat4) : mat4 to rotate
1132
+ * - angle (Number) : angle (in radians) to rotate
1133
+ * - dest (mat4) : optional mat4 receiving operation result. If not specified, result is written to +mat+.
1134
+ *
1135
+ * Rotates a matrix by the given angle around the Y axis
1136
+ *
1137
+ * Returns:
1138
+ * dest if specified, mat otherwise
1139
+ **/
1140
+ mat4.rotateY = function(mat, angle, dest) {
1141
+ var s = Math.sin(angle);
1142
+ var c = Math.cos(angle);
1143
+
1144
+ // Cache the matrix values (makes for huge speed increases!)
1145
+ var a00 = mat[0], a01 = mat[1], a02 = mat[2], a03 = mat[3];
1146
+ var a20 = mat[8], a21 = mat[9], a22 = mat[10], a23 = mat[11];
1147
+
1148
+ if(!dest) {
1149
+ dest = mat
1150
+ } else if(mat != dest) { // If the source and destination differ, copy the unchanged rows
1151
+ dest[4] = mat[4];
1152
+ dest[5] = mat[5];
1153
+ dest[6] = mat[6];
1154
+ dest[7] = mat[7];
1155
+
1156
+ dest[12] = mat[12];
1157
+ dest[13] = mat[13];
1158
+ dest[14] = mat[14];
1159
+ dest[15] = mat[15];
1160
+ }
1161
+
1162
+ // Perform axis-specific matrix multiplication
1163
+ dest[0] = a00*c + a20*-s;
1164
+ dest[1] = a01*c + a21*-s;
1165
+ dest[2] = a02*c + a22*-s;
1166
+ dest[3] = a03*c + a23*-s;
1167
+
1168
+ dest[8] = a00*s + a20*c;
1169
+ dest[9] = a01*s + a21*c;
1170
+ dest[10] = a02*s + a22*c;
1171
+ dest[11] = a03*s + a23*c;
1172
+ return dest;
1173
+ };
1174
+
1175
+ /**
1176
+ * mat4.rotateZ(mat, angle[, dest]) -> mat4
1177
+ * - mat (mat4) : mat4 to rotate
1178
+ * - angle (Number) : angle (in radians) to rotate
1179
+ * - dest (mat4) : optional mat4 receiving operation result. If not specified, result is written to +mat+.
1180
+ *
1181
+ * Rotates a matrix by the given angle around the Z axis
1182
+ *
1183
+ * Returns:
1184
+ * dest if specified, mat otherwise
1185
+ **/
1186
+ mat4.rotateZ = function(mat, angle, dest) {
1187
+ var s = Math.sin(angle);
1188
+ var c = Math.cos(angle);
1189
+
1190
+ // Cache the matrix values (makes for huge speed increases!)
1191
+ var a00 = mat[0], a01 = mat[1], a02 = mat[2], a03 = mat[3];
1192
+ var a10 = mat[4], a11 = mat[5], a12 = mat[6], a13 = mat[7];
1193
+
1194
+ if(!dest) {
1195
+ dest = mat
1196
+ } else if(mat != dest) { // If the source and destination differ, copy the unchanged last row
1197
+ dest[8] = mat[8];
1198
+ dest[9] = mat[9];
1199
+ dest[10] = mat[10];
1200
+ dest[11] = mat[11];
1201
+
1202
+ dest[12] = mat[12];
1203
+ dest[13] = mat[13];
1204
+ dest[14] = mat[14];
1205
+ dest[15] = mat[15];
1206
+ }
1207
+
1208
+ // Perform axis-specific matrix multiplication
1209
+ dest[0] = a00*c + a10*s;
1210
+ dest[1] = a01*c + a11*s;
1211
+ dest[2] = a02*c + a12*s;
1212
+ dest[3] = a03*c + a13*s;
1213
+
1214
+ dest[4] = a00*-s + a10*c;
1215
+ dest[5] = a01*-s + a11*c;
1216
+ dest[6] = a02*-s + a12*c;
1217
+ dest[7] = a03*-s + a13*c;
1218
+
1219
+ return dest;
1220
+ };
1221
+
1222
+ /**
1223
+ * mat4.frustum(left, right, bottom, top, near, far[, dest]) -> mat4
1224
+ * - left (Number) : scalar, left bounds of the frustum
1225
+ * - right (Number) : scalar, right bounds of the frustum
1226
+ * - bottom (Number) : scalar, bottom bounds of the frustum
1227
+ * - top (Number) : scalar, top bounds of the frustum
1228
+ * - near (Number) : scalar, near bounds of the frustum
1229
+ * - far (Number) : scalar, far bounds of the frustum
1230
+ * - dest (mat4) : optional mat4 frustum matrix will be written into. If not specified, a new mat4 is created.
1231
+ *
1232
+ * Generates a frustum matrix with the given bounds
1233
+ *
1234
+ * Returns:
1235
+ * dest if specified, a new mat4 otherwise
1236
+ **/
1237
+ mat4.frustum = function(left, right, bottom, top, near, far, dest) {
1238
+ if(!dest) { dest = mat4.create(); }
1239
+ var rl = (right - left);
1240
+ var tb = (top - bottom);
1241
+ var fn = (far - near);
1242
+ dest[0] = (near*2) / rl;
1243
+ dest[1] = 0;
1244
+ dest[2] = 0;
1245
+ dest[3] = 0;
1246
+ dest[4] = 0;
1247
+ dest[5] = (near*2) / tb;
1248
+ dest[6] = 0;
1249
+ dest[7] = 0;
1250
+ dest[8] = (right + left) / rl;
1251
+ dest[9] = (top + bottom) / tb;
1252
+ dest[10] = -(far + near) / fn;
1253
+ dest[11] = -1;
1254
+ dest[12] = 0;
1255
+ dest[13] = 0;
1256
+ dest[14] = -(far*near*2) / fn;
1257
+ dest[15] = 0;
1258
+ return dest;
1259
+ };
1260
+
1261
+ /**
1262
+ * mat4.perspective(fovy, aspect, near, far[, dest]) -> mat4
1263
+ * - fovy (Number) : scalar, vertical field of view
1264
+ * - aspect (Number) : scalar, aspect ratio. Typically viewport width/height
1265
+ * - near (Number) : scalar, near bounds of the frustum
1266
+ * - far (Number) : scalar, far bounds of the frustum
1267
+ * - dest (mat4) : optional mat4 the frustum matrix will be written into. If not specified, a new mat4 is created.
1268
+ *
1269
+ * Generates a perspective projection matrix with the given bounds
1270
+ *
1271
+ * Returns:
1272
+ * dest if specified, a new mat4 otherwise
1273
+ **/
1274
+ mat4.perspective = function(fovy, aspect, near, far, dest) {
1275
+ var top = near*Math.tan(fovy*Math.PI / 360.0);
1276
+ var right = top*aspect;
1277
+ return mat4.frustum(-right, right, -top, top, near, far, dest);
1278
+ };
1279
+
1280
+ /**
1281
+ * mat4.ortho(left, right, bottom, top, near, far[, dest]) -> mat4
1282
+ * - left (Number) : scalar, left bounds of the frustum
1283
+ * - right (Number) : scalar, right bounds of the frustum
1284
+ * - bottom (Number) : scalar, bottom bounds of the frustum
1285
+ * - top (Number) : scalar, top bounds of the frustum
1286
+ * - near (Number) : scalar, near bounds of the frustum
1287
+ * - far (Number) : scalar, far bounds of the frustum
1288
+ * - dest (mat4) : optional mat4 the frustum matrix will be written into. If not specified, a new mat4 is created.
1289
+ *
1290
+ * Generates a orthogonal projection matrix with the given bounds
1291
+ *
1292
+ * Returns:
1293
+ * dest if specified, a new mat4 otherwise
1294
+ **/
1295
+ mat4.ortho = function(left, right, bottom, top, near, far, dest) {
1296
+ if(!dest) { dest = mat4.create(); }
1297
+ var rl = (right - left);
1298
+ var tb = (top - bottom);
1299
+ var fn = (far - near);
1300
+ dest[0] = 2 / rl;
1301
+ dest[1] = 0;
1302
+ dest[2] = 0;
1303
+ dest[3] = 0;
1304
+ dest[4] = 0;
1305
+ dest[5] = 2 / tb;
1306
+ dest[6] = 0;
1307
+ dest[7] = 0;
1308
+ dest[8] = 0;
1309
+ dest[9] = 0;
1310
+ dest[10] = -2 / fn;
1311
+ dest[11] = 0;
1312
+ dest[12] = -(left + right) / rl;
1313
+ dest[13] = -(top + bottom) / tb;
1314
+ dest[14] = -(far + near) / fn;
1315
+ dest[15] = 1;
1316
+ return dest;
1317
+ };
1318
+
1319
+ /**
1320
+ * mat4.lookAt(eye, center, up[, dest]) -> mat4
1321
+ * - eye (vec3) : position of the viewer
1322
+ * - center (vec3) : the point the viewer is looking at
1323
+ * - up (vec3) : vec3 pointing "up"
1324
+ * - dest (mat4) : optional mat4 the frustum matrix will be written into. If not specified, a new mat4 is created.
1325
+ *
1326
+ * Generates a look-at matrix with the given eye position, focal point, and up axis
1327
+ *
1328
+ * Returns:
1329
+ * dest if specified, a new mat4 otherwise
1330
+ **/
1331
+ mat4.lookAt = function(eye, center, up, dest) {
1332
+ if(!dest) { dest = mat4.create(); }
1333
+
1334
+ var eyex = eye[0],
1335
+ eyey = eye[1],
1336
+ eyez = eye[2],
1337
+ upx = up[0],
1338
+ upy = up[1],
1339
+ upz = up[2],
1340
+ centerx = center[0],
1341
+ centery = center[1],
1342
+ centerz = center[2];
1343
+
1344
+ if (eyex == centerx && eyey == centery && eyez == centerz) {
1345
+ return mat4.identity(dest);
1346
+ }
1347
+
1348
+ var z0,z1,z2,x0,x1,x2,y0,y1,y2,len;
1349
+
1350
+ //vec3.direction(eye, center, z);
1351
+ z0 = eyex - center[0];
1352
+ z1 = eyey - center[1];
1353
+ z2 = eyez - center[2];
1354
+
1355
+ // normalize (no check needed for 0 because of early return)
1356
+ len = 1/Math.sqrt(z0*z0 + z1*z1 + z2*z2);
1357
+ z0 *= len;
1358
+ z1 *= len;
1359
+ z2 *= len;
1360
+
1361
+ //vec3.normalize(vec3.cross(up, z, x));
1362
+ x0 = upy*z2 - upz*z1;
1363
+ x1 = upz*z0 - upx*z2;
1364
+ x2 = upx*z1 - upy*z0;
1365
+ len = Math.sqrt(x0*x0 + x1*x1 + x2*x2);
1366
+ if (!len) {
1367
+ x0 = 0;
1368
+ x1 = 0;
1369
+ x2 = 0;
1370
+ } else {
1371
+ len = 1/len;
1372
+ x0 *= len;
1373
+ x1 *= len;
1374
+ x2 *= len;
1375
+ };
1376
+
1377
+ //vec3.normalize(vec3.cross(z, x, y));
1378
+ y0 = z1*x2 - z2*x1;
1379
+ y1 = z2*x0 - z0*x2;
1380
+ y2 = z0*x1 - z1*x0;
1381
+
1382
+ len = Math.sqrt(y0*y0 + y1*y1 + y2*y2);
1383
+ if (!len) {
1384
+ y0 = 0;
1385
+ y1 = 0;
1386
+ y2 = 0;
1387
+ } else {
1388
+ len = 1/len;
1389
+ y0 *= len;
1390
+ y1 *= len;
1391
+ y2 *= len;
1392
+ }
1393
+
1394
+ dest[0] = x0;
1395
+ dest[1] = y0;
1396
+ dest[2] = z0;
1397
+ dest[3] = 0;
1398
+ dest[4] = x1;
1399
+ dest[5] = y1;
1400
+ dest[6] = z1;
1401
+ dest[7] = 0;
1402
+ dest[8] = x2;
1403
+ dest[9] = y2;
1404
+ dest[10] = z2;
1405
+ dest[11] = 0;
1406
+ dest[12] = -(x0*eyex + x1*eyey + x2*eyez);
1407
+ dest[13] = -(y0*eyex + y1*eyey + y2*eyez);
1408
+ dest[14] = -(z0*eyex + z1*eyey + z2*eyez);
1409
+ dest[15] = 1;
1410
+
1411
+ return dest;
1412
+ };
1413
+
1414
+ /**
1415
+ * mat4.str(mat) -> String
1416
+ * - mat (mat4) : mat4 to represent as a string
1417
+ *
1418
+ * Returns a string representation of a mat4
1419
+ *
1420
+ * Returns:
1421
+ * string representation of mat
1422
+ **/
1423
+ mat4.str = function(mat) {
1424
+ return '[' + mat[0] + ', ' + mat[1] + ', ' + mat[2] + ', ' + mat[3] +
1425
+ ', '+ mat[4] + ', ' + mat[5] + ', ' + mat[6] + ', ' + mat[7] +
1426
+ ', '+ mat[8] + ', ' + mat[9] + ', ' + mat[10] + ', ' + mat[11] +
1427
+ ', '+ mat[12] + ', ' + mat[13] + ', ' + mat[14] + ', ' + mat[15] + ']';
1428
+ };
1429
+
1430
+ /**
1431
+ * quat4
1432
+ * Quaternions
1433
+ **/
1434
+ quat4 = {};
1435
+
1436
+ /**
1437
+ * quat4.create([quat]) -> quat4
1438
+ * - quat (quat4) : optional quat4 containing values to initialize with
1439
+ *
1440
+ * Creates a new instance of a quat4 using the default array type
1441
+ * Any javascript array containing at least 4 numeric elements can serve as a quat4
1442
+ *
1443
+ * Returns:
1444
+ * New quat4
1445
+ **/
1446
+ quat4.create = function(quat) {
1447
+ var dest = new glMatrixArrayType(4);
1448
+
1449
+ if(quat) {
1450
+ dest[0] = quat[0];
1451
+ dest[1] = quat[1];
1452
+ dest[2] = quat[2];
1453
+ dest[3] = quat[3];
1454
+ }
1455
+
1456
+ return dest;
1457
+ };
1458
+
1459
+ /**
1460
+ * quat4.set(quat, dest) -> quat4
1461
+ * - quat (quat4) : quat4 containing values to copy
1462
+ * - dest (quat4) : quat4 receiving copied values
1463
+ *
1464
+ * Copies the values of one quat4 to another
1465
+ *
1466
+ * Returns:
1467
+ * dest
1468
+ **/
1469
+ quat4.set = function(quat, dest) {
1470
+ dest[0] = quat[0];
1471
+ dest[1] = quat[1];
1472
+ dest[2] = quat[2];
1473
+ dest[3] = quat[3];
1474
+
1475
+ return dest;
1476
+ };
1477
+
1478
+ /**
1479
+ * quat4.calculateW(quat[, dest]) -> quat4
1480
+ * - quat (quat4) : quat4 to calculate W component of
1481
+ * - dest (quat4) : optional quat4 receiving calculated values. If not specified, result is written to quat.
1482
+ *
1483
+ * Calculates the W component of a quat4 from the X, Y, and Z components.
1484
+ * Assumes that quaternion is 1 unit in length.
1485
+ * Any existing W component will be ignored.
1486
+ *
1487
+ * Returns:
1488
+ * dest if specified, quat otherwise
1489
+ **/
1490
+ quat4.calculateW = function(quat, dest) {
1491
+ var x = quat[0], y = quat[1], z = quat[2];
1492
+
1493
+ if(!dest || quat == dest) {
1494
+ quat[3] = -Math.sqrt(Math.abs(1.0 - x*x - y*y - z*z));
1495
+ return quat;
1496
+ }
1497
+ dest[0] = x;
1498
+ dest[1] = y;
1499
+ dest[2] = z;
1500
+ dest[3] = -Math.sqrt(Math.abs(1.0 - x*x - y*y - z*z));
1501
+ return dest;
1502
+ }
1503
+
1504
+ /**
1505
+ * quat4.inverse(quat[, dest]) -> quat4
1506
+ * - quat (quat4) : quat4 to calculate inverse of
1507
+ * - dest (quat4) : optional quat4 receiving calculated values. If not specified, result is written to quat.
1508
+ *
1509
+ * Calculates the inverse of a quat4
1510
+ *
1511
+ * Returns:
1512
+ * dest if specified, quat otherwise
1513
+ **/
1514
+ quat4.inverse = function(quat, dest) {
1515
+ if(!dest || quat == dest) {
1516
+ quat[0] *= 1;
1517
+ quat[1] *= 1;
1518
+ quat[2] *= 1;
1519
+ return quat;
1520
+ }
1521
+ dest[0] = -quat[0];
1522
+ dest[1] = -quat[1];
1523
+ dest[2] = -quat[2];
1524
+ dest[3] = quat[3];
1525
+ return dest;
1526
+ }
1527
+
1528
+ /**
1529
+ * quat4.length(quat) -> quat4
1530
+ * - quat (quat4) : quat4 to calculate length of
1531
+ *
1532
+ * Calculates the length of a quat4
1533
+ *
1534
+ * Returns:
1535
+ * Length of quat
1536
+ **/
1537
+ quat4.length = function(quat) {
1538
+ var x = quat[0], y = quat[1], z = quat[2], w = quat[3];
1539
+ return Math.sqrt(x*x + y*y + z*z + w*w);
1540
+ }
1541
+
1542
+ /**
1543
+ * quat4.normalize(quat[, dest]) -> quat4
1544
+ * - quat (quat4) : quat4 to normalize
1545
+ * - dest (quat4) : optional quat4 receiving calculated values. If not specified, result is written to quat.
1546
+ *
1547
+ * Generates a unit quaternion of the same direction as the provided quat4
1548
+ * If quaternion length is 0, returns [0, 0, 0, 0]
1549
+ *
1550
+ * Returns:
1551
+ * dest if specified, quat otherwise
1552
+ **/
1553
+ quat4.normalize = function(quat, dest) {
1554
+ if(!dest) { dest = quat; }
1555
+
1556
+ var x = quat[0], y = quat[1], z = quat[2], w = quat[3];
1557
+ var len = Math.sqrt(x*x + y*y + z*z + w*w);
1558
+ if(len == 0) {
1559
+ dest[0] = 0;
1560
+ dest[1] = 0;
1561
+ dest[2] = 0;
1562
+ dest[3] = 0;
1563
+ return dest;
1564
+ }
1565
+ len = 1/len;
1566
+ dest[0] = x * len;
1567
+ dest[1] = y * len;
1568
+ dest[2] = z * len;
1569
+ dest[3] = w * len;
1570
+
1571
+ return dest;
1572
+ }
1573
+
1574
+ /**
1575
+ * quat4.multiply(quat, quat2[, dest]) -> quat4
1576
+ * - quat (quat4) : first operand
1577
+ * - quat2 (quat4) : second operand
1578
+ * - dest (quat4) : optional quat4 receiving calculated values. If not specified, result is written to quat.
1579
+ *
1580
+ * Performs a quaternion multiplication
1581
+ *
1582
+ * Returns:
1583
+ * dest if specified, quat otherwise
1584
+ **/
1585
+ quat4.multiply = function(quat, quat2, dest) {
1586
+ if(!dest) { dest = quat; }
1587
+
1588
+ var qax = quat[0], qay = quat[1], qaz = quat[2], qaw = quat[3];
1589
+ var qbx = quat2[0], qby = quat2[1], qbz = quat2[2], qbw = quat2[3];
1590
+
1591
+ dest[0] = qax*qbw + qaw*qbx + qay*qbz - qaz*qby;
1592
+ dest[1] = qay*qbw + qaw*qby + qaz*qbx - qax*qbz;
1593
+ dest[2] = qaz*qbw + qaw*qbz + qax*qby - qay*qbx;
1594
+ dest[3] = qaw*qbw - qax*qbx - qay*qby - qaz*qbz;
1595
+
1596
+ return dest;
1597
+ }
1598
+
1599
+ /**
1600
+ * quat4.multiplyVec3(quat, vec[, dest]) -> vec3
1601
+ * - quat (quat4) : quat4 to transform the vector with
1602
+ * - vec (vec3) : vec3 to transform
1603
+ * - dest (vec3) : optional vec3 receiving calculated values. If not specified, result is written to +vec+.
1604
+ *
1605
+ * Transforms a vec3 with the given quaternion
1606
+ *
1607
+ * Returns:
1608
+ * dest if specified, vec otherwise
1609
+ **/
1610
+ quat4.multiplyVec3 = function(quat, vec, dest) {
1611
+ if(!dest) { dest = vec; }
1612
+
1613
+ var x = vec[0], y = vec[1], z = vec[2];
1614
+ var qx = quat[0], qy = quat[1], qz = quat[2], qw = quat[3];
1615
+
1616
+ // calculate quat * vec
1617
+ var ix = qw*x + qy*z - qz*y;
1618
+ var iy = qw*y + qz*x - qx*z;
1619
+ var iz = qw*z + qx*y - qy*x;
1620
+ var iw = -qx*x - qy*y - qz*z;
1621
+
1622
+ // calculate result * inverse quat
1623
+ dest[0] = ix*qw + iw*-qx + iy*-qz - iz*-qy;
1624
+ dest[1] = iy*qw + iw*-qy + iz*-qx - ix*-qz;
1625
+ dest[2] = iz*qw + iw*-qz + ix*-qy - iy*-qx;
1626
+
1627
+ return dest;
1628
+ }
1629
+
1630
+ /**
1631
+ * quat4.toMat3(quat[, dest]) -> mat3
1632
+ * - quat (quat4) : quat4 to create matrix from
1633
+ * - dest (mat3) : optional mat3 receiving operation result. If not specified, a new mat3 is created.
1634
+ *
1635
+ * Calculates a 3x3 matrix from the given quat4
1636
+ *
1637
+ * Returns:
1638
+ * dest if specified, a new mat3 otherwise
1639
+ **/
1640
+ quat4.toMat3 = function(quat, dest) {
1641
+ if(!dest) { dest = mat3.create(); }
1642
+
1643
+ var x = quat[0], y = quat[1], z = quat[2], w = quat[3];
1644
+
1645
+ var x2 = x + x;
1646
+ var y2 = y + y;
1647
+ var z2 = z + z;
1648
+
1649
+ var xx = x*x2;
1650
+ var xy = x*y2;
1651
+ var xz = x*z2;
1652
+
1653
+ var yy = y*y2;
1654
+ var yz = y*z2;
1655
+ var zz = z*z2;
1656
+
1657
+ var wx = w*x2;
1658
+ var wy = w*y2;
1659
+ var wz = w*z2;
1660
+
1661
+ dest[0] = 1 - (yy + zz);
1662
+ dest[1] = xy - wz;
1663
+ dest[2] = xz + wy;
1664
+
1665
+ dest[3] = xy + wz;
1666
+ dest[4] = 1 - (xx + zz);
1667
+ dest[5] = yz - wx;
1668
+
1669
+ dest[6] = xz - wy;
1670
+ dest[7] = yz + wx;
1671
+ dest[8] = 1 - (xx + yy);
1672
+
1673
+ return dest;
1674
+ }
1675
+
1676
+ /**
1677
+ * quat4.toMat4(quat[, dest]) -> mat4
1678
+ * - quat (quat4) : quat4 to create matrix from
1679
+ * - dest (mat4) : optional mat4 receiving calculated values. If not specified, a new mat4 is created.
1680
+ *
1681
+ * Calculates a 4x4 matrix from the given quat4
1682
+ *
1683
+ * Returns:
1684
+ * dest if specified, a new mat4 otherwise
1685
+ **/
1686
+ quat4.toMat4 = function(quat, dest) {
1687
+ if(!dest) { dest = mat4.create(); }
1688
+
1689
+ var x = quat[0], y = quat[1], z = quat[2], w = quat[3];
1690
+
1691
+ var x2 = x + x;
1692
+ var y2 = y + y;
1693
+ var z2 = z + z;
1694
+
1695
+ var xx = x*x2;
1696
+ var xy = x*y2;
1697
+ var xz = x*z2;
1698
+
1699
+ var yy = y*y2;
1700
+ var yz = y*z2;
1701
+ var zz = z*z2;
1702
+
1703
+ var wx = w*x2;
1704
+ var wy = w*y2;
1705
+ var wz = w*z2;
1706
+
1707
+ dest[0] = 1 - (yy + zz);
1708
+ dest[1] = xy - wz;
1709
+ dest[2] = xz + wy;
1710
+ dest[3] = 0;
1711
+
1712
+ dest[4] = xy + wz;
1713
+ dest[5] = 1 - (xx + zz);
1714
+ dest[6] = yz - wx;
1715
+ dest[7] = 0;
1716
+
1717
+ dest[8] = xz - wy;
1718
+ dest[9] = yz + wx;
1719
+ dest[10] = 1 - (xx + yy);
1720
+ dest[11] = 0;
1721
+
1722
+ dest[12] = 0;
1723
+ dest[13] = 0;
1724
+ dest[14] = 0;
1725
+ dest[15] = 1;
1726
+
1727
+ return dest;
1728
+ }
1729
+
1730
+ /**
1731
+ * quat4.slerp(quat, quat2, lerp[, dest]) -> quat4
1732
+ * - quat (quat4) : first quarternion
1733
+ * - quat2 (quat4) : second quaternion
1734
+ * - lerp (Number) : interpolation amount between the two inputs
1735
+ * - dest (quat4) : optional quat4 receiving calculated values. If not specified, result is written to +quat+.
1736
+ *
1737
+ * Performs a spherical linear interpolation between two quat4
1738
+ *
1739
+ * Returns:
1740
+ * dest if specified, quat otherwise
1741
+ **/
1742
+ quat4.slerp = function(quat, quat2, lerp, dest) {
1743
+ if(!dest) { dest = quat; }
1744
+
1745
+ var eps_lerp = lerp;
1746
+
1747
+ var dot = quat[0]*quat2[0] + quat[1]*quat2[1] + quat[2]*quat2[2] + quat[3]*quat2[3];
1748
+ if (dot < 0.0) {
1749
+ eps_lerp = -1.0 * lerp;
1750
+ }
1751
+
1752
+ dest[0] = 1.0 - lerp * quat[0] + eps_lerp * quat2[0];
1753
+ dest[1] = 1.0 - lerp * quat[1] + eps_lerp * quat2[1];
1754
+ dest[2] = 1.0 - lerp * quat[2] + eps_lerp * quat2[2];
1755
+ dest[3] = 1.0 - lerp * quat[3] + eps_lerp * quat2[3];
1756
+
1757
+ return dest;
1758
+ }
1759
+
1760
+ /**
1761
+ * quat4.str(quat) -> String
1762
+ * - quat (quat4) : quat4 to represent as a string
1763
+ *
1764
+ * Returns a string representation of a quaternion
1765
+ *
1766
+ * Returns:
1767
+ * string representation of quat
1768
+ **/
1769
+ quat4.str = function(quat) {
1770
+ return '[' + quat[0] + ', ' + quat[1] + ', ' + quat[2] + ', ' + quat[3] + ']';
1771
+ }
1772
+