• Create Account

### #ActualMedo3337

Posted 29 November 2012 - 03:55 AM


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().

### #3Medo3337

Posted 29 November 2012 - 03:53 AM


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;
Is that the correct way to solve this problem?

### #2Medo3337

Posted 29 November 2012 - 03:52 AM

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;
Is that the correct way to solve this problem?

### #1Medo3337

Posted 29 November 2012 - 03:49 AM


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?

PARTNERS