Box2d - Object fixture restitution value affects odd bumping

35 views
Skip to first unread message

piotr.w...@gmail.com

unread,
Mar 9, 2015, 4:42:07 PM3/9/15
to pl...@googlegroups.com
Hi, 

today i meed new problem with box2d library and creating objects with fixture restitution settings between 0 to 1. 

I have here minimal test case which creates new object into physic world:

   public static void createDefaultBodyWithFixture(float x, float y, float w, float h, float density, float friction, float restitution) {
        
        System.out.println("\nparameters: x:" + x + " y: "+ y 
                                + "   [ f: " + density 
                                + " d: " + friction 
                                + " r: " + restitution + " ] ");
        
        BodyDef bodyDef = new BodyDef();
        bodyDef.type = BodyType.DYNAMIC;
        bodyDef.position.set(x, y);
        Body dynamicBody = m_world.createBody(bodyDef);
        
        PolygonShape dynamicBox = new PolygonShape();
        dynamicBox.setAsBox(w, h);
        
        FixtureDef dynamicFixture = new FixtureDef();
        dynamicFixture.shape = dynamicBox;
        dynamicFixture.density = density;
        dynamicFixture.friction = friction;
        dynamicFixture.restitution = 0.001f;

        
        Fixture fix = dynamicBody.createFixture(dynamicFixture);
                
        System.out.println("params from body: x:" + dynamicBody.getPosition().x + " y:" + dynamicBody.getPosition().y  
                + "   [ f: " + fix.getFriction() 
                + " d: " + fix.getDensity() 
                + " r: " + fix.getRestitution() + " ] \n --------");
       
    }

when I run example on Java target I got this Output:

parameters: x:1.0 y: 2.0   [ f: 0.1 d: 0.1 r: 0.01 ] 
params from body: x:1.0 y:2.0   [ f: 0.1 d: 0.1 r: 0.01 ] 
 --------

parameters: x:3.0 y: 2.0   [ f: 0.2 d: 0.1 r: 0.11 ] 
params from body: x:3.0 y:2.0   [ f: 0.1 d: 0.2 r: 0.11 ] 
 --------

parameters: x:5.0 y: 2.0   [ f: 0.3 d: 0.1 r: 0.21000001 ] 
params from body: x:5.0 y:2.0   [ f: 0.1 d: 0.3 r: 0.21000001 ] 
 --------

parameters: x:7.0 y: 2.0   [ f: 0.4 d: 0.1 r: 0.31 ] 
params from body: x:7.0 y:2.0   [ f: 0.1 d: 0.4 r: 0.31 ] 
 --------

parameters: x:9.0 y: 2.0   [ f: 0.5 d: 0.1 r: 0.41 ] 
params from body: x:9.0 y:2.0   [ f: 0.1 d: 0.5 r: 0.41 ] 
 --------

parameters: x:11.0 y: 2.0   [ f: 0.6 d: 0.1 r: 0.51 ] 
params from body: x:11.0 y:2.0   [ f: 0.1 d: 0.6 r: 0.51 ] 
 --------

parameters: x:13.0 y: 2.0   [ f: 0.70000005 d: 0.1 r: 0.61 ] 
params from body: x:13.0 y:2.0   [ f: 0.1 d: 0.70000005 r: 0.61 ] 
 --------

parameters: x:15.0 y: 2.0   [ f: 0.8 d: 0.1 r: 0.71 ] 
params from body: x:15.0 y:2.0   [ f: 0.1 d: 0.8 r: 0.71 ] 
 --------

parameters: x:17.0 y: 2.0   [ f: 0.90000004 d: 0.1 r: 0.81 ] 
params from body: x:17.0 y:2.0   [ f: 0.1 d: 0.90000004 r: 0.81 ] 
 --------

parameters: x:19.0 y: 2.0   [ f: 1.0 d: 0.1 r: 0.90999997 ] 
params from body: x:19.0 y:2.0   [ f: 0.1 d: 1.0 r: 0.90999997 ] 

and I see something like this:


PlayN 1.8.5 

Thanks,

Piotr


marcin...@gmail.com

unread,
Mar 9, 2015, 8:41:51 PM3/9/15
to pl...@googlegroups.com, piotr.w...@gmail.com
                                + "   [ f: " + density 
                                + " d: " + friction 

Output is confusing because of that...

Did you try to test it with the same density?

May you try with: The mass of a body is not adjusted when you set the density. You must call ResetMassData for this to occur.

body->ResetMassData();


Next: Restitution is combined using the following formula.

float32 restitution;

restitution = b2Max(shape1->restitution, shape2->restitution);


What is the restitution of the bottom-base element?

/lm

piotr.w...@gmail.com

unread,
Mar 9, 2015, 11:29:49 PM3/9/15
to pl...@googlegroups.com, piotr.w...@gmail.com
Thanks, for that hint ... but it does not help :). 

I set density to the same value for each boxes and result is still the same. 

I realized that bumping change is visible between 0.8 to 1 restitution value. 

/Piotr

marcin...@gmail.com

unread,
Mar 10, 2015, 12:43:42 AM3/10/15
to pl...@googlegroups.com, piotr.w...@gmail.com
I realized that bumping change is visible between 0.8 to 1 restitution value. 

For me it match setting restitution to 0.8f in your `groundBody` - double check that.
Message has been deleted

piotr.w...@gmail.com

unread,
Mar 10, 2015, 11:34:35 PM3/10/15
to pl...@googlegroups.com, piotr.w...@gmail.com, marcin...@gmail.com
Hmmmm, I did some test and here are results:

ground body restitution: 0.01f  and dynamic bodies restitution from 0.7f to 1.0f:


The same restitution range for bodies bout ground restitution 1.0f affects that:


Thanks for figure out this "issue", I just need next time think about relations between bodies :). 

Reply all
Reply to author
Forward
0 new messages