float x;
void move()
{
x+=0.2;
}
void render()
{
device->Clear(...);
device->BeginScene();
move();
// Code to do any transformation to the mesh according to x value...
// Other rendering code goes here...
device->EndScene();
device->Present(...);
}
In some computers, the above code will render 60 times per second, in some other computers the above code will render 40 times per second, this will cause the mesh to move faster in (60 fps) computers while slower in 40 fps computers.
How do I make the mesh move at the same speed no matter how many FPS?
I thought about doing the following:
DWORD currentTime = timeGetTime();
timeElapsed = currentTime - lastTime;
float speed = 0.1f;
x += speed * timeElapsed;
But the problem is that I could call the method move() from any part of the program, I will not be able to know 'timeElapsed' unless I'm calling inside render().