Skip to content

Commit 55b72c7

Browse files
committed
.
1 parent 5aabbb7 commit 55b72c7

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

examples/liquidfun_DamBreak_PShapeParticles/liquidfun_DamBreak_PShapeParticles.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616

1717
import com.thomasdiewald.liquidfun.java.DwWorld;
18+
import com.thomasdiewald.liquidfun.java.render.DwParticleRenderGL;
1819
import com.thomasdiewald.liquidfun.java.render.DwParticleRenderP5;
1920

2021
import org.jbox2d.collision.shapes.ChainShape;
@@ -86,15 +87,20 @@ public void reset(){
8687
// release old resources
8788
release();
8889

89-
world = new DwWorld(this, 18);
90-
91-
90+
// if false, PShape-Quads are used for particles, instead of openGL points.
9291
// this replaces the default particle renderer (OpenGL) with an alternative
9392
// renderer where particles are rendered as PShape-Quads.
9493
// It renders a bit slower then the OpenGL version and grouped rendering
9594
// is also not possible.
96-
world.setParticleRender(new DwParticleRenderP5(this, world, world.transform));
97-
95+
DwWorld.INIT_GL_PARTICLES = false;
96+
97+
// create world
98+
world = new DwWorld(this, 18);
99+
100+
// just for checking
101+
System.out.println("PShape Particles = "+(world.particles instanceof DwParticleRenderP5));
102+
System.out.println("OpenGL Particles = "+(world.particles instanceof DwParticleRenderGL));
103+
98104
// create scene: rigid bodies, particles, etc ...
99105
initScene();
100106
}

src/com/thomasdiewald/liquidfun/java/DwWorld.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
import com.thomasdiewald.liquidfun.java.render.DwJoint;
4141
import com.thomasdiewald.liquidfun.java.render.DwParticleRender;
4242
import com.thomasdiewald.liquidfun.java.render.DwParticleRenderGL;
43+
import com.thomasdiewald.liquidfun.java.render.DwParticleRenderP5;
44+
4345
import processing.core.PApplet;
4446
import processing.core.PGraphics;
4547
import processing.core.PShape;
@@ -67,6 +69,12 @@ public class DwWorld extends World{
6769
public PApplet papplet;
6870
public DwViewportTransform transform;
6971

72+
/**
73+
* if true, particles is an instance of {@link DwParticleRenderGL}
74+
* otheriwse {@link DwParticleRenderP5} is instantiated.
75+
*/
76+
static public boolean INIT_GL_PARTICLES = true;
77+
7078

7179
public DwDebugDraw debug_draw;
7280

@@ -91,6 +99,8 @@ public DwWorld(PApplet papplet){
9199
this(papplet, 20);
92100
}
93101

102+
103+
94104
public DwWorld(PApplet papplet, float scale){
95105
super(new Vec2(0, -10f));
96106

@@ -115,7 +125,12 @@ public DwWorld(PApplet papplet, float scale){
115125

116126

117127
bodies = new DwBodyGroup(papplet, this, transform);
118-
particles = new DwParticleRenderGL(papplet, this, transform);
128+
129+
if(INIT_GL_PARTICLES){
130+
particles = new DwParticleRenderGL(papplet, this, transform);
131+
} else {
132+
particles = new DwParticleRenderP5(papplet, this, transform);
133+
}
119134

120135
for(int i = 0; i < registered_methods.length; i++){
121136
papplet.registerMethod(registered_methods[i], this);

0 commit comments

Comments
 (0)