Hi all
I'm writing a simple android game and I've noticed a serious glitch on some phones. In the following code, there's a dynamic CircleShape falling towards a static box I like to refer to as "the ground" (but feel free to pick a different name).
Anyway, on the android 2.2 emulator as well as on my galaxy s (I9000), the circle bounces off the ground as balls often do. On a different phone, namely the I5700 samsung spica it's a different story. On the spica, the ball collides with the ground, then enters the ground where it speeds down probably due to the engine detecting that the two bodies are in each other, finally the circle exits the ground bottom and continues to fall due to nothing but gravity.
I've downloaded a few jbox2d demos from android marked to the phone and I've found at least one demo with the same problem on the spica ("Testing Box2D" by Maciej Gorski - posted Jan. 2012). A different, two year old, demo ("Box2d demo" by Nine studios, posted May, 2010) does not have this problem. This leads me to suspect that some change in jbox2d in the last two years is responsible for the glitch.
Note that the problem does not occur if the ball is replaced with a falling PolygonShape.
this is the code i used for testing on java and android:
Code:
Vec2 gravity = new Vec2(0.0f,-10.0f);
boolean doSleep = true;
World world = new World(gravity, doSleep);
BodyDef groundBodyDef = new BodyDef();
groundBodyDef.position.set(0.0f,-10.0f);
Body groundBody = world.createBody(groundBodyDef);
PolygonShape groundBox = new PolygonShape();
groundBox.setAsBox(50.0f, 10.0f);
groundBody.createFixture(groundBox, 0.0f);
//dynamic ball:
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyType.DYNAMIC;
bodyDef.position.set(0.0f,4.0f);
Body body = world.createBody(bodyDef);
CircleShape dynamicCircle = new CircleShape();
dynamicCircle.m_type = ShapeType.CIRCLE;
dynamicCircle.m_radius = 0.5f;
FixtureDef fixtureDef = new FixtureDef();
fixtureDef.shape = dynamicCircle;
fixtureDef.density = 1.0f;
fixtureDef.friction = 0.3f;
fixtureDef.restitution = 0.5f;
body.createFixture(fixtureDef);
float timeStep = 1.0f/60.0f;
int velocityIterations = 8;
int positionIterations = 3;
for (int i = 0; i<300; i++)
{
world.step(timeStep, velocityIterations, positionIterations);
Vec2 position = body.getPosition();
float angle = body.getAngle();
}