BulletSharp object is bouncing too much

peterkort
Posts: 1
Joined: Wed May 30, 2012 4:51 pm

BulletSharp object is bouncing too much

Post by peterkort »

I'm having a problem when using the bulletsharp port/wrapper.
I have three cylinders, I want the top one(dynamic) to rest on the other two(static). My setup looks like this:
Image

For some reason, after jittering a bit, the top cylinder bounces off of the other two and falls out of view.

Here's my code to set up the scene.
  • //now figure out bulletsharp stuff...
    CollisionConfiguration collConfig = new DefaultCollisionConfiguration();
    Dispatcher collDispatch = new CollisionDispatcher(collConfig);

    BroadphaseInterface broadphase = new DbvtBroadphase();
    ConstraintSolver sol = new SequentialImpulseConstraintSolver();
    world = new DiscreteDynamicsWorld(collDispatch, broadphase, sol, collConfig);

    world.Gravity = new Vector3(0.0f, -10.0f, 0.0f);

    //log (moving object)
    MotionState still = new DefaultMotionState();
    CylinderShape shape = new CylinderShapeZ(0.5f, 1.0f, 1.0f);
    still.WorldTransform = Matrix.Translation(0.0f, 0.4f, 0.0f);
    RigidBodyConstructionInfo constructInfo = new RigidBodyConstructionInfo(1.0f, still, shape);
    logBody = new RigidBody(constructInfo);
    logBody.SetDamping(0.04f, 0.1f);
    world.AddRigidBody(logBody);

    //rollers (static objects)
    CylinderShape r1s = new CylinderShapeZ(0.1f, 1.0f, 1.0f);
    MotionState r1m = new DefaultMotionState();
    r1m.WorldTransform = Matrix.Translation(-0.2f, -0.4f, 0.0f);
    RigidBodyConstructionInfo r1ci = new RigidBodyConstructionInfo(0.0f, r1m, r1s);
    r1 = new RigidBody(r1ci);
    world.AddRigidBody(r1);

    CylinderShape r2s = new CylinderShapeZ(0.1f, 1.0f, 1.0f);
    MotionState r2m = new DefaultMotionState();
    r2m.WorldTransform = Matrix.Translation(0.2f, -0.4f, 0.0f);
    RigidBodyConstructionInfo r2ci = new RigidBodyConstructionInfo(0.0f, r2m, r2s);
    r2 = new RigidBody(r2ci);
    world.AddRigidBody(r2);
And every frame is updated using:
  • world.StepSimulation(0.05f, 100, 0.0005f);
While debugging, the Restitution for all three objects is listed as 0.0f.
Is there anything I might be missing?

I can also mention that I have put together a similar setup in Blender using the Bullet physics there, and there is no jitter.
anthrax11
Posts: 72
Joined: Wed Feb 24, 2010 9:49 pm

Re: BulletSharp object is bouncing too much

Post by anthrax11 »

You need to calculate the inertia as well:

Code: Select all

            float mass = 1.0f;
            Vector3 localInertia;
            shape.CalculateLocalInertia(mass, out localInertia);
            RigidBodyConstructionInfo constructInfo = new RigidBodyConstructionInfo(mass, still, shape, localInertia);
And for the static objects:

Code: Select all

            RigidBodyConstructionInfo r1ci = new RigidBodyConstructionInfo(0.0f, r1m, r1s, Vector3.Zero);
Vector3.Zero is actually the default inertia parameter value, so it's not really needed, but there's currently a bug in BulletSharp where the default value isn't passed correctly. I'll fix that soon, but for now you need to pass the zero vector.