From a0f5c0019e84f9773d55c2ff359def76878076ad Mon Sep 17 00:00:00 2001 From: cha0s Date: Sat, 9 Nov 2019 16:44:45 -0600 Subject: [PATCH] refactor: velocity as polar --- packages/physics/traits/emitted.trait.js | 14 ++++++++++---- packages/physics/traits/emitter.trait.js | 16 +++++++++++----- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/packages/physics/traits/emitted.trait.js b/packages/physics/traits/emitted.trait.js index fe76ffc..f0810b2 100644 --- a/packages/physics/traits/emitted.trait.js +++ b/packages/physics/traits/emitted.trait.js @@ -28,7 +28,10 @@ export class Emitted extends decorate(Trait) { }, transient: true, ttl: 2, - velocity: [0, 0], + velocity: { + angle: 0, + magnitude: 0, + }, }; } @@ -53,7 +56,8 @@ export class Emitted extends decorate(Trait) { this.scaleStart = new Range(this.params.scale.start); this.scaleEnd = new Range(this.params.scale.end); this.ttl = this.params.ttl; - this.velocity = new Vector.Range(this.params.velocity); + this.velocityAngle = new Range(this.params.velocity.angle); + this.velocityMagnitude = new Range(this.params.velocity.magnitude); } get isTransientParticle() { @@ -65,7 +69,6 @@ export class Emitted extends decorate(Trait) { particle: () => { const position = null === this.position ? null : this.position.value(); - const velocity = this.velocity.value(); const force = this.force.value(); return { alpha: { @@ -85,7 +88,10 @@ export class Emitted extends decorate(Trait) { end: this.scaleEnd.value(), }, ttl: this.ttl, - velocity, + velocity: { + angle: this.velocityAngle.value(), + magnitude: this.velocityMagnitude.value(), + }, }; }, diff --git a/packages/physics/traits/emitter.trait.js b/packages/physics/traits/emitter.trait.js index e1e6858..16b8ff1 100644 --- a/packages/physics/traits/emitter.trait.js +++ b/packages/physics/traits/emitter.trait.js @@ -46,13 +46,18 @@ export class Emitter extends decorate(Trait) { } } for (const key in this.params.particles) { - particles[key] = this.params.particles[key]; + if (particles[key]) { + particles[key] = merge({}, particles[key], this.params.particles[key]); + } + else { + particles[key] = this.params.particles[key]; + } } this.particles = particles; } onParticleDead(particle) { - if (particle.isTransientParticle) { + if (particle.body.isTransientParticle) { particle.body.destroy(); } } @@ -107,8 +112,9 @@ export class Emitter extends decorate(Trait) { new Proton.Mass(particle.mass), new Proton.Life(particle.ttl), new Proton.Velocity( - particle.velocity[0], - particle.velocity[1] + particle.velocity.magnitude, + particle.velocity.angle, + 'polar' ), ]; const behaviors = [ @@ -160,7 +166,7 @@ export class Emitter extends decorate(Trait) { let { count = 1, rate = 0, - } = order; + } = mergedJson; if (0 === rate) { for (let i = 0; i < count; ++i) { this.entity.emitParticleJson(mergedJson);