Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a particle system in which I have particles that are moving to a target and the new targets are received via network. The list of new target are some noisy coordinates of a moving target stored in the server that I want to smooth in the client.

For doing the smoothing and the particle I wrote a simple particle engine with standard euler integration model.

So, my pseudo code is something like that:

# pseudo code

class Particle:
    def update():
        # do euler motion model integration:
        # if the distance to the target is more than a limit
        # add a new force to the accelleration 
        # seeking the target,
        # and add the accelleration to velocity
        # and velocity to the position

        if history.length > historySize :

class ParticleEngine:

    particleById = dict() # an associative array 
                          # where the keys are the id 
                          # and particle istances are sotred as values

    # this method is called each time a new tcp packet is received and parsed
    def setNetTarget(int id, Vec2D new_target):

    # this method is called each new frame
    def draw():
        for p in particleById.values: 

            for v in p.positionHistory:
                vertex(v.x, v.y)

The new target that are arriving are noisy but setting some accelleration/velocity parameters let the particle to have a smoothed trajectories.

But if a particle trajectory is a circle after a while the particle position converge to the center (a normal behaviour of euler integration model).

So I decided to change the simulation and use some other interpolation (spline?) or smooth method (kalman filter?) between the targets. Something like:

    case EULER_MOTION: ...

Now my question: where to write the motion simulation / trajectory interpolation? In the Particle? So I will have some Particle subclass like ParticleEuler, ParticleSpline, ParticleKalman, etc..? Or in the particle engine?

share|improve this question
If you know the source position, the target position, how much time it should take to get to the target, and how much of that time has passed, it's just a simple interpolation in your vertex shader. – Le Comte du Merde-fou Jun 24 '13 at 14:17
uhh.. i haven't thought about shading.. can you give me some example? anyway there are a lot of "interpolation" methods.. – nkint Jun 24 '13 at 14:18
Perhaps you should have a class for the particle system, a class for the particle and a class hierarchy for interpolation methods. The particle system can maintain a reference to the current interoplation method and provides it with particles to update. The interpolation method class operates on the particles via an interface (IParticle). This allows you to abstract the interpolation method away from the interpolated objects. – gareththegeek Jun 25 '13 at 9:57
@gareththegeek: could be an answer – nkint Jun 25 '13 at 12:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.