Skip to content

Commit 6075e46

Browse files
author
William Linna
committed
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
1 parent dc0bcb5 commit 6075e46

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

jme3-core/src/main/java/com/jme3/effect/ParticleEmitter.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ public class ParticleEmitter extends Geometry {
106106
private boolean worldSpace = true;
107107
//variable that helps with computations
108108
private transient Vector3f temp = new Vector3f();
109+
private transient Vector3f lastPos;
109110

110111
public static class ParticleEmitterControl implements Control {
111112

@@ -1013,12 +1014,16 @@ private void updateParticleState(float tpf) {
10131014

10141015
// Spawns particles within the tpf timeslot with proper age
10151016
float interval = 1f / particlesPerSec;
1017+
float originalTpf = tpf;
10161018
tpf += timeDifference;
10171019
while (tpf > interval){
10181020
tpf -= interval;
10191021
Particle p = emitParticle(min, max);
10201022
if (p != null){
10211023
p.life -= tpf;
1024+
if (lastPos != null) {
1025+
p.position.interpolateLocal(lastPos, 1 - tpf / originalTpf);
1026+
}
10221027
if (p.life <= 0){
10231028
freeParticle(lastUsed);
10241029
}else{
@@ -1028,6 +1033,12 @@ private void updateParticleState(float tpf) {
10281033
}
10291034
timeDifference = tpf;
10301035

1036+
if (lastPos == null) {
1037+
lastPos = new Vector3f();
1038+
}
1039+
1040+
lastPos.set(getWorldTranslation());
1041+
10311042
BoundingBox bbox = (BoundingBox) this.getMesh().getBound();
10321043
bbox.setMinMax(min, max);
10331044
this.setBoundRefresh();

0 commit comments

Comments
 (0)