Box2D Forums

It is currently Wed May 22, 2013 4:30 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Mon May 14, 2012 10:06 am 
Offline

Joined: Mon May 14, 2012 9:32 am
Posts: 2
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();

        }


Top
 Profile  
 
PostPosted: Mon May 14, 2012 10:10 am 
Offline

Joined: Mon May 14, 2012 9:32 am
Posts: 2
long post, i know :)

these are the different prints: java/android emulator/samsung galaxy s print the same numbers,samsung spica however, is on the right:

Code:
//galaxy s |   g. spica
//--------------------
3.9972222   3.9972222
3.9916666   3.9916666
3.983333   3.983333
3.972222   3.972222
3.9583333   3.9583333
3.9416666   3.9416666
3.9222221   3.9222221
3.8999999   3.8999999
3.8749998   3.8749998
3.847222   3.847222
3.8166666   3.8166666
3.7833333   3.7833333
3.7472222   3.7472222
3.7083333   3.7083333
3.6666665   3.6666665
3.622222   3.622222
3.5749998   3.5749998
3.5249999   3.5249999
3.472222   3.472222
3.4166665   3.4166665
3.358333   3.358333
3.297222   3.297222
3.233333   3.233333
3.1666665   3.1666665
3.097222   3.097222
3.0249999   3.0249999
2.9499998   2.9499998
2.872222   2.872222
2.7916665   2.7916665
2.7083333   2.7083333
2.6222222   2.6222222
2.5333333   2.5333333
2.4416666   2.4416666
2.347222   2.347222
2.25   2.25
2.15   2.15
2.0472224   2.0472224
1.9416668   1.9416668
1.8333335   1.8333335
1.7222224   1.7222224
1.6083336   1.6083336
1.4916669   1.4916669
1.3722225   1.3722225
1.2500004   1.2500004
1.1250004   1.1250004
0.9972226   0.9972226
0.8666671   0.8666671
0.7333338   0.7333338
0.59722275   0.59722275
0.504375   -3.5050006
0.5752083   -4.246667
0.6432638   -4.991111
0.7085416   -5.7383323
0.7710415   -6.488332
0.8307637   -7.241109
0.8877081   -7.996664
0.94187474   -8.754997
0.9932636   -9.516108
1.0418746   -10.279996
1.087708   -11.046662
1.1307635   -11.816106
1.1710413   -12.588327
1.2085412   -13.363327
1.2432634   -14.141105
1.2752078   -14.921659
1.3043743   -15.704992
1.3307632   -16.491106
1.3543743   -17.279997
1.3752075   -18.071667
1.3932631   -18.866114



Top
 Profile  
 
PostPosted: Wed May 16, 2012 2:24 am 
Offline

Joined: Mon Jun 08, 2009 12:21 pm
Posts: 353
hm, ok well first make sure you're using 2.1.2.2 for both situations.

Next, there's probably going to be differences with the floating point calculations on the simulator and on the phone. that said, the ball should not jump through the polygon shape just because of floating point differences. So I'm not sure


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group