【发布时间】:2012-10-08 08:49:46
【问题描述】:
【问题讨论】:
标签: bulletphysics
【问题讨论】:
标签: bulletphysics
我知道我迟到了,但我认为接受的答案只比文档的描述好一点。
timeStep:自上次调用 stepSimulation 以来经过的秒数,而不是毫秒数。
maxSubSteps:通常应该保持为 1,以便 Bullet 自行插入当前值。零值表示可变的滴答率,这意味着 Bullet 将模拟精确地推进timeStep 秒而不是插值。此功能有问题,不推荐。大于 1 的值必须始终满足等式 timeStep < maxSubSteps * fixedTimeStep,否则您将在模拟中浪费时间。
fixedTimeStep:与模拟的分辨率成反比。分辨率随着该值的减小而增加。请记住,更高的分辨率意味着它需要更多的 CPU。
【讨论】:
timeStep <= maxSubSteps * fixedTimeStep 可能吗?如果我想将物理模拟精确地推进 10 个(子)步,每 0.01 秒长,这样模拟在对 stepSimulation(...) 的调用结束时总共推进了 0.1 秒,那么正确的配置是什么?
btDynamicsWorld::stepSimulation(
btScalar timeStep,
int maxSubSteps=1,
btScalar fixedTimeStep=btScalar(1.)/btScalar(60.));
timeStep - 上次模拟后经过的时间。
对一些内部常数步进行内部模拟。 fixedTimeStep
fixedTimeStep~~~ 0.01666666 = 1/60
如果 timeStep 是 0.1,那么它将包括 6 个 (timeStep / fixedTimeStep) 内部模拟。
让滑翔机运动 BulletPhysics 根据除法后的提醒插入最后一步结果 (timeStep / fixedTimeStep)
【讨论】:
timeStep - 逐步模拟的时间量(以秒为单位)。通常情况下,您将通过自上次调用它以来的时间。
maxSubSteps - Bullet 每次调用时允许执行的最大步数。
fixedTimeStep - 调节模拟的分辨率。如果你的球穿透了你的墙壁而不是与它们碰撞,请尝试减少它。
在这里,我想在 Proxy 的回答中解决关于 maxSubSteps 的值 1 的特殊含义的问题。只有一个特殊值,即0,您很可能不想使用它,因为模拟将使用非常量的时间步长。所有其他值都相同。一起来看看the actual code:
if (maxSubSteps)
{
m_localTime += timeStep;
...
if (m_localTime >= fixedTimeStep)
{
numSimulationSubSteps = int(m_localTime / fixedTimeStep);
m_localTime -= numSimulationSubSteps * fixedTimeStep;
}
}
...
if (numSimulationSubSteps)
{
//clamp the number of substeps, to prevent simulation grinding spiralling down to a halt
int clampedSimulationSteps = (numSimulationSubSteps > maxSubSteps) ? maxSubSteps : numSimulationSubSteps;
...
for (int i = 0; i < clampedSimulationSteps; i++)
{
internalSingleStepSimulation(fixedTimeStep);
synchronizeMotionStates();
}
}
所以,maxSubSteps 等于 1 并没有什么特别之处。如果你不想失去时间,你真的应该遵守这个公式timeStep < maxSubSteps * fixedTimeStep。
【讨论】: