Re: more of Eep's bad mouth (was Re: Movement Waits off?) (Community)

Re: more of Eep's bad mouth (was Re: Movement Waits off?) // Community

1  |  

rolu

Jan 30, 2001, 6:12pm
[View Quote] Floating point stuff shouldn't be a problem if you take care of some
corrections. Or calculate stuff in another way.

Example:

(bad method) Something rotates every 12 seconds. Now assume a constant
framerate of 9fps. You have 12*9=108 frames for one rotation, so every frame
you do 1/108=0.00926th of a complete rotation. Every frame you add 0.00926
to the rotation counter (rounded a lot so we see the difference soon). So,
after 108 frames, you haven't done one rotation, but 1.00008th of a
rotation. Not much of a difference, about one extra rotation every 41.33
hours, but still noticable quite soon.

(good method) Something rotates every 12 seconds. It started rotating at a
specific time. Now, for whatever time it is, take the difference between now
and the time the object started rotating. Take the remainder of the division
of that number by 12, divide it by 12 itself, and you have the amount the
object is rotated. (numerical example: you start rotating at t=0 (t=system
time in seconds). A day later, at t=60*60*4=86400, you want to know how far
it has rotated. Take the difference to see how long it has been rotating.
This is also 86400 seconds. Divide this by 12, and take what's left.
86400/12=7200 with 0 left. So, now you know the object has rotated 7200
times, and is at exactly it's starting position. Another example: a day and
a second. Now the difference is 86401 seconds. This is 7200 with 1 left.
1/12 is 0.083, so now you know the object has rotated 0.083th of a complete
rotation. Of course, since I used whole seconds here, you get a rather jerky
movement. To make it work smooth, you have to use a smaller interval, but
that's no problem.

The idea of the "good" method is that you don't add up your floating point
errors. There are floating point errors, but you have about the same error
every time you calculate. Your data doesn't get "polluted", as with the bad
method.

Rolu

(by the way, I don't think it's floating point->integer conversion that is
the problem here.)
(by the way 2, you can do any floating point calculation you want with only
integers, and even have a better precision.)


>
> Ops - don't forget the toothbrush - you need it badly (your mouth stinks)!
>
> <plonk>
> Andras
>
>
[View Quote]

1  |  
Awportals.com is a privately held community resource website dedicated to Active Worlds.
Copyright (c) Mark Randall 2006 - 2021. All Rights Reserved.
Awportals.com   ·   ProLibraries Live   ·   Twitter   ·   LinkedIn