Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extreme unstable of particles #24

Closed
f1nalspace opened this issue Dec 4, 2014 · 6 comments
Closed

Extreme unstable of particles #24

f1nalspace opened this issue Dec 4, 2014 · 6 comments

Comments

@f1nalspace
Copy link

I am playing around with the particles in jbox2d.
At first glance it was working fine, creating a few particles for one group works and was running stable.
Now i creating more groups, but joining it together and even with two groups, it gets unstable very fast - particles jump like crazy.

I am creating particles like this, doing nothing special and later render it using opengl.
And yes i am creating particle groups for every lava tile in my map.

        world.setParticleRadius(0.1f * worldScale);
        world.setParticleDamping(0.2f);
        world.setParticleDensity(0.1f);

        ParticleGroup lastGroup = null;
        Vec2f tileFluidExt = new Vec2f(1f * worldScale * 0.5f, 1f * worldScale * 0.5f);
        Transform pxf = new Transform();
        pxf.setIdentity();
        CircleShape pshape = new CircleShape();
        for (int y = 0; y < tileFluidsLayer.getHeight(); y++) {
            for (int x = 0; x < tileFluidsLayer.getWidth()-1; x++) {
                int tile = tileFluidsLayer.getTile(x, y);
                if (tile == tileFluidsSet.getFirstId() + TileFluid.LAVA) {
                    final Vec2f fluidPos = createTilePosition(new Vec2f(x + 0.5f, y + 0.5f), tileFluidExt);
                    ParticleGroupDef pgf = new ParticleGroupDef();
                    pshape = new CircleShape();
                    pshape.m_radius = (1f - 0.2f) * worldScale;
                    pxf.setIdentity();
                    world.destroyParticlesInShape(pshape, pxf);
                    pgf.shape = pshape;
                    pgf.flags = ParticleType.b2_viscousParticle;
                    pgf.position.set(fluidPos.getX(), fluidPos.getY());
                    ParticleGroup newGroup = world.createParticleGroup(pgf);
                    if (lastGroup != null) {
                        world.joinParticleGroups(lastGroup, newGroup);
                    }
                    lastGroup = newGroup;
                }
            }
        }
@dmurph
Copy link
Member

dmurph commented Dec 20, 2014

This is solved by #26

@dmurph dmurph closed this as completed Dec 20, 2014
@f1nalspace
Copy link
Author

Even with the c++ version of liquidfun 1.1, it has the exact same problem. Gets unstable after the second group has been added. So upgrading to 1.1 is great, but wont solve my issue at all.

@dmurph
Copy link
Member

dmurph commented Dec 21, 2014

Ah, so that would be an issue with liquidfun then. Maybe some of the following would work:

  • only create particles for the edges of the lava
  • disable all particles not on edges, maybe make them static
  • have particles not on edges be solid shapes until they are needed as lava, and then dynamically switch them

Most of these will be pretty difficult though. Having large stable bodies of particles is going to be an issue with most particle simulations, so you'll probably have to figure out a way of 'faking' it.

@f1nalspace
Copy link
Author

Its not a matter of size/count, with just 100 particles 25 each groups - but joined together) it will get unstable, like crazy. Maybe it does not like Chain-Shapes... Yeah i see what is now coming. I may have no choice but create the particle simulation myself. I was planning to simulate ~200k particles - and all may have different properties (mass, stiffness, viscosity etc.)

@dmurph
Copy link
Member

dmurph commented Dec 22, 2014

What do you mean joined together?
Yeah if you're planning on 200k, then you'll probably want your own simulation. You can try using of of the guts of LiquidFun, the Voronoi diagram they use is pretty cool.

@dmurph
Copy link
Member

dmurph commented Dec 22, 2014

(ah, nvm, I see what you mean by joined together)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants