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
experimental
William Linna 9 years ago
parent dc0bcb5d13
commit 6075e4639d
  1. 11
      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();

Loading…
Cancel
Save