From fc7d76637dc981cfcd824f12e92d389b2e038028 Mon Sep 17 00:00:00 2001 From: Mahdi Dibaiee Date: Wed, 28 Jan 2015 19:26:03 +0330 Subject: [PATCH] [WIP] New Demo :sparkles: --- build.js | 126 ++++++++++++++++++++++--- build.js.map | 2 +- demos/fireworks/demo.js | 4 +- demos/fireworks/index.html | 2 +- demos/mouse-gravitation/demo.js | 68 +++++++++++++ demos/mouse-gravitation/index.html | 14 +++ demos/mouse-gravitation/lithree.min.js | 2 + src/lib/force.js | 33 +++++++ src/lib/forces/global-gravity.js | 12 +++ src/lib/forces/gravity.js | 26 +++++ src/lib/particle.js | 2 +- src/lib/play.js | 29 +++--- src/main.js | 4 +- 13 files changed, 289 insertions(+), 35 deletions(-) create mode 100644 demos/mouse-gravitation/demo.js create mode 100644 demos/mouse-gravitation/index.html create mode 100644 demos/mouse-gravitation/lithree.min.js create mode 100644 src/lib/force.js create mode 100644 src/lib/forces/global-gravity.js create mode 100644 src/lib/forces/gravity.js diff --git a/build.js b/build.js index d27fbb4..3052f11 100644 --- a/build.js +++ b/build.js @@ -507,15 +507,113 @@ - System.register("src/lib/play", ["src/lib/frames", "src/lib/gravity", "src/main"], function ($__export) { + System.register("src/lib/forces/global-gravity", ["src/lib/vector", "src/main"], function ($__export) { + "use strict"; + var __moduleName = "src/lib/forces/global-gravity"; + var Vector, Bolt; + function GlobalGravity(mass) { + var g = arguments[1] !== void 0 ? arguments[1] : Bolt.ugravitation || 10; + this.force = new Vector(0, -mass * g, 0); + } + return { + setters: [function (m) { + Vector = m["default"]; + }, function (m) { + Bolt = m["default"]; + }], + execute: function () { + GlobalGravity.prototype.apply = function (particle, duration) { + particle.acceleration.add(this.force); + }; + $__export("default", GlobalGravity); + } + }; + }); + + + + System.register("src/lib/forces/gravity", ["src/lib/vector", "src/main"], function ($__export) { + "use strict"; + var __moduleName = "src/lib/forces/gravity"; + var Vector, Bolt; + function Gravity(o1, o2) { + var mass = o1.mass * o2.mass; + var g = Bolt.ugravitation || 10; + var acc = mass * g; + var distance = new Vector(o1.position.x - o2.position.x, o1.position.y - o2.position.y, o1.position.z - o2.position.z); + this.force = new Vector(acc / (distance.x * distance.x), acc / (distance.y * distance.y), acc / (distance.z * distance.z)); + } + return { + setters: [function (m) { + Vector = m["default"]; + }, function (m) { + Bolt = m["default"]; + }], + execute: function () { + Gravity.prototype.apply = function (particle, duration) { + particle.acceleration.add(this.force); + }; + $__export("default", Gravity); + } + }; + }); + + + + System.register("src/lib/force", ["src/lib/vector", "src/lib/forces/global-gravity", "src/lib/forces/gravity"], function ($__export) { + "use strict"; + var __moduleName = "src/lib/force"; + var Vector, GlobalGravity, Gravity, Force; + return { + setters: [function (m) { + Vector = m["default"]; + }, function (m) { + GlobalGravity = m["default"]; + }, function (m) { + Gravity = m["default"]; + }], + execute: function () { + Force = { + registry: [], + generators: { + GlobalGravity: GlobalGravity, + Gravity: Gravity + }, + add: function (particle, force) { + this.registry.push([particle, force]); + return this.forces; + }, + remove: function (particle, force) { + var reg = this.registry; + this.registry.forEach(function (el, i) { + if (el[0] === particle && el[1] === force) reg.splice(i, 1); + }); + }, + clear: function () { + this.registry.length = 0; + }, + run: function (duration) { + this.registry.forEach(function (el) { + el[1].apply(el[0], duration); + }); + } + }; + $__export("default", Force); + } + }; + }); + + + + System.register("src/lib/play", ["src/lib/frames", "src/lib/force", "src/main"], function ($__export) { "use strict"; var __moduleName = "src/lib/play"; - var Frames, Gravity, Bolt, reqAnimFrame, cancelAnimFrame, Play; + var Frames, Force, Bolt, reqAnimFrame, cancelAnimFrame, Play; return { setters: [function (m) { Frames = m["default"]; }, function (m) { - Gravity = m["default"]; + Force = m["default"]; }, function (m) { Bolt = m["default"]; }], @@ -532,13 +630,14 @@ len = Bolt.objects.length; i < len; i++) { var object = Bolt.objects[i]; if (Bolt.configs.globalGravity) { - var force = Gravity.global(object.inverseMass); - object.position.add(object.velocity.clone().scalar(Frames.elapsed)); - var acc = object.acceleration.clone(); - acc.add(force); - object.velocity.add(acc.scalar(Frames.elapsed)); - object.velocity.scalar(Math.pow(object.damping, Frames.elapsed)); + var gravity = new Force.generators.GlobalGravity(object.mass); + Force.add(object, gravity); } + object.position.add(object.velocity.clone().scalar(Frames.elapsed)); + object.acceleration.scalar(Frames.elapsed); + object.velocity.add(object.acceleration); + Force.run(); + Force.clear(); } if (fn) fn.apply(this, arguments); loop(); @@ -561,10 +660,10 @@ - System.register("src/main", ["src/lib/vector", "src/lib/particle", "src/lib/gravity", "src/lib/frames", "src/lib/play"], function ($__export) { + System.register("src/main", ["src/lib/vector", "src/lib/particle", "src/lib/gravity", "src/lib/frames", "src/lib/play", "src/lib/force"], function ($__export) { "use strict"; var __moduleName = "src/main"; - var Vector, Particle, Gravity, Frames, Play, Bolt; + var Vector, Particle, Gravity, Frames, Play, Force, Bolt; return { setters: [function (m) { Vector = m["default"]; @@ -576,6 +675,8 @@ Frames = m["default"]; }, function (m) { Play = m["default"]; + }, function (m) { + Force = m["default"]; }], execute: function () { Bolt = { @@ -591,7 +692,8 @@ Particle: Particle, Gravity: Gravity, Frames: Frames, - Play: Play + Play: Play, + Force: Force }; window.Bolt = Bolt; $__export("default", Bolt); diff --git a/build.js.map b/build.js.map index a211f21..3347988 100644 --- a/build.js.map +++ b/build.js.map @@ -1 +1 @@ -{"version":3,"sources":["src/lib/vector.js","src/lib/particle.js","src/lib/gravity.js","src/lib/frames.js","src/lib/play.js","src/main.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;AAClB,cAAQ,GAAA,CAAA,CAAA,CAAA,EAAK,EAAA,CAAG;AACd,eAAG,QAAQ,CAAE,CAAA,CAAC,EAAI,CAAA,CAAA,CAAE,CAAA,CAAC,CAAC;UACxB;AAAA,AACA,eAAO,CAAA,IAAG,QAAQ,CAAC;QACrB;AAEA,cAAM,CAAG,GAAC;AAEV,aAAK,CAAG,OAAK;AACb,eAAO,CAAG,SAAO;AACjB,cAAM,CAAG,QAAM;AACf,aAAK,CAAG,OAAK;AACb,WAAG,CAAG,KAAG;AAAA,MACX;AAEA,WAAK,KAAK,EAAI,KAAG,CAAC;yBAEH,KAAG;;;;AAAC","file":"/home/mahdi/Documents/Workshop/bolt/build.js"} \ No newline at end of file +{"version":3,"sources":["src/lib/vector.js","src/lib/particle.js","src/lib/gravity.js","src/lib/frames.js","src/lib/forces/global-gravity.js","src/lib/forces/gravity.js","src/lib/force.js","src/lib/play.js","src/main.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,OAAK,CAAE,CAAA,EAAI,EAAA,CAAG,CAAA,CAAA,EAAI,EAAA,CAAG,CAAA,CAAA,EAAI,EAAA,CAAG;AACnC,OAAG,CAAC,CAAC,IAAG,WAAa,OAAK,CAAC;AAAG,WAAO,IAAI,OAAK,AAAC,CAAC,CAAA,CAA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C","file":"/home/mahdi/Documents/Workshop/bolt/build.js"} \ No newline at end of file diff --git a/demos/fireworks/demo.js b/demos/fireworks/demo.js index 9ee756b..d91daef 100644 --- a/demos/fireworks/demo.js +++ b/demos/fireworks/demo.js @@ -55,7 +55,7 @@ Bolt.Play.start(function() { fireworks.push(new Firework({ type: 0, position: Bolt.Vector(window.innerWidth/4, 0, 0), - mass: 4 + mass: 2 })); count = 0; } @@ -79,7 +79,7 @@ Bolt.Play.start(function() { type: 1, position: fw.particle.position.clone(), velocity: vel, - mass: 2 + mass: 1 }); fireworks.push(childFirework); } diff --git a/demos/fireworks/index.html b/demos/fireworks/index.html index d21d5ce..bb0d5b9 100644 --- a/demos/fireworks/index.html +++ b/demos/fireworks/index.html @@ -2,7 +2,7 @@ - Bolt + Bolt | Fireworks Demo

diff --git a/demos/mouse-gravitation/demo.js b/demos/mouse-gravitation/demo.js new file mode 100644 index 0000000..93c4d46 --- /dev/null +++ b/demos/mouse-gravitation/demo.js @@ -0,0 +1,68 @@ +var world = new LiThree.World(), + renderer = new LiThree.WebGLRenderer(window.innerWidth, window.innerHeight, world), + camera = renderer.camera; + +camera.position.z -= 10; + +var light = new LiThree.Light.Point(); +light.diffuseColor.hex = '#16A086'; +light.position.x = -10; +light.position.z = -20; +light.position.y = 0; +world.add(light); + +// renderer.canvas.style.setProperty('background', 'black'); + + +var mouse = new Bolt.Particle({ + position: Bolt.Vector(0, 0, 0), + mass: 1 +}); + +var middle = new Bolt.Vector(window.innerWidth / 2, window.innerHeight / 2, 0); + +for(var i = 0; i < 20; i++) { + var p = new Bolt.Particle({ + position: middle.clone(), + mass: 1 + }); + + var sphere = new LiThree.ObjectFactory.Sphere(50, 20, 20); + sphere.color.rgb(0.2, 0.2, 0.2); + + world.add(sphere); + + p.view = sphere; +} + +renderer.initShapes(); + +function syncPositions(particle) { + particle.view.position.x = particle.position.x; + particle.view.position.y = particle.position.y; + particle.view.position.z = particle.position.z; +} + +Bolt.configs.globalGravity = false; + +Bolt.Play.start(function() { + // i = 1 Ignore mouse + for(var i = 1, len = Bolt.objects.length; i < len; i++) { + var p = Bolt.objects[i]; + + // var mouseGravity = new Bolt.Force.generators.Gravity(p, mouse); + + // Bolt.Force.add(p, mouseGravity); + + syncPositions(p); + } + + renderer.draw(); +}); + +document.body.appendChild(renderer.canvas); + +renderer.canvas.addEventListener('mousemove', function(e) { + mouse.position.x = e.pageX; + mouse.position.y = e.pageY; +}); \ No newline at end of file diff --git a/demos/mouse-gravitation/index.html b/demos/mouse-gravitation/index.html new file mode 100644 index 0000000..a76d875 --- /dev/null +++ b/demos/mouse-gravitation/index.html @@ -0,0 +1,14 @@ + + + + + Bolt | Mouse Gravitation Demo + + +

+ + + + + + \ No newline at end of file diff --git a/demos/mouse-gravitation/lithree.min.js b/demos/mouse-gravitation/lithree.min.js new file mode 100644 index 0000000..7fcb532 --- /dev/null +++ b/demos/mouse-gravitation/lithree.min.js @@ -0,0 +1,2 @@ +!function(a){"use strict";function b(){var a,b,c=void 0===arguments[0]?1:arguments[0],d=void 0===arguments[1]?20:arguments[1],e=new y;e.vertices.push(0,0,0),e.vertexIndex=[],e.vertexNormals=[];var f=Math.PI/(d-1);for(d*=2,b=0,a=1;d>a;b+=f,a++)e.vertices.push(Math.cos(b)*c,Math.sin(b)*c,0);for(a=0;a=a;b+=h,a++){var l=new w(Math.cos(b)*d,j,Math.sin(b)*d),m=new w(Math.cos(b)*e,k,Math.sin(b)*e),n=l.cross(m);g.vertexNormals.push(n.x,n.y,n.z),g.vertexNormals.push(n.x,n.y,n.z),g.vertices.push(l.x,l.y,l.z),g.vertices.push(m.x,m.y,m.z)}for(a=0;a=a;a++){var k=a*Math.PI/d,l=Math.sin(k),m=Math.cos(k);for(b=0;e>=b;b++){var n=2*b*Math.PI/e,o=Math.sin(n),p=Math.cos(n),q=p*l,r=m,s=o*l,t=1-b/e,u=1-a/d;h.push(q),h.push(r),h.push(s),j.push(t),j.push(u),g.push(c*q),g.push(c*r),g.push(c*s)}}var v=[];for(a=0;d>a;a++)for(b=0;e>b;b++){var w=a*(e+1)+b,x=w+e+1;v.push(w),v.push(x),v.push(w+1),v.push(x),v.push(x+1),v.push(w+1)}return f.vertexIndex=v,f.vertexNormals=h,f.vertices=g,f.darwingFunction=i.drawingFunctions.ELEMENTS,f.drawingMode=i.drawingMode.TRIANGLES,f}var f=function(a,b,c){b&&Object.defineProperties(a,b),c&&Object.defineProperties(a.prototype,c)},g=function(){function a(){var a=void 0===arguments[0]?.785398:arguments[0],b=void 0===arguments[1]?1:arguments[1],c=void 0===arguments[2]?.1:arguments[2],d=void 0===arguments[3]?100:arguments[3];this.fovy=a,this.aspect=b,this.near=c,this.far=d,this.matrix=new v,this.lookAt=new w,this.position=new w,this.rotation=new w,this.up=new w,this._zoom=1}return f(a,null,{zoom:{set:function(a){if(0>a)throw"Zoom should be equal or greater than 0";this._zoom=a},get:function(){return this._zoom},enumerable:!0,configurable:!0},updatePerspective:{value:function(){var a=2*Math.atan(Math.tan(.5*this.fovy)/this._zoom);this.matrix.identity(),this.matrix.perspective(a,this.aspect,this.near,this.far)},writable:!0,enumerable:!0,configurable:!0},getMatrix:{value:function(){var a=new v;return a.identity(),a.translate(this.position),a.rotateX(this.rotation.x),a.rotateY(this.rotation.y),a.rotateZ(this.rotation.z),a},writable:!0,enumerable:!0,configurable:!0}}),a}(),f=function(a,b,c){b&&Object.defineProperties(a,b),c&&Object.defineProperties(a.prototype,c)},h=function(){function a(){var a=void 0===arguments[0]?1:arguments[0],b=void 0===arguments[1]?1:arguments[1],c=void 0===arguments[2]?1:arguments[2],d=void 0===arguments[3]?1:arguments[3];this.array=[a,b,c,d]}return f(a,null,{hex:{set:function(a){var b=/^#?([a-f\d])([a-f\d])([a-f\d])$/i;a=a.replace(b,function(a,b,c,d){return b+b+c+c+d+d});var c=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(a);this.array[0]=parseInt(c[1],16)/255,this.array[1]=parseInt(c[2],16)/255,this.array[2]=parseInt(c[3],16)/255},get:function(){var a=function(a){var b=a.toString(16);return 1===b.length?"0"+b:b};return"#"+a(this.array[0])+a(this.array[1])+a(this.array[2])},enumerable:!0,configurable:!0},rgb:{value:function(a,b,c){return this.array[0]=a,this.array[1]=b,this.array[2]=c,this},writable:!0,enumerable:!0,configurable:!0},alpha:{value:function b(b){return this.array[3]=b,this},writable:!0,enumerable:!0,configurable:!0},rgba:{value:function(a,b,c,d){return this.rgb(a,b,c),this.alpha(d),this},writable:!0,enumerable:!0,configurable:!0},toArray:{value:function(){var a=void 0===arguments[0]?3:arguments[0];return this.array.slice(0,a)},writable:!0,enumerable:!0,configurable:!0}}),a}(),i={};if(WebGLRenderingContext){var j=WebGLRenderingContext;i={support:!0,drawingMode:{POINTS:j.POINTS,LINES:j.LINES,LINE_LOOP:j.LINE_LOOP,LINE_STRIP:j.LINE_STRIP,TRIANGLES:j.TRIANGLES,TRIANGLE_FAN:j.TRIANGLE_FAN,TRIANGLE_STRIP:j.TRIANGLE_STRIP},drawingFunctions:{ARRAYS:1,ELEMENTS:0}}}else i.support=!1;var f=function(a,b,c){b&&Object.defineProperties(a,b),c&&Object.defineProperties(a.prototype,c)},k=function(){function a(){this._events={}}return f(a,null,{on:{value:function(a,b){return this._events[a]=this._events[a]||[],this._events[a].push(b),this},writable:!0,enumerable:!0,configurable:!0},once:{value:function(a,b){var c=function(){d.off(a,c),b.apply(this,arguments)},d=this;return c.listener=b,this.on(a,c),this},writable:!0,enumerable:!0,configurable:!0},off:{value:function(a,b){var c=this._events[a];if(void 0!==c){for(var d=0;de;e+=1)c[e].apply(this,a)}return this},writable:!0,enumerable:!0,configurable:!0}}),a}(),f=function(a,b,c){b&&Object.defineProperties(a,b),c&&Object.defineProperties(a.prototype,c)},l=function(){function a(){this.children=[],this.lights=[]}return f(a,null,{add:{value:function(a){"light"===a.type?this.lights.push(a):"object"===a.type&&this.children.push(a)},writable:!0,enumerable:!0,configurable:!0},remove:{value:function(a){"light"===a.type?this.lights.splice(this.lights.indexOf(a),1):"object"===a.type&&this.children.splice(this.children.indexOf(a),1)},writable:!0,enumerable:!0,configurable:!0}}),a}(),m=0,n=function(){this.index=m++,this.type="light"},f=function(a,b,c){b&&Object.defineProperties(a,b),c&&Object.defineProperties(a.prototype,c)},o=function G(a,b,c){var d=Object.getOwnPropertyDescriptor(a,b);if(void 0===d){var e=Object.getPrototypeOf(a);return null===e?void 0:G(e,b,c)}if("value"in d&&d.writable)return d.value;var f=d.get;return void 0===f?void 0:f.call(c)},p=function(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function, not "+typeof b);a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}),b&&(a.__proto__=b)},q=function(a){function b(){o(Object.getPrototypeOf(b.prototype),"constructor",this).call(this),this.color=new h(1,1,1),this.direction=new w(1,1,1)}return p(b,a),f(b,null,{program:{value:function(a){var b=this,c=a.uniform("vec3",function(){this.value(b.direction)}),d=a.uniform("vec3",function(){this.value(b.color.toArray())});a.code("%lw += %c * max(dot(transformedNormal, %ld), 0.0);",{lw:"lightWeight",ld:c,c:d})},writable:!0,enumerable:!0,configurable:!0}}),b}(n),f=function(a,b,c){b&&Object.defineProperties(a,b),c&&Object.defineProperties(a.prototype,c)},o=function H(a,b,c){var d=Object.getOwnPropertyDescriptor(a,b);if(void 0===d){var e=Object.getPrototypeOf(a);return null===e?void 0:H(e,b,c)}if("value"in d&&d.writable)return d.value;var f=d.get;return void 0===f?void 0:f.call(c)},p=function(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function, not "+typeof b);a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}),b&&(a.__proto__=b)},r=function(a){function b(){o(Object.getPrototypeOf(b.prototype),"constructor",this).call(this),this.specularColor=new h(.5,.5,.5),this.diffuseColor=new h(.3,.3,.3),this.position=new w(-10,4,-20)}return p(b,a),f(b,null,{program:{value:function(a){var b=this,c=a.uniform("vec3",function(){this.value(b.specularColor.toArray())}),d=a.uniform("vec3",function(){this.value(b.diffuseColor.toArray())}),e=a.uniform("vec3",function(){this.value(b.position)});a.code("\nvec3 %ld = normalize(%lp - %vp.xyz);\nfloat %sw = 0.0;\n\nif (bSpecular) {\n %sw = pow(max(dot(reflect(-%ld, normal), normalize(-%vp.xyz)), 0.0), fShininess);\n}\n\nfloat %dw = max(dot(normal, -%ld), 0.0);\n%lw += %sc * %sw + %dc * %dw;\n ",{sc:c,dc:d,lp:e,ld:"lightDirection"+this.index,vp:"vPosition",sw:"specularLightWeighting"+this.index,dw:"diffuseLightWeighting"+this.index,lw:"lightWeight",fs:"fShininess"})},writable:!0,enumerable:!0,configurable:!0}}),b}(n),s=function(){this.shininess=30,this.lighting=!0,this.specular=!0},f=function(a,b,c){b&&Object.defineProperties(a,b),c&&Object.defineProperties(a.prototype,c)},p=function(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function, not "+typeof b);a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}),b&&(a.__proto__=b)},t=function(a){function b(){for(var a=9;a--;)this.push(0)}return p(b,a),f(b,null,{transpose:{value:function(){var a=this[1],b=this[2],c=this[5];return this[1]=this[3],this[2]=this[6],this[3]=a,this[5]=this[7],this[6]=b,this[7]=c,this},writable:!0,enumerable:!0,configurable:!0},toArray:{value:function(){for(var a=[],b=9;b--;)a[b]=this[b];return a},writable:!0,enumerable:!0,configurable:!0}}),b}(Array),f=function(a,b,c){b&&Object.defineProperties(a,b),c&&Object.defineProperties(a.prototype,c)},p=function(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function, not "+typeof b);a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}}),b&&(a.__proto__=b)},u=1e-5,v=function(a){function b(){for(var a=16;a--;)this.push(0)}return p(b,a),f(b,{multiply:{value:function(a,c){var d=new b,e=a[0],f=a[1],g=a[2],h=a[3],i=a[4],j=a[5],k=a[6],l=a[7],m=a[8],n=a[9],o=a[10],p=a[11],q=a[12],r=a[13],s=a[14],t=a[15],u=c[0],v=c[1],w=c[2],x=c[3];return d[0]=u*e+v*i+w*m+x*q,d[1]=u*f+v*j+w*n+x*r,d[2]=u*g+v*k+w*o+x*s,d[3]=u*h+v*l+w*p+x*t,u=c[4],v=c[5],w=c[6],x=c[7],d[4]=u*e+v*i+w*m+x*q,d[5]=u*f+v*j+w*n+x*r,d[6]=u*g+v*k+w*o+x*s,d[7]=u*h+v*l+w*p+x*t,u=c[8],v=c[9],w=c[10],x=c[11],d[8]=u*e+v*i+w*m+x*q,d[9]=u*f+v*j+w*n+x*r,d[10]=u*g+v*k+w*o+x*s,d[11]=u*h+v*l+w*p+x*t,u=c[12],v=c[13],w=c[14],x=c[15],d[12]=u*e+v*i+w*m+x*q,d[13]=u*f+v*j+w*n+x*r,d[14]=u*g+v*k+w*o+x*s,d[15]=u*h+v*l+w*p+x*t,d},writable:!0,enumerable:!0,configurable:!0}},{identity:{value:function(){for(var a=16;a--;)this[a]=a%5===0?1:0;return this},writable:!0,enumerable:!0,configurable:!0},determinant:{value:function(){var a=this[0],b=this[1],c=this[2],d=this[3],e=this[4],f=this[5],g=this[6],h=this[7],i=this[8],j=this[9],k=this[10],l=this[11],m=this[12],n=this[13],o=this[14],p=this[15],q=a*f-b*e,r=a*g-c*e,s=a*h-d*e,t=b*g-c*f,u=b*h-d*f,v=c*h-d*g,w=i*n-j*m,x=i*o-k*m,y=i*p-l*m,z=j*o-k*n,A=j*p-l*n,B=k*p-l*o;return q*B-r*A+s*z+t*y-u*x+v*w},writable:!0,enumerable:!0,configurable:!0},perspective:{value:function(a,b,c,d){var e=1/Math.tan(a/2),f=1/(c-d);return this[0]=e/b,this[1]=0,this[2]=0,this[3]=0,this[4]=0,this[5]=e,this[6]=0,this[7]=0,this[8]=0,this[9]=0,this[10]=(d+c)*f,this[11]=-1,this[12]=0,this[13]=0,this[14]=2*d*c*f,this[15]=0,this},writable:!0,enumerable:!0,configurable:!0},lookAt:{value:function(a,b,c){var d,e,f,g,h,i,j,k,l,m;return Math.abs(a.x-b.x)0){b.attribute("vec3",function(){this.value(a.buffers.normals)},"vNormal"),b.uniform("mat3",function(){var b=a.getMatrix(d.camera),c=b.toInverseMat3().transpose();this.value(c)},"nMatrix"),b.uniform("float",function(){this.value(a.material.shininess)},"fShininess"),b.uniform("bool",function(){this.value(a.material.specular)},"bSpecular"),b.code("vec3 transformedNormal = nMatrix * vNormal;"),b.code("vec3 normal = normalize(transformedNormal);"),b.code("%lw = vec3(0.0, 0.0, 0.0);",{lw:b.varying("vec3","lightWeight")});for(var g in e.lights)e.lights[g].program(b,c);c.code("gl_FragColor = vec4(%lw + %c, 1.0);",{c:f,lw:c.varying("vec3","lightWeight")})}else c.code("gl_FragColor = vec4(%c, 1.0);",{c:f})},writable:!0,enumerable:!0,configurable:!0},use:{value:function(){this.gl.useProgram(this.program)},writable:!0,enumerable:!0,configurable:!0},compile:{value:function(a,b){var c=this.gl,d=c.createShader(b);c.shaderSource(d,a),c.compileShader(d);var e=c.getShaderParameter(d,c.COMPILE_STATUS);if(!e)throw"Could not compile shader:\n"+c.getShaderInfoLog(d)+"\n"+a;return d},writable:!0,enumerable:!0,configurable:!0},create:{value:function(){var a=this.gl,b=a.createProgram();a.attachShader(b,this.compile(this.vertexProgram.toString(),a.VERTEX_SHADER)),a.attachShader(b,this.compile(this.fragmentProgram.toString(),a.FRAGMENT_SHADER)),a.linkProgram(b);var c=a.getProgramParameter(b,a.LINK_STATUS);if(!c)throw"Program failed to link:"+a.getProgramInfoLog(b);return this.program=b,this.vertexProgram.init(),this.fragmentProgram.init(),b},writable:!0,enumerable:!0,configurable:!0}}),a}(),f=function(a,b,c){b&&Object.defineProperties(a,b),c&&Object.defineProperties(a.prototype,c)},D=0,E=function(){function a(a,b){this._variables={},this._programmer=b,this._code="",this.type=a}return f(a,null,{init:{value:function(){for(var a in this._variables)"undefined"!=typeof this._variables[a].create&&this._variables[a].create()},writable:!0,enumerable:!0,configurable:!0},uniform:{value:function(a){var b=this,c=void 0===arguments[1]?null:arguments[1],d=void 0===arguments[2]?"tmp_"+D++:arguments[2];return function(){var e=new F(a,d,b._programmer);return e.onupdate=c,b._variables[d]=e,e}()},writable:!0,enumerable:!0,configurable:!0},attribute:{value:function(a){var b=this,c=void 0===arguments[1]?null:arguments[1],d=void 0===arguments[2]?"tmp_"+D++:arguments[2];return function(){var e=new B(a,d,b._programmer);return e.onupdate=c,b._variables[d]=e,e}()},writable:!0,enumerable:!0,configurable:!0},varying:{value:function(a){var b=this,c=void 0===arguments[1]?"tmp_"+D++:arguments[1];return function(){return b._variables[c]={name:c,type:a,prefix:"varying"},b._variables[c]}()},writable:!0,enumerable:!0,configurable:!0},precision:{value:function(a,b){var c="tmp_"+D++;return this._variables[c]={name:b,type:a,prefix:"precision"},this._variables[c]},writable:!0,enumerable:!0,configurable:!0},code:{value:function b(b,a){var c;if("undefined"!=typeof a)for(var d in a)c="object"==typeof a[d]?a[d].name:a[d],b=b.replace(new RegExp("%"+d,"gm"),c);return this._code+=b+"\n",this},writable:!0,enumerable:!0,configurable:!0},getVariable:{value:function(a){if("undefined"!=typeof this._variables[a])return this._variables[a];throw"The variable "+a+" is not set."},writable:!0,enumerable:!0,configurable:!0},toString:{value:function(){var a,b,c="";for(a in this._variables)b=this._variables[a],b instanceof F?c+="uniform "+b.type+" "+b.name+";\n":b instanceof B?c+="attribute "+b.type+" "+b.name+";\n":"object"==typeof b&&(c+=""+b.prefix+" "+b.type+" "+b.name+";\n");return c+="void main() {\n"+this._code+"\n}"},writable:!0,enumerable:!0,configurable:!0}}),a}(),f=function(a,b,c){b&&Object.defineProperties(a,b),c&&Object.defineProperties(a.prototype,c)},F=function(){function a(a,b,c){this.type=a,this.name=b,this.onupdate=null,this._porgrammer=c}return f(a,null,{create:{value:function(){this.location=this._porgrammer.renderer.gl.getUniformLocation(this._porgrammer.program,this.name)},writable:!0,enumerable:!0,configurable:!0},update:{value:function(){"function"==typeof this.onupdate&&this.onupdate.apply(this)},writable:!0,enumerable:!0,configurable:!0},value:{value:function b(b){var a=this._porgrammer.gl;b instanceof w?a.uniform3fv(this.location,b.toArray()):b instanceof v?a.uniformMatrix4fv(this.location,!1,b.toArray()):b instanceof t?a.uniformMatrix3fv(this.location,!1,b.toArray()):"object"==typeof b?4===b.length?a.uniform4fv(this.location,b):3===b.length?a.uniform3fv(this.location,b):9===b.length?a.uniformMatrix3fv(this.location,!1,b):16===b.length&&a.uniformMatrix4fv(this.location,!1,b):"boolean"==typeof b?a.uniform1i(this.location,b):a.uniform1f(this.location,b)},writable:!0,enumerable:!0,configurable:!0}}),a}();a.LiThree={Renderer:z,WebGLRenderer:A,World:l,Object3D:y,Camera:{Perspective:g},Color:h,Math:{Vector3:w,Matrix4:v},Light:{Directional:q,Point:r},ObjectFactory:{Circle:b,Cylinder:d,Cube:c,Sphere:e}}}(this); +//# sourceMappingURL=lithree.min.js.map \ No newline at end of file diff --git a/src/lib/force.js b/src/lib/force.js new file mode 100644 index 0000000..2f1c04f --- /dev/null +++ b/src/lib/force.js @@ -0,0 +1,33 @@ +import Vector from './vector'; +import GlobalGravity from './forces/global-gravity'; +import Gravity from './forces/gravity'; + +var Force = { + registry: [], + generators: { + GlobalGravity: GlobalGravity, + Gravity: Gravity + }, + add: function(particle, force) { + this.registry.push([particle, force]); + + return this.forces; + }, + remove: function(particle, force) { + var reg = this.registry; + this.registry.forEach(function(el, i) { + if(el[0] === particle && el[1] === force) reg.splice(i, 1); + }); + }, + clear: function() { + this.registry.length = 0; + }, + run: function(duration) { + this.registry.forEach(function(el) { + // force.run(particle, duration); + el[1].apply(el[0], duration); + }); + } +}; + +export default Force; \ No newline at end of file diff --git a/src/lib/forces/global-gravity.js b/src/lib/forces/global-gravity.js new file mode 100644 index 0000000..fbaa545 --- /dev/null +++ b/src/lib/forces/global-gravity.js @@ -0,0 +1,12 @@ +import Vector from '../vector'; +import Bolt from '../../main'; + +function GlobalGravity(mass, g = Bolt.ugravitation || 10) { + this.force = new Vector(0, -mass*g, 0); +} + +GlobalGravity.prototype.apply = function(particle, duration) { + particle.acceleration.add(this.force); +}; + +export default GlobalGravity; \ No newline at end of file diff --git a/src/lib/forces/gravity.js b/src/lib/forces/gravity.js new file mode 100644 index 0000000..a965a16 --- /dev/null +++ b/src/lib/forces/gravity.js @@ -0,0 +1,26 @@ +import Vector from '../vector'; +import Bolt from '../../main'; + +function Gravity(o1, o2) { + var mass = o1.mass * o2.mass; + var g = Bolt.ugravitation || 10; + var acc = mass*g; + + var distance = new Vector( + o1.position.x - o2.position.x, + o1.position.y - o2.position.y, + o1.position.z - o2.position.z + ); + + this.force = new Vector( + acc / (distance.x*distance.x), + acc / (distance.y*distance.y), + acc / (distance.z*distance.z) + ); +} + +Gravity.prototype.apply = function(particle, duration) { + particle.acceleration.add(this.force); +}; + +export default Gravity; \ No newline at end of file diff --git a/src/lib/particle.js b/src/lib/particle.js index 96d45eb..237f33b 100644 --- a/src/lib/particle.js +++ b/src/lib/particle.js @@ -30,6 +30,6 @@ Object.defineProperties(Particle.prototype, { Particle.prototype.destroy = function() { return Bolt.objects.splice(Bolt.objects.indexOf(this), 1); -} +}; export default Particle; \ No newline at end of file diff --git a/src/lib/play.js b/src/lib/play.js index 366ae56..3faa37c 100644 --- a/src/lib/play.js +++ b/src/lib/play.js @@ -1,5 +1,5 @@ import Frames from './frames'; -import Gravity from './gravity'; +import Force from './force'; import Bolt from '../main'; @@ -22,29 +22,24 @@ var Play = { (function loop() { reqAnimFrame(function(now) { - // ctx.clearRect(0, 0, canvas.width, canvas.height); - // ctx.fillStyle = 'black'; - // ctx.fillRect(0, 0, canvas.width, canvas.height); var avg = Frames.tick(now); for(var i = 0, len = Bolt.objects.length; i < len; i++) { var object = Bolt.objects[i]; if(Bolt.configs.globalGravity) { - var force = Gravity.global(object.inverseMass); - - object.position.add(object.velocity.clone().scalar(Frames.elapsed)); - - var acc = object.acceleration.clone(); - acc.add(force); - object.velocity.add(acc.scalar(Frames.elapsed)); - object.velocity.scalar(Math.pow(object.damping, Frames.elapsed)); - - // ctx.beginPath(); - // ctx.fillStyle = object.color; - // ctx.arc(object.position.x, object.position.y, object.mass, 0, 2*Math.PI); - // ctx.fill(); + var gravity = new Force.generators.GlobalGravity(object.mass); + Force.add(object, gravity); } + + object.position.add(object.velocity.clone().scalar(Frames.elapsed)); + // object.velocity.scalar(Math.pow(object.damping, Frames.elapsed)); + + object.acceleration.scalar(Frames.elapsed); + object.velocity.add(object.acceleration); + + Force.run(); + Force.clear(); } if(fn) fn.apply(this, arguments); diff --git a/src/main.js b/src/main.js index 74d2d5a..38da100 100644 --- a/src/main.js +++ b/src/main.js @@ -3,6 +3,7 @@ import Particle from './lib/particle'; import Gravity from './lib/gravity'; import Frames from './lib/frames'; import Play from './lib/play'; +import Force from './lib/force'; var Bolt = { configs: { @@ -22,7 +23,8 @@ var Bolt = { Particle: Particle, Gravity: Gravity, Frames: Frames, - Play: Play + Play: Play, + Force: Force }; window.Bolt = Bolt;