Page 1 of 1

stepSimulation

Posted: Tue Oct 31, 2006 11:55 am
by Jack

Code: Select all

void PHYSICS::Sync(void)
{
	const float dt = DeltaTime();

	LockWrite();
	_pPhysWorld->stepSimulation(dt);
	UnlockWrite();
}
It looks like speed of the game depends on "dt". But it must not. If FPS are going up, the speed of the flying sphere (with constant velocity) is going up too.....

Posted: Tue Oct 31, 2006 1:47 pm
by optime
I am new here but dt will decrease when sync calls increase - won't it?

Re: stepSimulation

Posted: Tue Oct 31, 2006 1:57 pm
by Erwin Coumans
Jack wrote:

Code: Select all

void PHYSICS::Sync(void)
{
	const float dt = DeltaTime();

	LockWrite();
	_pPhysWorld->stepSimulation(dt);
	UnlockWrite();
}
It looks like speed of the game depends on "dt". But it must not. If FPS are going up, the speed of the flying sphere (with constant velocity) is going up too.....
No, the speed of the simulation is decoupled of the timestep.

Which version of Bullet are you using? Bullet 2.19 and later has an internal fixed timestep, separate from this 'dt'. If the dt is smaller then the fixed timestep, it will automatically interpolate, so it should be fine.

Thanks,
Erwin

Re: stepSimulation

Posted: Tue Oct 31, 2006 2:26 pm
by Jack
Jack wrote: I found it. It was due to clamping:

Code: Select all

//clamp the number of substeps, to prevent simulation grinding spiralling down to a halt
	int clampedSimulationSteps = (numSimulationSubSteps > maxSubSteps)? maxSubSteps : numSimulationSubSteps;
At low FPS numSimulationSubSteps was clamped to default 1.
btDynamicsWorld::stepSimulation has optional arguments for the maximum number of substeps and the fixed timestep:

Code: Select all

stepSimulation(float deltaTime, int maxNumSubSteps=1, float fixedTimeStep=1.f/60.f);
You can increase the second argument, maxNumSubSteps. If the FPS increases and the deltaTime becomes ismaller then the fixed timestep, it will automatically interpolate transforms. If the number of required substeps is larger then maxNumSubSteps, it will drop physics frames, this happens when your machine cannot run the simulation fast enough. You can provide some feedback for the user, see the CcdPhysicsDemo how to determine several cases.

Erwin

Posted: Tue Oct 31, 2006 3:16 pm
by Erwin Coumans
optime wrote:I am new here but dt will decrease when sync calls increase - won't it?
Yes, the timeStep (or dt, deltaTime) is simply 1.0 / frame_per_second.