Most of this borrowed from bullet physics library, see btDiscreteDynamicsWorld.cpp
| 261 | } |
| 262 | // Most of this borrowed from bullet physics library, see btDiscreteDynamicsWorld.cpp |
| 263 | bool Px3World::_simulate(const F32 dt) |
| 264 | { |
| 265 | S32 numSimulationSubSteps = 0; |
| 266 | //fixed timestep with interpolation |
| 267 | mAccumulator += dt; |
| 268 | if (mAccumulator >= smPhysicsStepTime) |
| 269 | { |
| 270 | numSimulationSubSteps = S32(mAccumulator / smPhysicsStepTime); |
| 271 | mAccumulator -= numSimulationSubSteps * smPhysicsStepTime; |
| 272 | } |
| 273 | if (numSimulationSubSteps) |
| 274 | { |
| 275 | //clamp the number of substeps, to prevent simulation grinding spiralling down to a halt |
| 276 | S32 clampedSimulationSteps = (numSimulationSubSteps > smPhysicsMaxSubSteps) ? smPhysicsMaxSubSteps : numSimulationSubSteps; |
| 277 | |
| 278 | for (S32 i=0;i<clampedSimulationSteps;i++) |
| 279 | { |
| 280 | if(i > 0) |
| 281 | mScene->fetchResults(true); |
| 282 | mScene->simulate(smPhysicsStepTime); |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | mIsSimulating = true; |
| 287 | |
| 288 | return true; |
| 289 | } |
| 290 | |
| 291 | void Px3World::tickPhysics( U32 elapsedMs ) |
| 292 | { |