I have some question regarding stepSimulation() in btDiscreteDynamicsWorld (bullet-2.81-rev2613).
I keep track of physics ticks incrementing a variable inside the callback of dynamicsWorld->setInternalTickCallback().
I checked and discovered that the ticks returned by stepSimulation() and the ticks of the callback are not the same.
I see that stepSimulation() returns 'numSimulationSubSteps', but the code do the follow:
Code: Select all
int clampedSimulationSteps = (numSimulationSubSteps > maxSubSteps)? maxSubSteps : numSimulationSubSteps;
saveKinematicState(fixedTimeStep*clampedSimulationSteps);
applyGravity();
for (int i=0;i<clampedSimulationSteps;i++)
{
internalSingleStepSimulation(fixedTimeStep);
synchronizeMotionStates();
}
2) What's the point updating the motion states every internalSingleStepSimulation() ?
We can safely remove it out of the for loop. Or not?
My real problem was the method used by bullet to calculate the substeps. So, in the end I inherited the btDiscreteDynamicsWorld and implemented this version without noticing any problem (note: this version don't use variable timeStep).
Any feedback is much apreciated.
Code: Select all
int BraveNewWorld::stepSimulation2(double elapsed, const int& maxSubSteps, const double& fixedTimeStep) {
startProfiling(elapsed);
BT_PROFILE("stepSimulation");
double max_time = fixedTimeStep * double( maxSubSteps ) ;
m_localTime += (elapsed > max_time) ? max_time : elapsed;
double num_ticks;
/* double tick_interpolator = */ modf( m_localTime / fixedTimeStep , &num_ticks);
m_localTime -= fixedTimeStep * num_ticks;
int numSimulationSubSteps = int(num_ticks);
//process some debugging flags
if (getDebugDrawer())
{
btIDebugDraw* debugDrawer = getDebugDrawer ();
gDisableDeactivation = (debugDrawer->getDebugMode() & btIDebugDraw::DBG_NoDeactivation) != 0;
}
if (numSimulationSubSteps) {
saveKinematicState(fixedTimeStep*double(numSimulationSubSteps));
applyGravity();
for (int i=0;i<numSimulationSubSteps;i++) {
internalSingleStepSimulation(fixedTimeStep);
}
}
synchronizeMotionStates();
clearForces();
#ifndef BT_NO_PROFILE
CProfileManager::Increment_Frame_Counter();
#endif //BT_NO_PROFILE
return numSimulationSubSteps;
}