what kind of timer to use?
of all the available timer functions in the windows API, which one should I use to create a nice smooth animation?
For example, im trying to draw a circle that moves across the screen, by redrawing it in a new location every 10 milliseconds. Only, it doesnt get drawn every 10 milliseconds, its more like every second, and it looks choppy and ugly.
Im using this function:
SetTimer (hwnd, ID_TIMER, 10, NULL) ;
as you can see, i want the timer message to be sent every 10 milliseconds, but this doesnt seem to happen.
any help would be appreciated!
GetTickCount() returns the number of milliseconds since last boot, it resets every 49 days
a typical rendering loop should look like
in the application scope:
DWORD dwStart
in the activation of the Application
dwStart = GetTickCount()
in the rendering scope
DWORD elapse = GetTickCount() - dwStart
DrawFrame(elapse);
dwStart = GetTickCount()
in DrawFrame(DWORD elapse)
static float t = 0;
t+= elapse / 1000.0f;
animate based on t
a typical rendering loop should look like
in the application scope:
DWORD dwStart
in the activation of the Application
dwStart = GetTickCount()
in the rendering scope
DWORD elapse = GetTickCount() - dwStart
DrawFrame(elapse);
dwStart = GetTickCount()
in DrawFrame(DWORD elapse)
static float t = 0;
t+= elapse / 1000.0f;
animate based on t
Why Not?
on windows, it''s best to use the performance counter, this is an actual clock, as far as i know, and not a timer interrupt jiffies kinda thing.. the frequency is something like 1mhz.. that''s 1 million ticks a sec..
------------
unsigned long long largeInteger;
unsigned long long timerValue;
unsigned long long timerValueNow;
float timerFrequency;
float currentTime;
float deltaTime;
In main:
QueryPerformanceFrequency(&largeInteger);
timerFrequency = (float) largeInteger;
currentTime = 0.0f;
In your loop:
QueryPerformanceCounter(&timerValueNow);
deltaTime = ((float) (timerValueNow - timerValue)) / timerFrequency;
timerValue = timerValueNow;
currentTime += deltaTime;
------------
unsigned long long largeInteger;
unsigned long long timerValue;
unsigned long long timerValueNow;
float timerFrequency;
float currentTime;
float deltaTime;
In main:
QueryPerformanceFrequency(&largeInteger);
timerFrequency = (float) largeInteger;
currentTime = 0.0f;
In your loop:
QueryPerformanceCounter(&timerValueNow);
deltaTime = ((float) (timerValueNow - timerValue)) / timerFrequency;
timerValue = timerValueNow;
currentTime += deltaTime;
--bart
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement