• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# Frame rate independent movement

## Recommended Posts

I''m currently trying to do make particle system but i''ve come to a problem which i''ve come across many times before - they move insanely fast unless I have ridiculously low values. I would like to be able to have reasonable values as opposed to something like 0.0001f for speed I have my camera moving relative to the frame rate but i''ve never quite been able to figure out how to have things update based on the frame rate unless you press a button (eg. moving camera). Any help is much appreciated

##### Share on other sites
I was trying to do that earlier but I calculate my framerate in the camera code when it's updated and I use a variable called frameInterval (for the time between frames) but when I try to use this variable in other files (my particle code for instance) I get errors saying that it's already been defined in the camera code.

Any ideas on how to get around this?

[edited by - Theriomorph on March 19, 2004 3:52:16 AM]

##### Share on other sites
In the source file, where you measure the time, you define frameInterval:

int frameInterval;

Now, in every source file, where you want to use frameInterval too, you say:

extern int frameInterval;

##### Share on other sites
I would suggest making the timer seperate from the camera
this is the timer I made using that gamedev article

class CTimer{protected:  double m_Frequency;  __int64 m_StartClock;  float m_FrameTime;  float m_FrameStart;  float m_FrameEnd;  float m_FpsLimiter;  float m_Fps;public:  float GetFrameTime() { return m_FrameTime; }  float GetFps() { return m_Fps; }  double GetTime();  void Init();  void Update();};

#include <windows.h>#include "timer.h"double CTimer::GetTime(){  __int64 EndClock;  QueryPerformanceCounter((LARGE_INTEGER*)&EndClock);  return (double)(EndClock-m_StartClock)*m_Frequency;}void CTimer::Init(){  __int64 rate;  // Get the performance frequency  QueryPerformanceFrequency((LARGE_INTEGER*)&rate);  // Invert it so we can multiply instead of divide  m_Frequency = 1.0/(double)rate;  // Get the start time  QueryPerformanceCounter((LARGE_INTEGER*)&m_StartClock);  m_FrameTime  = 0.0f;  m_FrameStart = (float)GetTime();  m_FrameEnd   = 0.0f;  m_FpsLimiter = 0.0f;  m_Fps        = 0.0f;}void CTimer::Update(){  // Cap the frame rate to the timer frequency  // The timer frequency is normally always faster than the frame rate  do {    m_FrameEnd = (float)GetTime(); // Get the end frame time  } while( m_FrameEnd == m_FrameStart);  //   m_FrameTime  = m_FrameEnd - m_FrameStart; // Get the elapsed time  m_FrameStart = m_FrameEnd; // Set the end time to be the next start time  // Get the frames per second every 0.25 seconds  m_FpsLimiter += m_FrameTime;  if( m_FpsLimiter >= 0.25f )  {    m_FpsLimiter = 0.0f;    m_Fps = float(1.0/m_FrameTime);  }}