Jump to content
  • Advertisement
Sign in to follow this  
thedodgeruk

animation time problem

This topic is 2989 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

cTimer::cTimer(void)
{
QueryPerformanceFrequency(&cntsPerSec);
///secsPerCnt = 1.0f / (float)cntsPerSec;
}


void cTimer::UpdateTimer(void)
{
prevTime = currentTime;
QueryPerformanceCounter(¤tTime);
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
Advertisement
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
{
private:

LARGE_INTEGER prevTime;
LARGE_INTEGER newTime;
LARGE_INTEGER frequency;


public:

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



/* Timer.cpp */


double Timer::Update()
{
prevTime = newTime;

QueryPerformanceCounter(&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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!