I have an old simulation that runs at 40hz, in which I have something like this happening: vel *= A;//A is in [0,1]
I'm trying to port this to a new simulator that runs at 60hz; how should I transform A in order to get the "equivalent" value for the 60hz sim (or in general, for a sim running at X hz)?
Both simulations are fixed-time-step.
thanks,
Raigan
p.s - if there's a name for this conversion, I'd love to know what it is, because it seems like a simple basic math problem about which I'm sure there's a good wikipedia page.
p.p.s - you may recall my previous post http://www.gamedev.net/community/forums/topic.asp?topic_id=570306; I've tried to use the same solution, however it's not working, I'm assuming because that example used += and now I'm doing *=..
Consistant damping at different frame-rates
Well you are going to get different results at 60hz than 40hz unfortunately ):
What you might try doing is still run your sim at 40hz but interpolate between the values you calculate at 40 hz to get the 60 hz values.
Basically youd still do your calculations at 40hz but you'd keep track of "last values" and "next values" and lerp (or whatever is appropriate) between the last and next to get the current.
Make sense?
What you might try doing is still run your sim at 40hz but interpolate between the values you calculate at 40 hz to get the 60 hz values.
Basically youd still do your calculations at 40hz but you'd keep track of "last values" and "next values" and lerp (or whatever is appropriate) between the last and next to get the current.
Make sense?
The new coefficient is,
a2 = a1^(dt2/dt1)
where dt1 and dt2 are the sample periods of the old and new systems, respectively, and a1 is the coefficient used in the old system.
-------
What you have is a discrete time linear system. These are related to continuous-time linear systems by sampling and the matrix exponential...
Here's a derivation; it works for scalar systems but there are issues for higher-dimensional systems since in that case the matrix logarithm is not uniquely defined... In any case, here goes:
Assume there's some continuous-time system,
dx/dt = a x
and that it has been sampled at two different rates, 1/dt1 and 1/dt2, to yield the discrete time systems,
x1[k+1] = a1 x1[k]
and
x2[k+1] = a2 x2[k]
where
a1 = exp(a dt1)
and
a2 = exp(a dt2) .
Question: How do you get 'a2' from 'a1,' without knowing 'a'? Simple:
a = log(a1)/dt1
so
a2 = exp(log(a1)(dt2/dt1)) = a1^(dt2/dt1) .
That's it.
-------
Great!! Wikipedia describes this too: Discretization of linear state space models. See also: matrix exponential.
[Edited by - Emergent on June 7, 2010 6:03:14 PM]
a2 = a1^(dt2/dt1)
where dt1 and dt2 are the sample periods of the old and new systems, respectively, and a1 is the coefficient used in the old system.
-------
What you have is a discrete time linear system. These are related to continuous-time linear systems by sampling and the matrix exponential...
Here's a derivation; it works for scalar systems but there are issues for higher-dimensional systems since in that case the matrix logarithm is not uniquely defined... In any case, here goes:
Assume there's some continuous-time system,
dx/dt = a x
and that it has been sampled at two different rates, 1/dt1 and 1/dt2, to yield the discrete time systems,
x1[k+1] = a1 x1[k]
and
x2[k+1] = a2 x2[k]
where
a1 = exp(a dt1)
and
a2 = exp(a dt2) .
Question: How do you get 'a2' from 'a1,' without knowing 'a'? Simple:
a = log(a1)/dt1
so
a2 = exp(log(a1)(dt2/dt1)) = a1^(dt2/dt1) .
That's it.
-------
Great!! Wikipedia describes this too: Discretization of linear state space models. See also: matrix exponential.
[Edited by - Emergent on June 7, 2010 6:03:14 PM]
I assumed it's fixed to avoid complex math, so you're pretty much in for some hurt. The problem with a fixed tick rate is that once you've gone down the road a bit, it's hard to tweak the value and have things stay the same.
Linear solutions aren't known for their stability, but with a fixed step you've essentially maximised the instability giving big gaps the whole time, then frigged the smoothness with found-by-experiment numbers. Those numbers will be very, very sensitive to a step rate change.
I'm with the lerping option. Tick one step into the future and then visually lerp the answer back to where the result should be at the present.
EDIT: I always do this stuff at 100Hz. Not only does that give nice small increments for most situations, it's always going to be faster than your frame-rate. You won't need a higher monitor refresh than that until the next TV you buy beams the signal straight into your brain. :)
Linear solutions aren't known for their stability, but with a fixed step you've essentially maximised the instability giving big gaps the whole time, then frigged the smoothness with found-by-experiment numbers. Those numbers will be very, very sensitive to a step rate change.
I'm with the lerping option. Tick one step into the future and then visually lerp the answer back to where the result should be at the present.
EDIT: I always do this stuff at 100Hz. Not only does that give nice small increments for most situations, it's always going to be faster than your frame-rate. You won't need a higher monitor refresh than that until the next TV you buy beams the signal straight into your brain. :)
Awesome, thanks Emergent! I'm not sure where discrete systems were discussed in school, but I must not have taken that class :(
Quote:Original post by Rubicon
Linear solutions aren't known for their stability
Huh?
By "linear solutions" you really mean "Euler integration," right? That's a little different from what we're talking about. It's related though, since an Euler step is a first-order Taylor approximation to the matrix exponential.
Here's the deal: If you have
dx/dt = a x
then the Euler approximation is
x[k+1] = x[k] + a x[k] dt
or
x[k+1] = (1 + a dt) x[k] dt .
By comparison,
e^(a dt) = 1 + a dt + (1/2) a^2 dt^2 + ... + (1/n!)a^n dt^n + ...
so you see that the Euler method just keeps up to the linear term. Moreover, it's stable only when
|1 + a dt| < 1
which you can probably see just by recognizing that |A^n| goes to infinity as n goes to infinity if |A|>1, and to zero if |A|<1.
That's all I'll explain here, but hopefully that at least begins to set things straight. IIRC there are some articles on basic numerical integration like this in one of the Math and Physics forum's sticky threads...
I mean any kind of integration on a system with a variable time step as input.
How many times have you seen physics objects falling into or through the floor, or springs razz past their breaking points (or turn inside out) because someone opened the CD drawer.
With complex mathematical models, the equations are often the easy bit, especially if math is your forte. Actually modelling something stable is where the art comes into it ime.
And I admit I'm not very good at it, just making observations on the output of both myself and those around me who are in fact much better at it but seem to constantly suffer the same problems.
How many times have you seen physics objects falling into or through the floor, or springs razz past their breaking points (or turn inside out) because someone opened the CD drawer.
With complex mathematical models, the equations are often the easy bit, especially if math is your forte. Actually modelling something stable is where the art comes into it ime.
And I admit I'm not very good at it, just making observations on the output of both myself and those around me who are in fact much better at it but seem to constantly suffer the same problems.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
