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,697 @@
1
+ //= require "jax/webgl/core/events"
2
+ //= require "jax/webgl/scene"
3
+
4
+ /**
5
+ * class Jax.Camera
6
+ * includes Jax.Events.Methods
7
+ *
8
+ * Every object in Jax has a Camera associated with it, and is usually referred to simply
9
+ * as +camera+. Manipulating an object's camera is to manipulate the orientation of the
10
+ * object itself within the world.
11
+ *
12
+ * You can add event listeners to Jax.Camera to monitor its matrices for changes. Whenever
13
+ * a matrix changes, the object's orientation has been modified, so this is a good way to
14
+ * keep track of changes to an object's orientation. Add listeners like so:
15
+ *
16
+ * obj = new Jax.Model( ... );
17
+ * obj.camera.addEventListener('matrixUpdated', function() {
18
+ * // the object's orientation has changed
19
+ * });
20
+ *
21
+ * Note that no arguments are passed into the event listener in this case.
22
+ *
23
+ * See Jax.Events for more information about event listeners.
24
+ *
25
+ **/
26
+ Jax.Camera = (function() {
27
+ var LOCAL_VIEW = [0,0,-1], LOCAL_UP = [0,1,0], LOCAL_RIGHT = [1,0,0];
28
+
29
+ // used in tandem with _tmp[], see below
30
+ var POSITION = 0, VIEW = 1, RIGHT = 2, UP = 3, FORWARD = 4, SIDE = 5;
31
+
32
+ /*
33
+ handles storing data in the private _vecbuf, which is used solely to prevent
34
+ unnecessary allocation of temporary vectors. Note that _vecbuf is used for many
35
+ operations and data persistence not guaranteed (read: improbable).
36
+ */
37
+ function store(self, buftype) {
38
+ if (arguments.length == 2) {
39
+ // no x,y,z given -- find it
40
+ return storeVecBuf(self, buftype);
41
+ }
42
+ var buf = self._tmp[buftype];
43
+ buf[0] = arguments[2];
44
+ buf[1] = arguments[3];
45
+ buf[2] = arguments[4];
46
+ return buf;
47
+ }
48
+
49
+ function tmpRotQuat(self) {
50
+ return self._rotquat = self._rotquat || quat4.create();
51
+ }
52
+
53
+ function storeVecBuf(self, buftype) {
54
+ var world = self.rotation;
55
+
56
+ var position = (self._tmp[POSITION]);
57
+ var result = (self._tmp[buftype]);
58
+
59
+ vec3.set(self.position, position);
60
+
61
+ switch(buftype) {
62
+ case POSITION:
63
+ // we already have the position
64
+ return position;
65
+ break;
66
+ case VIEW:
67
+ quat4.multiplyVec3(world, LOCAL_VIEW, result);
68
+ break;
69
+ case RIGHT:
70
+ quat4.multiplyVec3(world, LOCAL_RIGHT, result);
71
+ break;
72
+ case UP:
73
+ quat4.multiplyVec3(world, LOCAL_UP, result);
74
+ break;
75
+ default:
76
+ throw new Error("Unexpected buftype: "+buftype);
77
+ }
78
+ return result;
79
+ }
80
+
81
+ function matrixUpdated(self) {
82
+ // Callback fires whenever one of the camera's matrices has changed.
83
+ // We need to use this to update other variables like normal matrix, frustum, etc,
84
+ // but we don't actually update them here because the user may be making several
85
+ // changes to the camera in sequence (and those updates would be useless).
86
+ // Instead we'll mark them as out-of-date and let their respective getters do the
87
+ // work.
88
+ // update the normal matrix
89
+ self.stale = true;
90
+ self.frustum_up_to_date = false;
91
+ }
92
+
93
+ function calculateMatrices(self) {
94
+ self.stale = false;
95
+
96
+ var pos = storeVecBuf(self, POSITION);
97
+ quat4.toMat4(self.rotation, self.matrices.mv);
98
+ mat4.translate(self.matrices.mv, vec3.negate(pos), self.matrices.mv);
99
+ mat4.inverse(self.matrices.mv);
100
+
101
+ mat4.toInverseMat3(self.matrices.mv, self.matrices.n);
102
+ mat3.transpose(self.matrices.n);
103
+
104
+ self.fireEvent('matrixUpdated');
105
+ }
106
+
107
+ return Jax.Class.create({
108
+ initialize: function() {
109
+ /**
110
+ * Jax.Camera#projection -> Object
111
+ * This property is undefined until either #ortho() or #perspective() is called. After a projection matrix
112
+ * has been initialized, this object will contain various metadata about the projection matrix, such as
113
+ * the width and height of the viewport.
114
+ *
115
+ * For orthogonal projection matrices, it contains the following information:
116
+ * width, height, depth
117
+ * left, right
118
+ * top, bottom
119
+ * near, far
120
+ *
121
+ * For perspective projection matrices, it contains the following information:
122
+ * width, height
123
+ * near, far
124
+ * fov (in degrees)
125
+ *
126
+ * Note that this information is here for reference only; modifying it will in no way modify the projection
127
+ * matrix itself. (For that, you need to make another call to #ortho() or #perspective().) Therefore,
128
+ * changing this object's properties is not recommended because doing so would no longer accurately reflect
129
+ * the parameters of the real projection matrix.
130
+ *
131
+ * Subsequent calls to #perspective() or #ortho() will cause this object to be regenerated. Because of this,
132
+ * it is not recommended to store any persistent data in this object.
133
+ **/
134
+
135
+ /* used for temporary storage, just to avoid repeatedly allocating temporary vectors */
136
+ this._tmp = [ vec3.create(), vec3.create(), vec3.create(), vec3.create(), vec3.create(), vec3.create() ];
137
+
138
+ this.rotation = quat4.create([0,0,0,1]);
139
+ this.position = vec3.create([0,0,0]);
140
+
141
+ this.matrices = { mv: mat4.identity(mat4.create()), p : mat4.identity(mat4.create()), n : mat3.create() };
142
+ this.frustum = new Jax.Scene.Frustum(this.matrices.mv, this.matrices.p);
143
+
144
+ this.addEventListener('updated', function() { matrixUpdated(this); });
145
+ this.reset();
146
+ this.setFixedYawAxis(true, vec3.UNIT_Y);
147
+ },
148
+
149
+ /**
150
+ * Jax.Camera#setFixedYawAxis(useFixedYaw[, axis = vec3(0,1,0)]) -> Jax.Camera
151
+ * - useFixedYaw (Boolean): set to true if you wish to fix the yaw axis, false otherwise
152
+ * - axis (vec3): optional vec3 to use as the yaw axis.
153
+ *
154
+ * Due to the nature of 3D rotation, rotated objects are subject to a phenomenon known as
155
+ * camera drift (also called Z drift or "roll" drift). This occurs when a series of
156
+ * rotations cause the object's up vector to become rotated, affecting a "tilt" around
157
+ * the object's local Z axis.
158
+ *
159
+ * Since this is not generally the expected outcome, Jax.Camera will by default set a
160
+ * fixed yaw axis, which prevents drift. You can disable it or change the axis around
161
+ * which yaw will be constrained by calling this function.
162
+ **/
163
+ setFixedYawAxis: function(useFixedYaw, axis) {
164
+ this.fixed_yaw = useFixedYaw;
165
+ if (axis) this.fixed_yaw_axis = vec3.create(axis);
166
+ },
167
+
168
+ /**
169
+ * Jax.Camera#getFrustum() -> Jax.Scene.Frustum
170
+ * Returns the frustum for the camera. If the frustum is out of date, it will
171
+ * be refreshed.
172
+ **/
173
+ getFrustum: function() {
174
+ if (!this.frustum_up_to_date) this.frustum.update();
175
+ this.frustum_up_to_date = true;
176
+ return this.frustum;
177
+ },
178
+
179
+ /**
180
+ * Jax.Camera#getPosition() -> vec3
181
+ * Returns the current world space position of this camera.
182
+ **/
183
+ getPosition: function() { return vec3.create(this.position); },
184
+
185
+ /**
186
+ * Jax.Camera#getViewVector() -> vec3
187
+ * Returns the view vector relative to this camera.
188
+ **/
189
+ getViewVector: function() { return vec3.create(storeVecBuf(this, VIEW)); },
190
+
191
+ /**
192
+ * Jax.Camera#getUpVector() -> vec3
193
+ * Returns the up vector relative to this camera.
194
+ **/
195
+ getUpVector: function() { return vec3.create(storeVecBuf(this, UP)); },
196
+
197
+ /**
198
+ * Jax.Camera#getRightVector() -> vec3
199
+ * Returns the right vector relative to this camera.
200
+ **/
201
+ getRightVector:function() { return vec3.create(storeVecBuf(this, RIGHT)); },
202
+
203
+ /**
204
+ * Jax.Camera#ortho(options) -> undefined
205
+ * - options (Object): the set of parameters used to calculate the projection matrix.
206
+ *
207
+ * Sets up an orthographic projection matrix. Objects will not appear to shrink as they grow
208
+ * more distant from the camera in this mode. This mode is frequently used by high-precision
209
+ * tools such as modeling programs, and is commonly found in games when rendering UIs,
210
+ * crosshairs and the like.
211
+ *
212
+ * * _top_ - the topmost coordinate visible on the scren. Defaults to 1.
213
+ * * _left_ - the leftmost coordinate visible on the screen. Defaults to -1.
214
+ * * _right_ - the rightmost coordinate visible on the screen. Defaults to 1.
215
+ * * _bottom_ - the bottommost coordinate visible on the screen. Defaults to -1.
216
+ * * _near_ - the nearest coordinate visible. Defaults to 0.01.
217
+ * * _far_ the furthest coordinate visible. Defaults to 200.
218
+ *
219
+ **/
220
+ ortho: function(options) {
221
+ if (typeof(options.left) == "undefined") options.left = -1;
222
+ if (typeof(options.right) == "undefined") options.right = 1;
223
+ if (typeof(options.top) == "undefined") options.top = 1;
224
+ if (typeof(options.bottom) == "undefined") options.bottom = -1;
225
+ if (typeof(options.far) == "undefined") options.far = 200;
226
+ options.near = options.near || 0.01;
227
+
228
+ mat4.ortho(options.left, options.right, options.bottom, options.top, options.near, options.far, this.matrices.p);
229
+ this.projection = {
230
+ width: options.right - options.left,
231
+ height: options.top - options.bottom,
232
+ depth: options.near - options.far,
233
+ left: options.left,
234
+ right: options.right,
235
+ near: options.near,
236
+ far: options.far,
237
+ top: options.top,
238
+ bottom: options.bottom
239
+ };
240
+ this.fireEvent('matrixUpdated');
241
+ },
242
+
243
+ /**
244
+ * Jax.Camera#setPosition(positionVector) -> undefined
245
+ * - positionVector (vec3): a vector representing the new position of the camera in world coordinates.
246
+ * Jax.Camera#setPosition(x, y, z) -> undefined
247
+ * - x (Number): the new X coordinate in world coordinates
248
+ * - y (Number): the new Y coordinate in world coordinates
249
+ * - z (Number): the new Z coordinate in world coordinates
250
+ *
251
+ * Sets the position of this camera.
252
+ **/
253
+ setPosition: function() {
254
+ switch(arguments.length) {
255
+ case 1: vec3.set(arguments[0], this.position); break;
256
+ case 3: vec3.set(arguments, this.position); break;
257
+ default: throw new Error("Invalid arguments for Camera#setPosition");
258
+ }
259
+
260
+ this.fireEvent('updated');
261
+
262
+ return this;
263
+ },
264
+
265
+ /**
266
+ * Jax.Camera#setDirection(vector) -> Jax.Camera
267
+ * Jax.Camera#setDirection(x,y,z) -> Jax.Camera
268
+ * - vector (vec3): the new direction that the camera will be pointing, relative to the camera
269
+ * - x (Number): the X component of the direction to point in, relative to the camera
270
+ * - y (Number): the Y component of the direction to point in, relative to the camera
271
+ * - z (Number): the Z component of the direction to point in, relative to the camera
272
+ *
273
+ **/
274
+ setDirection: function(vector) {
275
+ var vec;
276
+ if (arguments.length == 3) vec = arguments;
277
+ else vec = vec3.create(vector);
278
+ vec3.scale(vec, -1);
279
+ vec3.normalize(vec);
280
+
281
+ if (this.fixed_yaw) {
282
+ var right = vec3.normalize(vec3.cross(this.fixed_yaw_axis, vec, vec3.create()));
283
+ var up = vec3.normalize(vec3.cross(vec, right, vec3.create()));
284
+ quat4.fromAxes(vec, right, up, this.rotation);
285
+ } else {
286
+ var rotquat = vec3.toQuatRotation(storeVecBuf(this, VIEW), vec, tmpRotQuat(this));
287
+ quat4.multiply(rotquat, this.rotation, this.rotation);
288
+ }
289
+
290
+ quat4.normalize(this.rotation);
291
+ this.fireEvent('updated');
292
+ return this;
293
+ },
294
+
295
+ /**
296
+ * Jax.Camera#rotate(amount, x, y, z) -> rotated camera
297
+ * - amount (Number): amount to rotate, in radians
298
+ * - x (Number): X coordinate of the axis around which to rotate
299
+ * - y (Number): Y coordinate of the axis around which to rotate
300
+ * - z (Number): Z coordinate of the axis around which to rotate
301
+ * Jax.Camera.rotate(amount, vector) -> rotated camera
302
+ * - amount (Number): amount to rotate, in radians
303
+ * - vector (vec3): vector form of the axis around which to rotate
304
+ *
305
+ * Rotates the camera by the specified amount around some axis. Note that this
306
+ * axis is relative to the camera; see +Jax.Camera#rotateWorld+ if you need to
307
+ * rotate around an axis in world space.
308
+ **/
309
+ rotate: function() {
310
+ var amount = arguments[0];
311
+ var vec;
312
+ switch(arguments.length) {
313
+ case 2: vec = arguments[1]; break;
314
+ case 4: vec = this._tmp[0]; vec[0] = arguments[1]; vec[1] = arguments[2]; vec[2] = arguments[3]; break;
315
+ default: throw new Error("Invalid arguments");
316
+ }
317
+
318
+ return this.rotateWorld(amount, quat4.multiplyVec3(this.rotation, vec, this._tmp[0]));
319
+
320
+ // var axis = storeVecBuf(this, RIGHT);
321
+ // this.rotateWorld(amount, axis);
322
+ //
323
+ // var rotquat = quat4.fromAngleAxis(amount, vec, tmpRotQuat(this));
324
+ // quat4.normalize(rotquat);
325
+ // quat4.multiply(rotquat, this.rotation, this.rotation);
326
+ //
327
+ // this.fireEvent('updated');
328
+ // return this;
329
+ },
330
+
331
+ /**
332
+ * Jax.Camera#rotateWorld(amount, x, y, z) -> rotated camera
333
+ * - amount (Number): amount to rotate, in radians
334
+ * - x (Number): X coordinate of the axis around which to rotate
335
+ * - y (Number): Y coordinate of the axis around which to rotate
336
+ * - z (Number): Z coordinate of the axis around which to rotate
337
+ * Jax.Camera.rotate(amount, vector) -> rotated camera
338
+ * - amount (Number): amount to rotate, in radians
339
+ * - vector (vec3): vector form of the axis around which to rotate
340
+ *
341
+ * Rotates the camera by the specified amount around some axis. Note that this
342
+ * axis is in world space; see +Jax.Camera#rotate+ if you need to
343
+ * rotate around an axis relative to the camera's current orientation.
344
+ **/
345
+ rotateWorld: function() {
346
+ var amount = arguments[0];
347
+ var vec;
348
+ switch(arguments.length) {
349
+ case 2: vec = arguments[1]; break;
350
+ case 4: vec = this._tmp[0]; vec[0] = arguments[1]; vec[1] = arguments[2]; vec[2] = arguments[3]; break;
351
+ default: throw new Error("Invalid arguments");
352
+ }
353
+
354
+ var rotquat = quat4.fromAngleAxis(amount, vec, tmpRotQuat(this));
355
+ quat4.normalize(rotquat);
356
+ quat4.multiply(rotquat, this.rotation, this.rotation);
357
+
358
+ this.fireEvent('updated');
359
+ return this;
360
+ },
361
+
362
+ /**
363
+ * Jax.Camera#pitch(amount) -> Jax.Camera
364
+ * - amount (Number): rotation amount in radians
365
+ *
366
+ * Rotates around the camera's local X axis, resulting in a relative rotation up (positive) or down (negative).
367
+ **/
368
+ pitch: function(amount) {
369
+ var axis = storeVecBuf(this, RIGHT);
370
+ this.rotateWorld(amount, axis);
371
+ },
372
+
373
+ /**
374
+ * Jax.Camera#yaw(amount) -> Jax.Camera
375
+ * - amount (Number): rotation amount in radians
376
+ *
377
+ * Rotates around the camera's local Y axis, resulting in a relative rotation right (positive) or
378
+ * left (negative).
379
+ *
380
+ * If this camera uses a fixed yaw axis (true by default), that world-space axis is used instead of the
381
+ * camera's local Y axis.
382
+ *
383
+ * See also Jax.Camera#setFixedYawAxis
384
+ **/
385
+ yaw: function(amount) {
386
+ var axis;
387
+ if (this.fixed_yaw) axis = this.fixed_yaw_axis;
388
+ else axis = storeVecBuf(this, UP);
389
+ this.rotateWorld(amount, axis);
390
+ },
391
+
392
+ /**
393
+ * Jax.Camera#roll(amount) -> Jax.Camera
394
+ * - amount (Number): rotation amount in radians
395
+ *
396
+ * Rotates around the camera's local Z axis, resulting in a relative tilting counter-clockwise (positive)
397
+ * or clockwise (negative).
398
+ **/
399
+ roll: function(amount) {
400
+ var axis = storeVecBuf(this, VIEW);
401
+ this.rotateWorld(amount, axis);
402
+ },
403
+
404
+ /**
405
+ * Jax.Camera#reorient(view[, position]) -> Jax.Camera
406
+ * - view (vec3): the new direction, relative to the camera, that the camera will be pointing
407
+ * - position (vec3): an optional new position for the camera, in world space.
408
+ *
409
+ * Reorients this camera to look in the given direction and optionally to be
410
+ * repositioned according to the given position vector.
411
+ *
412
+ * Returns this camera after modification..
413
+ **/
414
+ reorient: function(view, pos) {
415
+ if (pos) this.setPosition(pos);
416
+ this.setDirection(view);
417
+ return this;
418
+ },
419
+
420
+ /**
421
+ * Jax.Camera#orient(viewVector, upVector[, positionVector]) -> Jax.Camera
422
+ * - viewVector (vec3): the new direction that the camera will be pointing
423
+ * - upVector (vec3): the new "up" direction perpendicular to the view
424
+ * - positionVector (vec3): optionally, a new position for the camera
425
+ * Jax.Camera#orient(vx, vy, vz, ux, uy, uz[, px, py, pz]) -> Jax.Camera
426
+ *
427
+ * Reorients this camera to be looking in the specified direction.
428
+ * Optionally, repositions this camera.
429
+ *
430
+ * **Deprecated.** Please use Jax.Camera#setDirection instead.
431
+ **/
432
+ orient: function(view, up) {
433
+ var pos = null;
434
+
435
+ if (Jax.environment != Jax.PRODUCTION)
436
+ alert("Jax.Camera#orient is deprecated. Please use Jax.Camera#reorient instead.\n\n"+new Error().stack);
437
+
438
+ switch(arguments.length) {
439
+ case 1:
440
+ view = store(this, VIEW, view[0], view[1], view[2]);
441
+ up = null;
442
+ break;
443
+ case 2:
444
+ view = store(this, VIEW, view[0], view[1], view[2]);
445
+ up = store(this, UP, up[0], up[1], up[2]);
446
+ break;
447
+ case 3:
448
+ if (typeof(arguments[0]) == "number") {
449
+ view = store(this, VIEW, arguments[0], arguments[1], arguments[2]);
450
+ up = null;
451
+ } else {
452
+ view = store(this, VIEW, view[0], view[1], view[2]);
453
+ up = store(this, UP, up[0], up[1], up[2]);
454
+ pos = store(this, POSITION, arguments[2][0], arguments[2][1], arguments[2][2]);
455
+ }
456
+ break;
457
+ case 6:
458
+ view = store(this, VIEW, arguments[0], arguments[1], arguments[2]);
459
+ up = store(this, UP, arguments[3], arguments[4], arguments[5]);
460
+ break;
461
+ case 9:
462
+ view = store(this, VIEW, arguments[0], arguments[1], arguments[2]);
463
+ up = store(this, UP, arguments[3], arguments[4], arguments[5]);
464
+ pos = store(this, POSITION, arguments[6], arguments[7], arguments[8]);
465
+ break;
466
+ default:
467
+ throw new Error("Unexpected arguments for Camera#orient");
468
+ }
469
+
470
+ if (pos) this.setPosition(pos);
471
+ this.setDirection(view);
472
+
473
+ return this;
474
+ },
475
+
476
+ /**
477
+ * Jax.Camera#lookAt(point[, pos]) -> Jax.Camera
478
+ * - point (vec3): the point, in world space, to look at
479
+ * - pos (vec3): an optional point to reposition this camera at, in world space,
480
+ * replacing its current position
481
+ *
482
+ **/
483
+ lookAt: function(point, pos) {
484
+ if (arguments.length > 2)
485
+ alert("Jax.Camera#lookAt with more than 2 arguments is deprecated. Please use only two arguments: the point to look at (a vec3) and an optional point to reposition the camera to (a vec3).\n\n"+new Error().stack);
486
+
487
+ if (pos) this.setPosition(pos);
488
+ else pos = store(this, POSITION);
489
+
490
+ var forward = this._tmp[FORWARD];
491
+ this.setDirection(vec3.subtract(point, pos, forward));
492
+ },
493
+
494
+ /**
495
+ * Jax.Camera#perspective(options) -> undefined
496
+ * - options (Object): a generic object whose properties will be used to set up the
497
+ * projection matrix.
498
+ *
499
+ * Sets up a traditional perspective view for this camera. Objects will appear to be
500
+ * smaller as they get further away from the camera.
501
+ *
502
+ * Options include:
503
+ * * _width_ - the width of the camera, in pixels. Required.
504
+ * * _height_ - the height of the camera, in pixels. Required.
505
+ * * _fov_ - the angle of the field of view, in degrees. Default: 45
506
+ * * _near_ - the distance of the near plane from the camera's actual position. Objects
507
+ * closer to the camera than this will not be seen, even if they are technically in
508
+ * front of the camera itself. Default: 0.01
509
+ * * _far_ - the distance of the far plane from the camera's actual position. Objects
510
+ * further away from the camera than this won't be seen. Default: 200
511
+ **/
512
+ perspective: function(options) {
513
+ options = options || {};
514
+ if (!options.width) throw new Error("Expected a screen width in Jax.Camera#perspective");
515
+ if (!options.height)throw new Error("Expected a screen height in Jax.Camera#perspective");
516
+ options.fov = options.fov || 45;
517
+ options.near = options.near || 0.01;
518
+ options.far = options.far || 200;
519
+
520
+ var aspect_ratio = options.width / options.height;
521
+ mat4.perspective(options.fov, aspect_ratio, options.near, options.far, this.matrices.p);
522
+ this.projection = {
523
+ width: options.width, height: options.height,
524
+ near: options.near, far: options.far,
525
+ fov: options.fov
526
+ };
527
+ this.fireEvent('matrixUpdated');
528
+ },
529
+
530
+ /**
531
+ * Jax.Camera#getTransformationMatrix() -> mat4
532
+ *
533
+ * Returns the transformation matrix. This matrix represents the camera's position and
534
+ * orientation in the world.
535
+ *
536
+ * If the matrix is outdated due to changes to the camera,
537
+ * it is automatically updated and then a 'matrixUpdated' event is fired.
538
+ **/
539
+ getTransformationMatrix: function() {
540
+ if (this.stale) calculateMatrices(this);
541
+ return this.matrices.mv;
542
+ },
543
+
544
+ /**
545
+ * Jax.Camera#getProjectionMatrix() -> mat4
546
+ *
547
+ * Returns the projection matrix. This matrix represents the projection of the world
548
+ * onto a screen.
549
+ **/
550
+ getProjectionMatrix: function() { return this.matrices.p; },
551
+
552
+ /**
553
+ * Jax.Camera#getNormalMatrix() -> mat3
554
+ *
555
+ * Returns the normal matrix, which is defined as the transpose of the inverse of the
556
+ * transformation matrix.
557
+ *
558
+ * This matrix is commonly used in lighting calculations.
559
+ *
560
+ * If the matrix is outdated due to changes to the camera,
561
+ * it is automatically updated and then a 'matrixUpdated' event is fired.
562
+ **/
563
+ getNormalMatrix: function() {
564
+ if (this.stale) calculateMatrices(this);
565
+ return this.matrices.n;
566
+ },
567
+
568
+ /**
569
+ * Jax.Camera#unproject(x, y[, z]) -> [[nearx, neary, nearz], [farx, fary, farz]]
570
+ * - x (Number): X coordinate in pixels
571
+ * - y (Number): Y coordinate in pixels
572
+ *
573
+ * Calculates a line segment in world space of the given pixel location. One end of the
574
+ * line segment represents the nearest world space point to which the pixel corresponds,
575
+ * while the other end of the line segment represents the farthest visible point, depending
576
+ * on the near and far planes of the projection matrix.
577
+ *
578
+ * You can also find a point at an arbitrary distance by passing a third argument representing
579
+ * the distance, Z, to travel from the near plane towards the far plane. Z should be a number
580
+ * between 0 and 1 (so think of it as a percentage). In this form, only one set of coordinates
581
+ * is returned: the actual world space position of the specified coordinate.
582
+ *
583
+ * This function was adapted from gluUnproject(), found at
584
+ * http://www.opengl.org/wiki/GluProject_and_gluUnProject_code
585
+ **/
586
+ unproject: function(winx, winy, winz) {
587
+ // winz is either 0 (near plane), 1 (far plane) or somewhere in between.
588
+ // if it's not given a value we'll produce coords for both.
589
+ if (typeof(winz) == "number") {
590
+ winx = parseFloat(winx);
591
+ winy = parseFloat(winy);
592
+ winz = parseFloat(winz);
593
+
594
+ var inf = [];
595
+ var mm = this.getTransformationMatrix(), pm = this.matrices.p;
596
+ var viewport = [0, 0, pm.width, pm.height];
597
+
598
+ //Calculation for inverting a matrix, compute projection x modelview; then compute the inverse
599
+ var m = mat4.set(mm, mat4.create());
600
+
601
+ mat4.inverse(m, m); // WHY do I have to do this? --see Jax.Context#reloadMatrices
602
+ mat4.multiply(pm, m, m);
603
+ mat4.inverse(m, m);
604
+
605
+ // Transformation of normalized coordinates between -1 and 1
606
+ inf[0]=(winx-viewport[0])/viewport[2]*2.0-1.0;
607
+ inf[1]=(winy-viewport[1])/viewport[3]*2.0-1.0;
608
+ inf[2]=2.0*winz-1.0;
609
+ inf[3]=1.0;
610
+
611
+ //Objects coordinates
612
+ var out = vec3.create();
613
+ mat4.multiplyVec4(m, inf, out);
614
+ if(out[3]==0.0)
615
+ return null;
616
+
617
+ out[3]=1.0/out[3];
618
+ return [out[0]*out[3], out[1]*out[3], out[2]*out[3]];
619
+ }
620
+ else
621
+ return [this.unproject(winx, winy, 0), this.unproject(winx, winy, 1)];
622
+ },
623
+
624
+ /**
625
+ * Jax.Camera#strafe(distance) -> the translated camera
626
+ * - distance (Number): the distance to move. If positive, the camera will move "right";
627
+ * if negative, the camera will move "left".
628
+ *
629
+ * Causes the camera to strafe, or move "sideways" along the right vector.
630
+ **/
631
+ strafe: function(distance) {
632
+ this.move(distance, storeVecBuf(this, RIGHT));
633
+ return this;
634
+ },
635
+
636
+ /**
637
+ * Jax.Camera#move(distance[, direction]) -> the translated camera
638
+ * - distance (Number): the distance to move. If positive, the camera will move "forward"
639
+ * along the direction vector; if negative, it will move "backward".
640
+ * - direction (vec3): the vector to move along. If not specified, this will default to
641
+ * the camera's view vector. That is, it will default to the direction
642
+ * the camera is pointing.
643
+ *
644
+ **/
645
+ move: function(distance, direction) {
646
+ if (!direction) direction = storeVecBuf(this, VIEW);
647
+ vec3.add(vec3.scale(direction, distance, this._tmp[FORWARD]), this.position, this.position);
648
+ this.fireEvent('updated');
649
+ return this;
650
+ },
651
+
652
+ /**
653
+ * Jax.Camera#projectMovement(forward[, strafe[, dest]]) -> vec3
654
+ * - forward (Number): the amount of forward movement. Use a negative number for going
655
+ * backwards.
656
+ * - strafe (Number): the amount of horizontal movement. Use a negative number for going
657
+ * left.
658
+ * - dest (vec3): an optional receiving vec3 to store the projected result. If omitted, a
659
+ * new vec3 will be created.
660
+ *
661
+ * Projects the given movement amounts along this camera's view and right vectors, returning
662
+ * the result without actually modifying this Camera.
663
+ **/
664
+ projectMovement: function(forward, strafe, dest) {
665
+ if (!strafe) strafe = 0;
666
+ if (!dest) dest = vec3.create();
667
+
668
+ var view = vec3.scale(storeVecBuf(this, VIEW), forward);
669
+ var right = vec3.scale(storeVecBuf(this, RIGHT), strafe);
670
+ vec3.set(this.position, dest);
671
+ vec3.add(view, dest, dest);
672
+ vec3.add(right, dest, dest);
673
+
674
+ return dest;
675
+ },
676
+
677
+ /**
678
+ * Jax.Camera#reset() -> the reset camera
679
+ *
680
+ * Resets this camera by moving it back to the origin and pointing it along the negative
681
+ * Z axis with the up vector along the positive Y axis.
682
+ **/
683
+ reset: function() {
684
+ this.position[0] = this.position[1] = this.position[2] = 0;
685
+ this.rotation[0] = this.rotation[1] = this.rotation[2] = 0;
686
+ this.rotation[3] = 1;
687
+ this.fireEvent('updated');
688
+ }
689
+ });
690
+ })();
691
+
692
+ /** alias of: Jax.Camera#setDirection
693
+ * Jax.Camera#setViewVector(vector) -> Jax.Camera
694
+ **/
695
+ Jax.Camera.prototype.setViewVector = Jax.Camera.prototype.setDirection;
696
+
697
+ Jax.Camera.addMethods(Jax.Events.Methods);
@@ -0,0 +1 @@
1
+ if (Jax.getGlobal()['WEBGL_CLEANUP']) Jax.getGlobal()['WEBGL_CLEANUP']();