cpu speed independent movement

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
jugurdzija
Posts: 26
Joined: Thu Feb 05, 2004 10:58 pm

cpu speed independent movement

Post by jugurdzija »

here is the problem:
i need to move object in a certain moment with basic equatations like s=a*(t*t)
time (t) is like (now-startTime)
now=driver->getTimer()->getTime() and so is startTime called before
but i have problem,on faster computer movement isnt the same like on slower ones,how to solve this?

startTime=driver->getTimer()->getTime() is called before
while(device->run())
{
now=driver->getTimer()->getTime();
}
Guest

Post by Guest »

You'll need to write some code like this:

Code: Select all


long lasttick;

void MainLoop()
{
	Render();  // draw a frame

	if (driver->getTimer()->getTime() > lasttick + 10) {
		lasttick = driver->getTimer()->getTime();
		Tick();
	}
}
Using this, the tick() function is called at 10 millisecond intervals, and providing that your code within tick() is executed in under 10ms then time will remain steady between CPU's.
Post Reply