use world-step with deltatime

hello again,

i started experimenting around with box2d and created a game in simple billiard-style (i removed the gravity and used a few circle-shapes for collision and stuff).

everything works pretty excellent, but i guess that the step-thingy of the b2world-class isn't meant to be used in the way i plan it to use...

in my game i have an update-function which receives an integer called deltatime representing the time that passed since the last update-cycle. in this update-function i also update my b2world-object.

it looks somehow like that:

Quote:
void Update(uint32_t deltaTime)
{
m_world->Step(m_timeStep, m_iterations);

for (b2Contact* c = m_world->GetContactList(); c; c = c->GetNext())
{
if (c->GetManifoldCount() > 0)
{
b2Body* body1 = c->GetShape1()->GetBody();
b2Body* body2 = c->GetShape2()->GetBody();
float32 mass1 = body1->GetMass();
float32 mass2 = body2->GetMass();

if(mass1 > 0.0f && mass2 > 0.0f)
{
GetIconByBody(body1)->SetBallType(MathIcon::BallYellow);
GetIconByBody(body2)->SetBallType(MathIcon::BallYellow);
}
}
}

for(int i = 0; i < m_pieces.size(); i++)
m_pieces[i]->Update(deltaTime);
}


...and i want to bring the deltatime somehow in connection with the paramaters in m_world->Step but have no idea how...

any help appreciated! 🙂
I recommend looking at this article:

http://www.gaffer.org/game-physics/fix-your-timestep/

In short, Box2D only supports fixed time steps.
Erin Catto wrote:
I recommend looking at this article:

http://www.gaffer.org/game-physics/fix-your-timestep/

In short, Box2D only supports fixed time steps.

alright, thanks a lot for that link!
my solution works pretty similar with the stuff mentioned in the link! 🙂
Hello,
Even I am trying to achieve same thing, following is my code:
Code:
-(void) logicUpdate:(float) deltaTime
{
//Since my deltaTime is in milli seconds.
   accumilator += (deltaTime/1000);
   float32 timeStep = (1.0f/60.0f);
   int32 velocityIterations = 6;
   int32 positionItrations = 2;
   b2World* game_world = [[WorldManager sharedInstance] gameWorld];
   while (accumilator > timeStep)
   {
      game_world->Step(timeStep, velocityIterations, positionItrations);
      game_world->ClearForces();
      accumilator -= timeStep;
   }
}

With this my game speed is really very slow. Am I doing something wrong?

Actually I am developing for iPhone. I am taking "1" pixel as "3" meters. Is it right thing?

Thanks,
Madhu.
kmadhukishore wrote:
Actually I am developing for iPhone. I am taking "1" pixel as "3" meters. Is it right thing?


Probably not. As stated in the manual, Box2D works best with objects between 0.1 and 10 meters in size. If you have a 10 pixel object, it will be 30 meters in size. Your scaling will make all your objects huge and huge objects appear to fall slowly under gravity.

Original thread: https://box2d.org/forum/viewtopic.php?t=109