Gravity Force

Fixes in demo
This commit is contained in:
Mahdi Dibaiee 2015-01-28 19:36:54 +03:30
parent fc7d76637d
commit f180233e66
4 changed files with 11 additions and 5 deletions

View File

@ -542,6 +542,9 @@
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));
if (this.force.x === Infinity) this.force.x = 0;
if (this.force.y === Infinity) this.force.y = 0;
if (this.force.z === Infinity) this.force.z = 0;
}
return {
setters: [function (m) {

File diff suppressed because one or more lines are too long

View File

@ -24,10 +24,10 @@ 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
mass: 100
});
var sphere = new LiThree.ObjectFactory.Sphere(50, 20, 20);
var sphere = new LiThree.ObjectFactory.Sphere(5, 20, 20);
sphere.color.rgb(0.2, 0.2, 0.2);
world.add(sphere);
@ -50,9 +50,9 @@ Bolt.Play.start(function() {
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);
var mouseGravity = new Bolt.Force.generators.Gravity(p, mouse);
// Bolt.Force.add(p, mouseGravity);
Bolt.Force.add(p, mouseGravity);
syncPositions(p);
}

View File

@ -17,6 +17,9 @@ function Gravity(o1, o2) {
acc / (distance.y*distance.y),
acc / (distance.z*distance.z)
);
if(this.force.x === Infinity) this.force.x = 0;
if(this.force.y === Infinity) this.force.y = 0;
if(this.force.z === Infinity) this.force.z = 0;
}
Gravity.prototype.apply = function(particle, duration) {