import org.jbox2d.testbed.tests.*; import org.jbox2d.testbed.*; import org.jbox2d.dynamics.contacts.*; import org.jbox2d.p5.*; import org.jbox2d.dynamics.*; import org.jbox2d.common.*; import org.jbox2d.util.blob.*; import org.jbox2d.collision.*; import org.jbox2d.testbed.timingTests.*; import org.jbox2d.dynamics.joints.*; // To work around threading problems with size boolean sizeSet; int count = 0; // Number of links in chain int numLinks = 10; // Physics things we must store Physics physics; Body body, body2; void setup() { size(640,480,P3D); frameRate(60); sizeSet = false; } void draw() { background(0); //This is a hack to make sure that the sketch size is //fully initialized before initializing the scene, //which depends on the width and height values. //Once Processing 1.0 is released, this should no longer //be necessary. ++count; if ( (!sizeSet && count > 10) ) { initScene(); } if (mousePressed) { //Create a body float x0 = mouseX; float y0 = mouseY; Body randomBod = physics.createCircle(x0, y0, random(5.0f,15f)); Vec2 vel = new Vec2(random(-30.0f,30.0f),random(-30.0f,30.0f)); randomBod.setLinearVelocity(vel); } if (keyPressed) { //physics.setCustomRenderingMethod(physics, "defaultDraw"); //Reset everything physics.destroy(); body = body2 = null; initScene(); } } void initScene() { physics = new Physics(this, width, height); physics.setDensity(1.0f); Body b1 = null; Body b2 = null; // Make a chain of bodies for (int i=0; i