diff --git a/SimDynamics/DynamicsEngine/BulletEngine/BulletCoinQtViewer.cpp b/SimDynamics/DynamicsEngine/BulletEngine/BulletCoinQtViewer.cpp index 638e86945824c1e9df1caaa0558e0ae6e5a5a566..71623514e0c3318704ee6bd6c69e69e3c5e8fd54 100644 --- a/SimDynamics/DynamicsEngine/BulletEngine/BulletCoinQtViewer.cpp +++ b/SimDynamics/DynamicsEngine/BulletEngine/BulletCoinQtViewer.cpp @@ -175,7 +175,6 @@ void BulletCoinQtViewer::stepPhysics() VR_INFO << "Slow frame (" << ms << "us elapsed)! Limiting elapsed time (losing realtime capabilities for this frame)." << endl; ms = minFPS; } */ - btScalar dt1; if (!simModeFixedTimeStep) { if ((ms / 1000.0f) > bulletMaxSubSteps * bulletTimeStepMsec) { @@ -190,16 +189,17 @@ void BulletCoinQtViewer::stepPhysics() warned_norealtime = false; } - dt1 = btScalar(ms / 1000000.0f); - } else + btScalar dt1 = btScalar(ms / 1000000.0f); + bulletEngine->stepSimulation(dt1, bulletMaxSubSteps, float(bulletTimeStepMsec) / 1000.0f); + } + else { // FIXED TIME STEP - dt1 = float(bulletTimeStepMsec) / 1000.0f; + btScalar dt1 = float(bulletTimeStepMsec) / 1000.0f; + bulletEngine->stepSimulation(dt1*bulletMaxSubSteps, bulletMaxSubSteps, dt1); } // VR_INFO << "stepSimulation(" << dt1 << ", " << bulletMaxSubSteps << ", " << (bulletTimeStepMsec / 1000.0f) << ")" << endl; - bulletEngine->stepSimulation(dt1, bulletMaxSubSteps, float(bulletTimeStepMsec) / 1000.0f); - //optional but useful: debug drawing //m_dynamicsWorld->debugDrawWorld(); } diff --git a/SimDynamics/DynamicsEngine/BulletEngine/BulletCoinQtViewer.h b/SimDynamics/DynamicsEngine/BulletEngine/BulletCoinQtViewer.h index 2b9029e0880b02e0f8dc5e81efb0186ae56ade4a..fe0bb040d8604f12b8697c75e11476d1f39754eb 100644 --- a/SimDynamics/DynamicsEngine/BulletEngine/BulletCoinQtViewer.h +++ b/SimDynamics/DynamicsEngine/BulletEngine/BulletCoinQtViewer.h @@ -62,13 +62,16 @@ public: /*! In this mode, the time between two updates is measures and the engine is stepped accordingly. (standard) Could result in inaccurate simulation. Especially, if the steps tend to become large (e.g. on slow computers). + Also not deterministic. */ void setSimModeRealTime(); /*! - Sets the simulation mode to fixed time step. + Sets the simulation mode to fixed time step. This mode is deterministic. The time step can be specified in milli seconds: \see setBulletSimTimeStepMsec + In this mode bulletMaxSubsteps is used as the number of + full simulation steps bullet performs per frame. */ void setSimModeFixedTimeStep(); @@ -133,6 +136,8 @@ public: If this value is too low, the simulation will not run in real-time if the computer is not fast enough to render enough frames to perform 1/timeStep time steps per second. If this value is too high, more time is spent on simulation, increasing visualization lagginess on a slow computer. + In fixed timestep mode this parameter is used to specifiy how many steps per call to stepEngine() + are actually calculated by bullet. (Good to speed up simulation) */ void setBulletSimMaxSubSteps(int maxSubSteps);