Particle trajectory smoothing: where to do the simulation?

Posted by nkint on Game Development See other posts from Game Development or by nkint
Published on 2013-06-24T12:25:09Z Indexed on 2013/06/24 16:39 UTC
Read the original article Hit count: 214

Filed under:
|
|

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

        positionHistory.push_back(position);
        if history.length > historySize :
            history.pop_front()

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):
        particleById[id].setNewTarget(new_target)

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

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

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:

switch( INTERPOLATION_MODEL ):
    case EULER_MOTION: ...
    case HERMITE_INTERPOLATION: ...
    case SPLINE_INTERPOLATION: ...
    case KALMAN_FILTER_SMOOTHING: ...

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?

© Game Development or respective owner

Related posts about particles

Related posts about trajectory