Skip to content

Commit

Permalink
update cubezone
Browse files Browse the repository at this point in the history
  • Loading branch information
A-JIE committed Nov 3, 2016
1 parent 9e2572a commit 38b4dc9
Show file tree
Hide file tree
Showing 5 changed files with 888 additions and 1,000 deletions.
32 changes: 25 additions & 7 deletions build/three.proton.js
Original file line number Diff line number Diff line change
Expand Up @@ -3435,7 +3435,7 @@
function BoxZone(a, b, c, d, e, f) {
var x, y, z, w, h, d;
BoxZone._super_.call(this);

if (Proton.Util.isUndefined(b, c, d, e, f)) {
x = y = z = 0;
w = h = d = (a || 100);
Expand All @@ -3459,6 +3459,10 @@
this.width = w;
this.height = h;
this.depth = d;

//
this.friction = 0.85;
this.max = 6;
}

Proton.Util.inherits(BoxZone, Proton.Zone);
Expand Down Expand Up @@ -3489,26 +3493,40 @@
BoxZone.prototype._bound = function(particle) {
if (particle.p.x - particle.radius < this.x - this.width / 2) {
particle.p.x = this.x - this.width / 2 + particle.radius;
particle.v.x *= -1;
particle.v.x *= -this.friction;
this._static(particle, "x");
} else if (particle.p.x + particle.radius > this.x + this.width / 2) {
particle.p.x = this.x + this.width / 2 - particle.radius;
particle.v.x *= -1;
particle.v.x *= -this.friction;
this._static(particle, "x");
}

if (particle.p.y - particle.radius < this.y - this.height / 2) {
particle.p.y = this.y - this.height / 2 + particle.radius;
particle.v.y *= -1;
particle.v.y *= -this.friction;
this._static(particle, "y");
} else if (particle.p.y + particle.radius > this.y + this.height / 2) {
particle.p.y = this.y + this.height / 2 - particle.radius;
particle.v.y *= -1;
particle.v.y *= -this.friction;
this._static(particle, "y");
}

if (particle.p.z - particle.radius < this.z - this.depth / 2) {
particle.p.z = this.z - this.depth / 2 + particle.radius;
particle.v.z *= -1;
particle.v.z *= -this.friction;
this._static(particle, "z");
} else if (particle.p.z + particle.radius > this.z + this.depth / 2) {
particle.p.z = this.z + this.depth / 2 - particle.radius;
particle.v.z *= -1;
particle.v.z *= -this.friction;
this._static(particle, "z");
}
}

BoxZone.prototype._static = function(particle, axis) {
if (particle.v[axis] * particle.a[axis] > 0) return;
if (Math.abs(particle.v[axis]) < Math.abs(particle.a[axis]) * 0.0167 * this.max) {
particle.v[axis] = 0;
particle.a[axis] = 0;
}
}

Expand Down
2 changes: 1 addition & 1 deletion build/three.proton.min.js

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions example/customrender.html
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,16 @@
emitter.addBehaviour(new Proton.Scale(1, .1));
emitter.addBehaviour(new Proton.G(6));

var zone2 = new Proton.BoxZone(600);
emitter.addBehaviour(new Proton.CrossZone(zone2, "bound"));
var zone = new Proton.BoxZone(600);
zone.friction = 0.95;
zone.max = 7;
emitter.addBehaviour(new Proton.CrossZone(zone, "bound"));
emitter.addBehaviour(new Proton.Color(0xff0000, 'random', Infinity, Proton.easeOutQuart));

emitter.p.x = 0;
emitter.p.y = 0;
emitter.emit();
Proton.Debug.drawZone(proton, scene, zone);

return emitter;
}
Expand All @@ -147,8 +150,9 @@
}

var tha = 0;

function render() {
proton.update(clock.getDelta());
proton.update();
renderer.render(scene, camera);

tha += .005;
Expand Down
Loading

0 comments on commit 38b4dc9

Please sign in to comment.