stepSimulation

Jack
Posts: 59
Joined: Thu Aug 31, 2006 11:51 am

stepSimulation

Post 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.....
optime
Posts: 7
Joined: Mon Oct 30, 2006 7:44 pm

Post by optime »

I am new here but dt will decrease when sync calls increase - won't it?
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: stepSimulation

Post 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
Jack
Posts: 59
Joined: Thu Aug 31, 2006 11:51 am

Re: stepSimulation

Post 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
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Post 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.