Jump to content
  • Advertisement
Sign in to follow this  

animation time problem

This topic is 3072 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i have this code from a book

///secsPerCnt = 1.0f / (float)cntsPerSec;

void cTimer::UpdateTimer(void)
prevTime = currentTime;
presentTime = ((float)currentTime.QuadPart - (float)prevTime.QuadPart) / cntsPerSec.QuadPart;

frameTime = presentTime;

i updatetimer once per loop through the main loop.
and multply all movement by frametime .

but its not smoothing it out , any ideas were its going wrong please

Share this post

Link to post
Share on other sites
first, don't cast to floats.... there is a reason it uses doubles (it needs the extra precision because this is a high precision timer.

Make prevTime,currentTime,presentTime all doubles and see if that helps at all. Otherwise it is fine.

Share this post

Link to post
Share on other sites
you need to cast to double.

/* Here is how a simple use of queryperformanceCounter works */

/* Timer.h */

class Timer

LARGE_INTEGER frequency;


Timer() { QueryPerformanceFrequency(&frequency); QueryPerformanceCounter(&newTime); };
double Update();

/* Timer.cpp */

double Timer::Update()
prevTime = newTime;


return static_cast<double>(newTime.QuadPart - prevTime.QuadPart) / static_cast<double>(frequency.QuadPart);

/* in your prgram use the timer like so */

// create a timer
Timer* timer = new Timer();
double delta;

// each frame call update on the timer
delta = timer->Update();

// then to updat your objects move ments do it like so
objectX += objectVelocity * delta;

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!