Skip to content

Commit 8b15897

Browse files
committed
refactoring
1 parent 2ac906b commit 8b15897

39 files changed

Lines changed: 781 additions & 114 deletions

File tree

examples/testbed/box2d_BlobJoint.java renamed to examples/box2d_BlobJoint/box2d_BlobJoint.java

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313

14-
package testbed;
14+
package box2d_BlobJoint;
1515

1616
import com.thomasdiewald.liquidfun.java.DwWorld;
1717
import org.jbox2d.collision.shapes.CircleShape;
@@ -31,6 +31,24 @@
3131

3232

3333
public class box2d_BlobJoint extends PApplet {
34+
35+
//
36+
// This examples builds round softbodies using ConstantVolumeJoints.
37+
// Vertices are made of CircleShape Bodies, Edges are a linked list of
38+
// Distancejoints, managed and created by ConstantVolumeJointDef.
39+
//
40+
//
41+
// Controls:
42+
//
43+
// LMB ... drag bodies
44+
// LMB + SHIFT ... shoot bullet
45+
// MMB ... add particles
46+
// RMB ... remove particles
47+
// 'r' ... reset
48+
// 't' ... update/pause physics
49+
// 'f' ... toggle debug draw
50+
// 'g' ... toggle DwLiquidFX
51+
//
3452

3553
int viewport_w = 1280;
3654
int viewport_h = 720;
@@ -219,14 +237,12 @@ void createBlobJoint(int nBodies, float bodyRadius, float cx, float cy, float rx
219237

220238
bodylist[i] = body;
221239
}
222-
223240

224241
cvjd.frequencyHz = 10.0f;
225242
cvjd.dampingRatio = 1.0f;
226243
cvjd.collideConnected = false;
227244
world.createJoint(cvjd);
228245

229-
230246

231247
colorMode(HSB, 1);
232248
float hue_range = 60 / 360f;
@@ -262,23 +278,18 @@ void createBlobJoint(int nBodies, float bodyRadius, float cx, float cy, float rx
262278

263279
// create shapes for bodies
264280
for (int i = 0; i < nBodies; ++i) {
265-
266281
float inorm = i / (float)nBodies;
267282
float hue = abs(2 * inorm - 1) * hue_range + hue_tone;
268283
hue = hue - (int)hue; // [0, 1]
269-
284+
270285
world.bodies.add(bodylist[i], true, color(hue, 1, 1), false, color(0), 1f);
271286
}
272287
colorMode(RGB, 255);
273-
274288
}
275289

276290

291+
277292

278-
279-
280-
281-
282293
public static void main(String args[]) {
283294
PApplet.main(new String[] { box2d_BlobJoint.class.getName() });
284295
}

examples/testbed/box2d_BlobJoint_LiquidFx.java renamed to examples/box2d_BlobJoint_LiquidFx/box2d_BlobJoint_LiquidFx.java

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313

14-
package testbed;
14+
package box2d_BlobJoint_LiquidFx;
1515

1616
import com.thomasdiewald.liquidfun.java.DwWorld;
1717
import com.thomasdiewald.pixelflow.java.DwPixelFlow;
@@ -34,6 +34,28 @@
3434

3535

3636
public class box2d_BlobJoint_LiquidFx extends PApplet {
37+
38+
//
39+
// This examples builds round softbodies using ConstantVolumeJoints.
40+
// Vertices are made of CircleShape Bodies, Edges are a linked list of
41+
// Distancejoints, managed and created by ConstantVolumeJointDef.
42+
//
43+
// required libraries:
44+
// - PixelFlow, https://github.com/diwi/PixelFlow
45+
//
46+
//
47+
// Controls:
48+
//
49+
// LMB ... drag bodies
50+
// LMB + SHIFT ... shoot bullet
51+
// MMB ... add particles
52+
// RMB ... remove particles
53+
// 'r' ... reset
54+
// 't' ... update/pause physics
55+
// 'f' ... toggle debug draw
56+
// 'g' ... toggle DwLiquidFX
57+
//
58+
3759

3860
int viewport_w = 1280;
3961
int viewport_h = 720;
@@ -250,13 +272,9 @@ public void initScene() {
250272
createBlobJoint(20, vertex_rad, -15, 20, 5, 5, 80 / 360f);
251273

252274

253-
254-
255275
world.mouse_spawn_particles.setBoxShape(400, 200);
256276
world.mouse_spawn_particles.spawn(220,height-200);
257-
258-
259-
277+
260278
world.mouse_spawn_particles.setCircleShape(50);
261279
}
262280

@@ -288,7 +306,6 @@ void createBlobJoint(int nBodies, float bodyRadius, float cx, float cy, float rx
288306

289307
cvjd.addBody(body);
290308

291-
292309
bodylist[i] = body;
293310
}
294311

@@ -298,8 +315,6 @@ void createBlobJoint(int nBodies, float bodyRadius, float cx, float cy, float rx
298315
cvjd.collideConnected = false;
299316
world.createJoint(cvjd);
300317

301-
302-
303318
colorMode(HSB, 1);
304319
float hue_range = 60 / 360f;
305320

@@ -334,7 +349,6 @@ void createBlobJoint(int nBodies, float bodyRadius, float cx, float cy, float rx
334349

335350
// create shapes for bodies
336351
for (int i = 0; i < nBodies; ++i) {
337-
338352
float inorm = i / (float)nBodies;
339353
float hue = abs(2 * inorm - 1) * hue_range + hue_tone;
340354
hue = hue - (int)hue; // [0, 1]
@@ -346,10 +360,7 @@ void createBlobJoint(int nBodies, float bodyRadius, float cx, float cy, float rx
346360
}
347361

348362

349-
350-
351-
352-
363+
353364

354365
public static void main(String args[]) {
355366
PApplet.main(new String[] { box2d_BlobJoint_LiquidFx.class.getName() });

examples/testbed/box2d_Breakable.java renamed to examples/box2d_Breakable/box2d_Breakable.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313

14-
package testbed;
14+
package box2d_Breakable;
1515

1616

1717
import com.thomasdiewald.liquidfun.java.DwWorld;
@@ -34,7 +34,27 @@
3434

3535

3636
public class box2d_Breakable extends PApplet {
37-
37+
38+
//
39+
// This examples demonstrates how bodies (compounds) can break.
40+
// A Body is built of two fixtures.
41+
// A ContactListener is implemented to find the max collision impulse at which
42+
// the body will break.
43+
// In case the body should break, one fixture is destroyed and recreated as a
44+
// new body. The previous velocity (angular, linear) are applied to both remains.
45+
//
46+
//
47+
// Controls:
48+
//
49+
// LMB ... drag bodies
50+
// LMB + SHIFT ... shoot bullet
51+
// MMB ... add particles
52+
// RMB ... remove particles
53+
// 'r' ... reset
54+
// 't' ... update/pause physics
55+
// 'f' ... toggle debug draw
56+
//
57+
3858
int viewport_w = 1280;
3959
int viewport_h = 720;
4060
int viewport_x = 230;
@@ -177,7 +197,7 @@ public void initScene() {
177197

178198

179199

180-
class MyContactListener implements ContactListener{
200+
class MyContactListener implements ContactListener {
181201

182202
@Override
183203
public void beginContact(Contact contact) {
@@ -218,7 +238,7 @@ public void postSolve(Contact contact, ContactImpulse impulse) {
218238

219239

220240

221-
void Break() {
241+
void applyBreak() {
222242
// Create two bodies from one.
223243
Body body1 = m_piece1.getBody();
224244
Vec2 center = body1.getWorldCenter();
@@ -261,7 +281,7 @@ void Break() {
261281

262282
public void updateBreak() {
263283
if (m_break) {
264-
Break();
284+
applyBreak();
265285
m_broke = true;
266286
m_break = false;
267287
}

examples/testbed/box2d_BrickWall.java renamed to examples/box2d_BrickWall/box2d_BrickWall.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313

14-
package testbed;
14+
package box2d_BrickWall;
1515

1616
import com.thomasdiewald.liquidfun.java.DwWorld;
1717

@@ -29,6 +29,23 @@
2929

3030
public class box2d_BrickWall extends PApplet {
3131

32+
33+
//
34+
// Simple stacking demo.
35+
//
36+
//
37+
// Controls:
38+
//
39+
// LMB ... drag bodies
40+
// LMB + SHIFT ... shoot bullet
41+
// MMB ... add particles
42+
// RMB ... remove particles
43+
// 'r' ... reset
44+
// 't' ... update/pause physics
45+
// 'f' ... toggle debug draw
46+
//
47+
48+
3249
int viewport_w = 1280;
3350
int viewport_h = 720;
3451
int viewport_x = 230;
@@ -256,8 +273,6 @@ else if(odd_row && x == (numx-1)){
256273
ox -= dimx * 0.25;
257274
}
258275

259-
260-
261276
body_def.position.x = tx + ox + x * (dimx);
262277
body_def.position.y = ty + oy + y * (dimy);
263278

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313

14-
package testbed;
14+
package box2d_Bullet;
1515

1616

1717
import com.thomasdiewald.liquidfun.java.DwWorld;
@@ -30,7 +30,23 @@
3030

3131

3232
public class box2d_Bullet extends PApplet {
33-
33+
34+
35+
//
36+
// Bullet demo.
37+
//
38+
// Controls:
39+
//
40+
// LMB ... drag bodies
41+
// LMB + SHIFT ... shoot bullet
42+
// MMB ... add particles
43+
// RMB ... remove particles
44+
// 'r' ... reset
45+
// 't' ... update/pause physics
46+
// 'f' ... toggle debug draw
47+
//
48+
49+
3450
int viewport_w = 1280;
3551
int viewport_h = 720;
3652
int viewport_x = 230;
@@ -187,9 +203,8 @@ public void initScene() {
187203
m_bullet.setLinearVelocity(new Vec2(0.0f, -50.0f));
188204
}
189205

190-
191-
bodies.addAll();
192-
206+
207+
bodies.addAll();
193208
}
194209

195210

@@ -203,12 +218,9 @@ public void launch() {
203218
m_bullet.setTransform(new Vec2(m_x, 10.0f), 0.0f);
204219
m_bullet.setLinearVelocity(new Vec2(0.0f, -50.0f));
205220
m_bullet.setAngularVelocity(0.0f);
206-
207221
}
208222

209223

210-
211-
212224

213225
public static void main(String args[]) {
214226
PApplet.main(new String[] { box2d_Bullet.class.getName() });

examples/testbed/box2d_Cantilever_WeldJoint.java renamed to examples/box2d_Cantilever_WeldJoint/box2d_Cantilever_WeldJoint.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313

14-
package testbed;
14+
package box2d_Cantilever_WeldJoint;
1515

1616

1717
import com.thomasdiewald.liquidfun.java.DwWorld;
@@ -31,7 +31,24 @@
3131

3232

3333
public class box2d_Cantilever_WeldJoint extends PApplet {
34-
34+
35+
36+
//
37+
// This examples shows how to use Weldjoints.
38+
//
39+
//
40+
// Controls:
41+
//
42+
// LMB ... drag bodies
43+
// LMB + SHIFT ... shoot bullet
44+
// MMB ... add particles
45+
// RMB ... remove particles
46+
// 'r' ... reset
47+
// 't' ... update/pause physics
48+
// 'f' ... toggle debug draw
49+
//
50+
51+
3552
int viewport_w = 1280;
3653
int viewport_h = 720;
3754
int viewport_x = 230;

0 commit comments

Comments
 (0)