Page 1 of 1

Predict whether a step will occur

Posted: Wed Mar 07, 2018 9:37 am
by rebirth
Hi,

I have the physics engine set to a fixed 60hz and my engine is free running. If free running at 120hz then the physics step will skip one update and add the deltatime to some sort of accumulator.

Is there anyway, without altering Bullet's source code, to determine if Bullet will skip a particular update before calling its step function? Something like:

Code: Select all

float total = accumulatorSoFar + deltaTime;
if (total >= doStepValue)
	updateNode();
Called before physics step.

At the moment I have to synchronise with my nodes, which will basically undo a movement of a kinematic object (setting it from the ghostobject) if step returns zero. I'd like to cut out the wasted calculations used to manually move the kinematic object when no physics step occurs.

Thanks

Re: Predict whether a step will occur

Posted: Thu Mar 08, 2018 3:32 am
by hyyou
Can you call stepSimulation(customFixedValue) only when "total >= doStepValue" instead?

Re: Predict whether a step will occur

Posted: Thu Mar 08, 2018 12:20 pm
by rebirth
hyyou wrote: Thu Mar 08, 2018 3:32 am Can you call stepSimulation(customFixedValue) only when "total >= doStepValue" instead?
I could, but it would mean duplicating what Bullet is doing in the stepSimulation method, and trying to have both synchronised perfectly could be problematic. In fact, I did try but a lot of the updates had bullet doing 2 internal steps (could be a precision problem) instead of just one. I could make some changes to Bullet and break the method down into two methods. This way Bullet could be used to determine movement updates for everything else outside of the physics world, too.

Re: Predict whether a step will occur

Posted: Thu Mar 08, 2018 4:05 pm
by drleviathan
The way to do what you want is to do what you were doing with one little change. Accumulate your own time and only call stepSimulation() when you've accumulated enough but also pass 0 as the second argument (which defaults to 1 if not provided).

Code: Select all

btScalar deltaTime = btScalar(1.0/60.0);
int maxSubSteps = 0;
world->stepSimulation(deltaTime, maxSubsteps);
To understand why this is the case you need only examine the implementation of btDiscreteDynamicsWorld::stepSimulation().

Re: Predict whether a step will occur

Posted: Thu Mar 08, 2018 6:23 pm
by rebirth
I've been avoiding the variable update due to the assumption that it can be buggy, so I decided to go with the deterministic approach. I'll see how it works later, though.