Predict whether a step will occur

Post Reply
rebirth
Posts: 24
Joined: Thu Jul 24, 2014 2:48 am

Predict whether a step will occur

Post by rebirth » Wed Mar 07, 2018 9:37 am

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

hyyou
Posts: 89
Joined: Wed Mar 16, 2016 10:11 am

Re: Predict whether a step will occur

Post by hyyou » Thu Mar 08, 2018 3:32 am

Can you call stepSimulation(customFixedValue) only when "total >= doStepValue" instead?

rebirth
Posts: 24
Joined: Thu Jul 24, 2014 2:48 am

Re: Predict whether a step will occur

Post by rebirth » Thu Mar 08, 2018 12:20 pm

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.

User avatar
drleviathan
Posts: 460
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: Predict whether a step will occur

Post by drleviathan » Thu Mar 08, 2018 4:05 pm

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().

rebirth
Posts: 24
Joined: Thu Jul 24, 2014 2:48 am

Re: Predict whether a step will occur

Post by rebirth » Thu Mar 08, 2018 6:23 pm

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.

Post Reply