我怎样才能让我的物理对象安定下来?
Posted
技术标签:
【中文标题】我怎样才能让我的物理对象安定下来?【英文标题】:How can I make my physics object settle down? 【发布时间】:2012-06-03 03:24:01 【问题描述】:我正在使用 BulletSharp,它是子弹库的 C# 发行版。我在一个据称具有 0.0f 的 Restitution 的对象中出现了一些弹跳。
我有一个动态圆柱体(即将成为网格)落在两个静态圆柱体上。像这样:
顶部的圆柱体经常疯狂地弹跳,通常弹到一边。
这是我用来设置场景的代码:
//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 中进行了类似的模拟。那里没有弹跳……我不知道那和这之间可能有什么区别。
【问题讨论】:
你可以为坠落的物体添加恢复原状吗? 仅对坠落的物体添加恢复原状并没有产生任何明显的差异。将所有三个对象的恢复原状设置为 0.1 似乎会稍微稳定下来,但这取决于模拟步长。还是有一点弹跳,偶尔弹跳。 【参考方案1】:您没有在模型中添加惯性。这应该会减慢抖动,并且不会产生最终从滚轮反弹的混响。您需要为所有三个对象添加它,包括滚轮上的零。试试这个,让我知道它是如何工作的:
//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);
【讨论】:
以上是关于我怎样才能让我的物理对象安定下来?的主要内容,如果未能解决你的问题,请参考以下文章