Sign in to follow this  

Floating Precision Errors

This topic is 4816 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 just finished (re)implementing skinned meshes to work with DirectX 9.0c and added the ability to control the speed at which the animations play. Here's what I'm doing to get the time I'm at in the animation: Animation.time += (timeGetTime() - LastTime) * Animation.speed; Animation.time = Animation.time - ((int)(Animation.time / (AnimationLength + 1)) * (AnimationLength + 1)); Where LastTime is a static variable saved from the last frame's timeGetTime call. This way the time goes up but then wraps (loops) around whenever AnimationLength is reached. The problem is that the precision errors are off by a LOT. After just a couple seconds (albeit a couple hundred frames per second) the animations are already quite far off and only get worse. I just changed from storing time as a double instead of a float but it's still pretty bad. How should I remedy this? Is there some better way of making the animation loop around? Thanks for any advice, ms

Share this post


Link to post
Share on other sites
I've not completely understood yet in which cases the compiler makes mathematical operations return either of the data types involved but it usually helps transforming the data types involved into the the data type of the variable getting the result. For example you don't always want an operation involving a DWORD and a double to be calculated as a DWORD so transform the DWORD into a double:


Animation.time += (double) (timeGetTime() - LastTime) * Animation.speed;´
//What type is timeGetTime? If it's a float maybe you want to transform LastTime into float.

Animation.time -= ((Animation.time / (double)(AnimationLength + 1)) * (double) (AnimationLength + 1));



\Jimmy H

Share this post


Link to post
Share on other sites
@Jimmy - timeGetTime() returns a DWORD

I think I figured it out. I type casted everything to float (yes, float, not double) and changed the animation function to accept a DWORD parameter called CurrTime so that the timeGetTime function is called once per frame (before it was being called once per animation resulting in each animation being slightly off from each other). This seems to be working well. Thanks for your help!

Share this post


Link to post
Share on other sites

This topic is 4816 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this