spec/example_app/app/controllers/noise_controller.js in jax-0.0.0.5 vs spec/example_app/app/controllers/noise_controller.js in jax-0.0.0.6

- old
+ new

@@ -1,18 +1,50 @@ //= require "application_controller" var NoiseController = (function() { + var red, green, blue; + return Jax.Controller.create("noise", ApplicationController, { index: function() { - var model = new Jax.Model({mesh:new Jax.Mesh.Sphere({material:Material.find("blob")})}); + var model = new Blob(); this.world.addObject(model); this.player.camera.move(-5); - }, + + var light_options = { + type: Jax.POINT_LIGHT, + attenuation: { + constant: 0, + linear: 0, + quadratic: 0.002 + } + }; + + red = new LightSource(Jax.Util.normalizeOptions({ + position: [-20, 0, 20], color: { ambient: [0.2, 0, 0, 1], diffuse: [0.8, 0, 0, 1], specular:[1.0, 0, 0, 1] } + }, light_options)); + this.world.addLightSource(red); + green = new LightSource(Jax.Util.normalizeOptions({ + position: [ 20, 20, 20], color: { ambient: [0, 0.2, 0, 1], diffuse: [0, 0.8, 0, 1], specular:[0, 1.0, 0, 1] } + }, light_options)); + this.world.addLightSource(green); + + blue = new LightSource(Jax.Util.normalizeOptions({ + position: [ 20, -20, 20], color: { ambient: [0, 0, 0.2, 1], diffuse: [0, 0, 0.8, 1], specular:[0, 0, 1.0, 1] } + }, light_options)); + this.world.addLightSource(blue); + }, - // Some special actions are fired whenever the corresponding input is - // received from the user. - mouse_clicked: function(event) { + update: function(tc) { + this.rot = (this.rot || 0) + tc * 3.0; + function set(light, angle) { + var s = Math.sin(angle), c = Math.cos(angle); + light.camera.setPosition(s*20, c*20, 20); + } + var dif = Math.deg2rad(120); + set(red, this.rot + dif); + set(blue, this.rot + dif*2); + set(green, this.rot + dif*3); } }); })();