Skip to content
Snippets Groups Projects
Commit 838012cb authored by Erik von Reis's avatar Erik von Reis
Browse files

This is somewhat cleaner code flow. It's been re-tested.

parent 404b23c5
No related branches found
No related tags found
1 merge request!52Paramramp
......@@ -120,30 +120,45 @@ RampParamUpdate( RampParamState* state )
dxNow = dxLand;
}
// update state
state->isRamping = !( dxNow == 0.0 && state->dxPrev == 0.0 );
if ( dxNow == dxReq )
state->val = state->req;
else if(dxNow != 0.0)
{
const double minprecision = 1.1103e-16; //approx. minimum fraction of a
// double precision value that when added, changes that value
double minchange = lfabs(state->val)*minprecision;
//approx. minimum fraction of a double precision value that when added, changes that value
const double minprecision = 1.1103e-16;
//minimum change that will affect the current value (this is approximate, and can be bigger than the minimum change).
double minchange = lfabs(state->val)*minprecision;
if(dxNow != 0.0)
{
//handle the case where dxReq is smaller than our approx. minimum
if(minchange > lfabs(dxReq))
{
state->val = state->req;
dxNow = dxReq;
}
else
{
//otherwise, use the approx. minimum as a lower limit for our change.
if(minchange > lfabs(dxNow))
{
dxNow = dxNow > 0 ? minchange : -minchange;
}
state->val += dxNow;
}
}
// update state
state->isRamping = !( dxNow == 0.0 && state->dxPrev == 0.0 );
//if close enough, just jump to the end
if ( lfabs(dxNow) > lfabs(dxReq))
{
state->val = state->req;
dxNow = dxReq;
}
else
{
state->val += dxNow;
}
state->dxPrev = dxNow;
return state->val;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment