Delta time

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
omar shaaban
Posts: 616
Joined: Wed Nov 01, 2006 6:26 pm
Location: Cairo,Egypt
Contact:

Delta time

Post by omar shaaban »

it seems peaple are still asking about delta time (which makes vitek write the code to them....about 25% of vitek posts is wrting this code lol...just kidding :lol: )
here it is the code we all know:

Code: Select all

	while(device->run())
	{
 u32 now = timer->getTime();
 f32 elapsedSeconds = (now - then) / 1000.f;
	if(elapsedSeconds>=deltatime)
{
     driver->beginScene(true, true, SColor(255,100,101,140));
	smgr->drawAll();
    guienv->drawAll();
then = now;
driver->endScene();
///////////////////////////////
     int fps = driver->getFPS();

     if (lastFPS != fps)
     {
        core::stringw str = L"Delta time - Irrlicht Engine [";		  str += driver->getName();
		  str += "] FPS:";
		  str += fps;

		  device->setWindowCaption(str.c_str());
		  lastFPS = fps;}

//////////////////////////////
}}
humbrol
Posts: 83
Joined: Sun Nov 18, 2007 8:22 pm

Post by humbrol »

may be a dumb question but where is deltatime declared and what is it set to?
Boogy
Posts: 3
Joined: Sat Jan 30, 2010 9:21 pm

Post by Boogy »

Code: Select all

u32 then = device->getTimer()->getTime();

while(device->run())
 {
   // Work out a frame delta time.
   const u32 now = device->getTimer()->getTime();
   const f32 frameDeltaTime = (f32)(now - then) / 1000.f; // Time in seconds
   then = now;

}
I've got this code from here: Tutorial!
Post Reply