0

I have followed this tutorial and the testbed launches, but nothing ever happens. The GUI appears but the tests never run, it just sits there. The testbed is launched from the driver class and you add the testbed test. Anyone else have this problem?

Driver Class

public class Driver {
public static final String GRAVITY_SETTING = "Gravity";
/**
 * @param args
 */
public static void main(String[] args) {
    // TODO Auto-generated method stub
    TestbedModel model = new TestbedModel();         // create our model

    // add tests
    model.addCategory("My Tests");
    model.addTest(new MJWTest2());
    model.addTest(new VerticalStack());

    // add our custom setting "My Range Setting", with a default value of 10, between 0 and 20
    model.getSettings().addSetting(new TestbedSetting(GRAVITY_SETTING, SettingType.ENGINE, false));

    TestbedPanel panel = new TestPanelJ2D(model);    // create our testbed panel
    JFrame testbed = new TestbedFrame(model, panel, null); // put both into our testbed frame
    // etc
    testbed.setVisible(true);
    testbed.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

}

Testbed Test class

public class MJWTest2 extends TestbedTest {
    public static final String GRAVITY_SETTING = "Gravity";


    @Override
    public void initTest(boolean argDeserialized) {
        setTitle("Couple of Things Test");

        getWorld().setGravity(new Vec2());

        for (int i = 0; i < 2; i++) {
            PolygonShape polygonShape = new PolygonShape();
            polygonShape.setAsBox(1, 1);
            FixtureDef fix = new FixtureDef();
            fix.shape = polygonShape;

            BodyDef bodyDef = new BodyDef();
            bodyDef.type = BodyType.DYNAMIC;
            bodyDef.position.set(5 * i, 0);
            bodyDef.angle = (float) (Math.PI / 4 * i);
            bodyDef.allowSleep = false;
            Body body = getWorld().createBody(bodyDef);
            body.createFixture(fix);

            body.applyForce(new Vec2(-10000 * (i - 1), 0), new Vec2());
        }
    }
@Override
public void step(TestbedSettings settings) {
    super.step(settings); // make sure we update the engine!
    TestbedSetting gravity = settings.getSetting(GRAVITY_SETTING); // grab our setting
    if (gravity.enabled) {
      getWorld().setGravity(new Vec2(0, -9));
    }
    else {
      getWorld().setGravity(new Vec2());
    }
  }

    @Override
    public String getTestName() {
        return "Couple of Things";
    }
}
NJGUY
  • 2,045
  • 3
  • 23
  • 43

2 Answers2

1

There was an updated to the engine w/o an update to the wiki. Whoops! sorry. You need to create a controller and start is, as shown here: https://github.com/dmurph/jbox2d/blob/master/jbox2d-testbed/src/main/java/org/jbox2d/testbed/framework/j2d/TestbedMain.java

Daniel Murphy
  • 852
  • 7
  • 14
0

Try this

public class MJWTest2 extends TestbedTest {

   @Override
   public void initTest(boolean argDeserialized) {
      setTitle("Couple of Things Test");

      getWorld().setGravity(new Vec2());

      for (int i = 0; i < 2; i++)
      {
//         CircleShape circleShape = new CircleShape();
//         circleShape.m_radius = 1;
//         Shape shape = circleShape;
         PolygonShape polygonShape = new PolygonShape();
         polygonShape.setAsBox(1, 1);
         Shape shape = polygonShape;

         BodyDef bodyDef = new BodyDef();
         bodyDef.type = BodyType.DYNAMIC;
         bodyDef.position.set(5 * i, 0);
         bodyDef.angle = (float) (Math.PI / 4 * i);
         bodyDef.allowSleep = false;
         Body body = getWorld().createBody(bodyDef);
         body.createFixture(shape, 5.0f);

         body.applyForce(new Vec2(-10000 * (i - 1), 0), new Vec2());
      }
   }

   /**
    * @see org.jbox2d.testbed.framework.TestbedTest#getTestName()
    */
   @Override
   public String getTestName() {
      return "Couple of Things";
   }
}

And so called 'driver class'

public class App2 {

public static final String GRAVITY_SETTING = "Gravity";

public static void main(String[] args) {
    // TODO Auto-generated method stub
    TestbedModel model = new TestbedModel();         // create our model

    // add tests
    model.addCategory("My Tests");
    model.addTest(new MJWTest2());
    model.addTest(new VerticalStack());

    // add our custom setting "My Range Setting", with a default value of 10, between 0 and 20
    model.getSettings().addSetting(new TestbedSetting(GRAVITY_SETTING, SettingType.ENGINE, false));

    TestbedPanel panel = new TestPanelJ2D(model);    // create our testbed panel
    JFrame testbed = new TestbedFrame(model, panel); // put both into our testbed frame
    // etc
    testbed.setVisible(true);
    testbed.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}
}

worked fine for me.. hope that it works for you as well..