9

我正在使用 BulletSharp,子弹库的 C# 发行版。我一直在一个据说恢复为 0.0f 的对象中出现一些弹跳。

我有一个动态圆柱体(即将成为网格)落在两个静态圆​​柱体上。像这样:

起始物体位置

顶部的圆柱体经常剧烈地弹跳,通常弹到一边。

这是我用来设置场景的代码:

        //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);

以及我world.StepSimulation(0.05f, 100, 0.0005f);用来更新物理模拟的每一帧。

我是否缺少任何明显的设置?为什么我的模拟会这样做?

小更新:我已经成功地在 Blender 的 Bullet 中进行了类似的模拟。那里没有弹跳……我不知道那和这之间可能有什么区别。

4

1 回答 1

4

您没有在模型中添加惯性。这应该会减慢抖动,并且不会产生最终从滚轮反弹的混响。您需要为所有三个对象添加它,包括滚轮上的零。试试这个,让我知道它是如何工作的:

//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)
Vector3 cylinderInertia;
MotionState still = new DefaultMotionState();
CylinderShape shape = new CylinderShapeZ(0.5f, 1.0f, 1.0f);
still.WorldTransform = Matrix.Translation(0.0f, 0.4f, 0.0f);
shape.CalculateLocalInertia(1.0f, out cylinderInertia);    
RigidBodyConstructionInfo constructInfo = new RigidBodyConstructionInfo(1.0f, still, shape, cylinderInertia);
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, Vector3.Zero);
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, Vector3.Zero);
r2 = new RigidBody(r2ci);
world.AddRigidBody(r2);
于 2012-06-03T03:04:07.433 回答