如何在Processing中绘制Liquidfun粒子?

时间:2017-04-12 18:37:34

标签: java processing box2d jbox2d liquidfun

我认为我想要做的很简单,但很难找到任何文档。我想做的就是使用Liquidfun library在屏幕上看到粒子,尽管找到如何在Processing中使用它的例子并不简单。我一直试图将this liquid emulation翻译成Processing:

特别是我坚持在Processing中的屏幕上绘制Liquidfun粒子。下面的代码是我到目前为止的代码。我知道相关的documentation,但它没有对这个问题有所了解。

import shiffman.box2d.*;
import org.jbox2d.common.*;
import org.jbox2d.dynamics.joints.*;
import org.jbox2d.collision.shapes.*;
import org.jbox2d.collision.shapes.Shape;
import org.jbox2d.dynamics.*;
import org.jbox2d.dynamics.contacts.*;
import org.jbox2d.particle.ParticleGroupDef;
import org.jbox2d.particle.ParticleGroup;
import org.jbox2d.particle.ParticleSystem;
import org.jbox2d.particle.ParticleType;
import org.jbox2d.particle.ParticleDef;
import org.jbox2d.particle.ParticleColor;
import org.jbox2d.collision.shapes.CircleShape;
import org.jbox2d.collision.shapes.PolygonShape;
import org.jbox2d.common.Vec2;
import org.jbox2d.dynamics.Body;
import org.jbox2d.dynamics.BodyDef;
import org.jbox2d.dynamics.BodyType;

Box2DProcessing box2d;
PS particle;
ParticleGroup pg ;
ParticleGroupDef pd;
ParticleSystem ps;
ParticleColor partcol;
//BodyDef bd;

void setup() {

  size(1640, 1360);
  noStroke();
  box2d = new Box2DProcessing(this);
  box2d.createWorld();
   BodyDef bd = new BodyDef();
   Body ground = box2d.world.createBody(bd);
   ChainShape shape= new ChainShape();
   Vec2 [] box={new Vec2(0, 0),new Vec2(400, 0),new Vec2(400, 400),new Vec2(0, 400)};

        shape.createLoop(box, 4);
        ground.createFixture(shape, 0.0f);

    ps=new ParticleSystem(box2d.world);
    ps.setParticleRadius(0.025f);
    ps.setParticleDamping(0.2f);
    particle =new PS();
    partcol=new ParticleColor();   
}
void draw() {
  noLoop();
  for (int i=0;i<pg.getParticleCount()-2270;i++){
  particle.display();
  } 
}



class PS {  
    PS() {    
    //the definition for the particle group
    PolygonShape shape = new PolygonShape();
    shape.setAsBox(0.8f, 1.0f, new Vec2(-1.2f, 1.01f), 255);
      //shape.m_p.set(0, 30);
      shape.m_radius = 20; 
      ParticleGroupDef pd=new ParticleGroupDef();
      pd.flags = ParticleType.b2_waterParticle;
      pd.shape = shape; 
      pg=ps.createParticleGroup(pd); 
    }

        void display() {
           print(" "+pg.getParticleCount()+" ");
       }
  }

目前我得到的是一个空白的屏幕,虽然我可以在显示方法中打印组中的粒子数。这可能是将box2d转换为Processing坐标的问题吗?

0 个答案:

没有答案