private void checkBounds() { for (int i = 0; i < liquid.length; ++i) { if (liquid[i].getMemberWorldCenter().y < -10.0f) { m_world.destroyBody(liquid[i]); float massPerParticle = totalMass / nParticles; CircleDef pd = new CircleDef(); pd.density = 1.0f; pd.filter.groupIndex = -10; pd.radius = .05f; pd.restitution = 0.4f; pd.friction = 0.0f; float cx = 0.0f + parent.random(-0.6f, 0.6f); float cy = 15.0f + parent.random(-2.3f, 2.0f); BodyDef bd = new BodyDef(); bd.position = new Vec2(cx, cy); bd.fixedRotation = true; Body b = m_world.createBody(bd); b.createShape(pd).setUserData(LIQUID_INT); MassData md = new MassData(); md.mass = massPerParticle; md.I = 1.0f; b.setMass(md); b.allowSleeping(false); liquid[i] = b; } } if (bod.getMemberWorldCenter().y < -15.0f) { m_world.destroyBody(bod); PolygonDef polyDef = new PolygonDef(); polyDef.setAsBox(parent.random(0.3f, 0.7f), parent.random(0.3f, 0.7f)); polyDef.density = 1.0f; BodyDef bodyDef = new BodyDef(); bodyDef.position = new Vec2(0.0f, 25.0f); bod = m_world.createBody(bodyDef); bod.createShape(polyDef); bod.setMassFromShapes(); } }
@Override public void create() { if (firstTime) { setCamera(0f, 2f, 35f); firstTime = false; } // m_world.setGravity(new Vec2(0.0f,0.0f)); Body ground = null; { PolygonDef sd = new PolygonDef(); sd.setAsBox(5.0f, 0.5f); BodyDef bd = new BodyDef(); bd.position.set(0.0f, 0.0f); ground = m_world.createBody(bd); ground.createShape(sd); sd.setAsBox(1.0f, 0.2f, new Vec2(0.0f, 4.0f), -0.2f); ground.createShape(sd); sd.setAsBox(1.5f, 0.2f, new Vec2(-1.2f, 5.2f), -1.5f); ground.createShape(sd); sd.setAsBox(0.5f, 50.0f, new Vec2(5.0f, 0.0f), 0.0f); ground.createShape(sd); sd.setAsBox(0.5f, 3.0f, new Vec2(-8.0f, 0.0f), 0.0f); ground.createShape(sd); sd.setAsBox(2.0f, 0.1f, new Vec2(-6.0f, -2.8f), 0.1f); ground.createShape(sd); CircleDef cd = new CircleDef(); cd.radius = 0.5f; cd.localPosition.set(-0.5f, -4.0f); ground.createShape(cd); } liquid = new Body[nParticles]; float massPerParticle = totalMass / nParticles; // PointDef pd = new PointDef(); // pd.mass = massPerParticle; // pd.restitution = 0.0f; // pd.filter.groupIndex = -10; CircleDef pd = new CircleDef(); pd.density = 1.0f; pd.filter.groupIndex = -10; pd.radius = .05f; pd.restitution = 0.4f; pd.friction = 0.0f; float cx = 0.0f; float cy = 25.0f; for (int i = 0; i < nParticles; ++i) { BodyDef bd = new BodyDef(); bd.position = new Vec2( parent.random(cx - boxWidth * .5f, cx + boxWidth * .5f), parent.random(cy - boxHeight * .5f, cy + boxHeight * .5f)); bd.fixedRotation = true; Body b = m_world.createBody(bd); b.createShape(pd).setUserData(LIQUID_INT); MassData md = new MassData(); md.mass = massPerParticle; md.I = 1.0f; b.setMass(md); b.allowSleeping(false); liquid[i] = b; } PolygonDef polyDef = new PolygonDef(); polyDef.setAsBox(parent.random(0.3f, 0.7f), parent.random(0.3f, 0.7f)); polyDef.density = 1.0f; BodyDef bodyDef = new BodyDef(); bodyDef.position = new Vec2(0.0f, 25.0f); bod = m_world.createBody(bodyDef); bod.createShape(polyDef); bod.setMassFromShapes(); }