stepSimulation

mi076
Posts: 144
Joined: Fri Aug 01, 2008 6:36 am
Location: Bonn, Germany

stepSimulation

Post by mi076 »

Hello,
i would like to show how i configure/run the simulation. I have
changed this part of code many times.
I look at btDiscreteDynamicsWorld::stepSimulation:

Code: Select all

int	btDiscreteDynamicsWorld::stepSimulation( btScalar timeStep,int maxSubSteps, btScalar fixedTimeStep)
{
<...>
	int numSimulationSubSteps = 0;
	if (maxSubSteps)
	{
		//fixed timestep with interpolation
		m_localTime += timeStep;
		if (m_localTime >= fixedTimeStep)
		{
			numSimulationSubSteps = int( m_localTime / fixedTimeStep);
			m_localTime -= numSimulationSubSteps * fixedTimeStep;
		}
	} else
	{
		//variable timestep
		fixedTimeStep = timeStep;
		m_localTime = timeStep;
		if (btFuzzyZero(timeStep))
		{
			numSimulationSubSteps = 0;
			maxSubSteps = 0;
		} else
		{
			numSimulationSubSteps = 1;
			maxSubSteps = 1;
		}
	}
<...>
}

Here is my code :

Edited. S. next post


Apps are here:

http://code.google.com/p/game-ws

One (small) problem i have is - if i use softbodies and set substeps = 0 (variable simulation rate) - softbodies are exploding and fps goes to 1-2 frames/s. The same application without softbodies is running O.K.

This stuff is configurable : hit ESCAPE to get Menu (once, it works currently on "key up" :-)), then "Options"->"Physics"
Due to problems with softbodies i have hidden the option in "lamp" test... It is available
only for "vehicle" test.
Any feedback is appreciated, thanks...
Last edited by mi076 on Mon Apr 27, 2009 1:19 pm, edited 1 time in total.
mi076
Posts: 144
Joined: Fri Aug 01, 2008 6:36 am
Location: Bonn, Germany

Re: stepSimulation

Post by mi076 »

changed ...

Code: Select all

void Application::run(bool * app_exit)
{
static Timer sync_timer;
sync_timer.start();

app_exit_ptr = app_exit;

btScalar et                 = 0.0;
static btScalar disp_sync_t = 0.0;
btScalar sim_interval       = btScalar(1.0/level_config_ptr[3]);  // fixed sim. rate
btScalar disp_interval      = btScalar(1.0/level_config_ptr[10]);
int substeps = level_config_ptr[5];

    while (!must_quit)
    {
    // get elapsed time
    et = static_cast<btScalar>(sync_timer.getElapsedTime());
    sync_timer.start();

    // handle input
    inject_input(app_exit_ptr, &must_quit);
        if (!render_gui)
        {
        get_keyboard(app_exit_ptr,&must_quit);
        }

    // step simulation
        if (level_config_ptr[2] == 0) // variable simulation rate
        {
            if (level_loaded && level) level->step(et,0,et);
        }
        else // fixed simulation rate
        {
            if (level_loaded && level) level->step(et,substeps,sim_interval);
        }

    // display
    disp_sync_t += et;
        if (level_config_ptr[9] == 0) // variable display rate
        {
        display();
        }
        else // fixed display rate
        {
            if (disp_sync_t >= disp_interval)
            {
            disp_sync_t = 0.0;
            display();
            } 
        }
    }

sync_timer.stop();
}
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 »

One (small) problem i have is - if i use softbodies and set substeps = 0 (variable simulation rate) - softbodies are exploding and fps goes to 1-2 frames/s. The same application without softbodies is running O.K.
Variable timesteps are unsupported and likely lead to instability and other problems.

What are the issues, when you use the default unmodified Bullet engine with any of the following options for 'stepSimulation'?

Code: Select all

//(1) one argument means, it uses a fixed internal timestep of 60 hertz
stepSimulation(deltaTime);

int maxNumSubsteps = 3;
btAssert(maxNumSubsteps>0);
//(2) two arguments, with second being positive (not zero!), uses a fixed internal timestep of 60 hertz, using a 'maxNumSubsteps'
stepSimulation(deltaTime, maxNumSubsteps);

#define FIXED_SUBSTEP 1./60.
//#define FIXED_SUBSTEP 1./120.
//#define FIXED_SUBSTEP 1./240.
///(3) same as (2), but now use a different internal fixed timestep, this has to be a constant, such as 1./60. or 1./120 or smaller.
stepSimulation(deltaTime, positive_value,FIXED_SUBSTEP);
Thanks a lot,
Erwin
mi076
Posts: 144
Joined: Fri Aug 01, 2008 6:36 am
Location: Bonn, Germany

Re: stepSimulation

Post by mi076 »

Thank you very much for reply.
Variable timesteps are unsupported and likely lead to instability and other problems.

Code: Select all

stepSimulation(deltaTime, positive_value,FIXED_SUBSTEP);
Default mode for my tests was all the time correct,
i have played too much with options :-),
some of physics options have had misleading terminology ...
I have corrected the options it actual version..

BTW, MultiThreadedDemo.cpp, SoftDemo.cpp have configuration

Code: Select all

#define FIXED_STEP 1
#ifdef FIXED_STEP
                m_dynamicsWorld->stepSimulation(1.0f/60.f,0);
#else
What are the issues, when you use the default unmodified Bullet engine with any of the following options for 'stepSimulation'?
I use unmodified 2.74 engine (with exception - put profiler start/stop into my "step" function, can revert it now, no need) and unmodified Bullet's vehicle class. Everything seems to run fine ... probably i shall try to add some drifting / sliding.
Thank you very much ...