From 6075e4639d3c15f7ed497db13c5a60aeeb282b82 Mon Sep 17 00:00:00 2001 From: William Linna Date: Sat, 14 Nov 2015 16:19:54 +0200 Subject: [PATCH 1/2] Interpolate particle positions NOTE: This change is not invented by me. All credit goes to methusalah. See this thread: http://hub.jmonkeyengine.org/t/interpolation-of-particle-spawning-point/30385/7 --- .../main/java/com/jme3/effect/ParticleEmitter.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/jme3-core/src/main/java/com/jme3/effect/ParticleEmitter.java b/jme3-core/src/main/java/com/jme3/effect/ParticleEmitter.java index 28bfd595d..6a05e359c 100644 --- a/jme3-core/src/main/java/com/jme3/effect/ParticleEmitter.java +++ b/jme3-core/src/main/java/com/jme3/effect/ParticleEmitter.java @@ -106,6 +106,7 @@ public class ParticleEmitter extends Geometry { private boolean worldSpace = true; //variable that helps with computations private transient Vector3f temp = new Vector3f(); + private transient Vector3f lastPos; public static class ParticleEmitterControl implements Control { @@ -1013,12 +1014,16 @@ public class ParticleEmitter extends Geometry { // Spawns particles within the tpf timeslot with proper age float interval = 1f / particlesPerSec; + float originalTpf = tpf; tpf += timeDifference; while (tpf > interval){ tpf -= interval; Particle p = emitParticle(min, max); if (p != null){ p.life -= tpf; + if (lastPos != null) { + p.position.interpolateLocal(lastPos, 1 - tpf / originalTpf); + } if (p.life <= 0){ freeParticle(lastUsed); }else{ @@ -1028,6 +1033,12 @@ public class ParticleEmitter extends Geometry { } timeDifference = tpf; + if (lastPos == null) { + lastPos = new Vector3f(); + } + + lastPos.set(getWorldTranslation()); + BoundingBox bbox = (BoundingBox) this.getMesh().getBound(); bbox.setMinMax(min, max); this.setBoundRefresh(); From c8a16c940f877728198f7da8e976cd117432b51e Mon Sep 17 00:00:00 2001 From: William Linna Date: Sat, 14 Nov 2015 16:32:44 +0200 Subject: [PATCH 2/2] Only interpolate if particles are in world space --- jme3-core/src/main/java/com/jme3/effect/ParticleEmitter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jme3-core/src/main/java/com/jme3/effect/ParticleEmitter.java b/jme3-core/src/main/java/com/jme3/effect/ParticleEmitter.java index 6a05e359c..ca3467781 100644 --- a/jme3-core/src/main/java/com/jme3/effect/ParticleEmitter.java +++ b/jme3-core/src/main/java/com/jme3/effect/ParticleEmitter.java @@ -1021,7 +1021,7 @@ public class ParticleEmitter extends Geometry { Particle p = emitParticle(min, max); if (p != null){ p.life -= tpf; - if (lastPos != null) { + if (lastPos != null && isInWorldSpace()) { p.position.interpolateLocal(lastPos, 1 - tpf / originalTpf); } if (p.life <= 0){