javalibgdxbox2dliquidfun

LiquidFun rendering particles


I'm using LiquidFun to simulate water, it's a physics engine based on box2d that uses particles. My problem is when rendering the particles with a specific color.

what is the purpose of setting the particle color on it's particle definition? when you also have to set the color on which the particle is to be rendered on the ParticleDebugRenderer.

public void createWater(float x, float y){
        ParticleDef def = new ParticleDef();
        def.color.set(Color.Red); //set particle color
        def.flags.add(ParticleDef.ParticleType.b2_tensileParticle);
        def.flags.add(ParticleDef.ParticleType.b2_colorMixingParticle);
        def.position.set(x, y);
        int index = system.createParticle(def);
    }

ParticleDebugRenderer:

pdr = new ParticleDebugRenderer(Color.BLUE, maxParticles); //set as BLUE

if I set the particle to be RED it would still be rendered in blue because the ParticleDebugRenderer is set to BLUE.


Solution

  • Looking at the source code we can find 2 renderers.

    ParticleDebugRenderer.java and ColorParticleRenderer.java

    The code difference between them is that ColorParticleRenderer gets color from ParticleSystem and ParticleDebugRenderer gets color from constuctor.

    The main use difference is that we use ColorParticleRenderer everytime we are not debugging. ParticleDebugRenderer is the one to use when we want to debug a particle. We use it, because we don't want to make changes in colors at the definition of ParticleSystem, because

    1. There may be several ParticleSystem of one definition, so changing color in definition would be pointless.
    2. It is easier to change one line of drawing than 1 line of definition (you avoid saying: ohh I forgot that I change the color at the definition)

    Your confusion comes from fact that you are using ParticleDebugRenderer when you are not debugging so you assign the same color twice.