Is physics framerate dependent?

Discussion about everything. New games, 3d math, development tips...
Post Reply
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Is physics framerate dependent?

Post by randomMesh »

Hi.

I started to use Irrlicht in combination with ODE some time ago.

Everything works fine so far, but i wonder if i should apply forces, torques and such in a framerate dependent way as you would move your Irrlichtnode in a "normal" way.

Say you have this code (using no physics)

Code: Select all

irr::ITimer* timer = device->getTimer();
irr::u32 then = timer->getTime();
irr::u32 now = 0;
irr::f32 elapsed = 0.0f;
...
//compute time since last frame
now = timer->getTime(); 
elapsed = (now - then) / 1000.f; 
then = now;
...
void moveForward(const irr::f32 elapsed)
{
	const irr::f32 dist = speed * elapsed;
	//move in a framerate dependant way
}
So if i am using ODE, can i do it the same way?

Code: Select all

void moveForward(const irr::f32 elapsed) const
{
	const irr::f32 dist = speed * elapsed;
	dBodyAddTorque(odeBody, dist, 0, 0);
}
or should i let the physic engine take care of the correct simulation without computing time since last frame since there is

Code: Select all

dWorldStep(theWorld, 0.1f);
?

I hope you understand my question.

regards
randomMesh
Last edited by randomMesh on Sat Sep 22, 2007 10:58 pm, edited 1 time in total.
fmx

Post by fmx »

don't ODE (and other Physics libraries) use some sort of internal timers?

I would think that it should be possible to just use the second method and achieve the same results regardless of the Frame count.
ie,

Code: Select all

void moveForward(const irr::f32 elapsed) const 
{ 
   const irr::f32 dist = speed; 
   dBodyAddTorque(odeBody, dist, 0, 0); 
} 
you could find out for yourself if you load in a REALLY high-poly (80,000+ tris) static mesh, then 'fire' an ODE-physics-based projectile, and see how it moves when you look at the high-poly model, and when you don't

the FPS would change 'cos rendering the high-poly model would be cpu intensive, so you can use it to see how your physics entities behave under varying frame-rate changes.

Let us know how things turn out.
I may be wrong...

;)
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Yeah the physics library should have its own internal timer thing going on. When using Physx by Ageia you pass the delta time to the simulation update function and that does all the movement updates for you based on that delta time.

When you set a force or torque etc i wouldnt have though youd have to do it based on framerate as the physic library would take care of it for you.

I don't know anything about ODE though myself, so i could be wrong there!
Image Image Image
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Post by randomMesh »

Thank you both for your answers.
Post Reply