Interpolation of particle spawning point when emitter has moved

I noticed that the particle emission point is not interpolated when the emitter move. The drawing become unnatural when emitting high number of small particles along the emitter trajectory, ie. the contrail at a plane’s wingtip.

See the related post in the troubleshooting section : http://hub.jmonkeyengine.org/forum/topic/interpolation-of-particle-spawning-point/

As it worked for me, I propose to commit this little modification :

[java]
private Vector3f lastPos;
private void updateParticleState(float tpf) {

    ...

    // Spawns particles within the tpf timeslot with proper age

float originalTPF = tpf;
float interval = 1f / particlesPerSec;
tpf += timeDifference;
while (tpf > interval){
tpf -= interval;
Particle p = emitParticle(min, max);
if (p != null){
p.life -= tpf;
if(isInWorldSpace())
p.position.interpolate(lastPos, 1-tpf/originalTPF);
if (p.life <= 0){
freeParticle(lastUsed);
}else{
updateParticle(p, tpf, min, max);
}
}
}
timeDifference = tpf;
lastPos = new Vector3f(getWorldTranslation());

}

[/java]

I’m not sure where is the best to initialize the lastPos, though. In preload(…) maybe, or in the update after a null check?

Hope you will find it usefull.

Sorry for the <strong/> in the code, I tried to hightlight modified lines :slight_smile:

Hint: if you post in a unified diff format (http://en.wikipedia.org/wiki/Diff) it’s easier to understand the changes :slight_smile: