Add SGMisc::seek helper

This commit is contained in:
Thomas Geymayer 2013-02-08 12:12:15 +01:00
parent 34d3c63384
commit 979aea5212

View File

@ -41,6 +41,23 @@ public:
static T clip(const T& a, const T& _min, const T& _max)
{ return max(_min, min(_max, a)); }
/**
* Seek a variable towards a target value with given rate and timestep
*
* @param var Variable or eg. SGPropObj
* @param target Target value
* @param rate Max. change rate/sec
* @param dt Time step (sec)
*/
template<class Var>
static T seek(Var& var, T target, T rate, T dt)
{
if( var < target )
return var = min(var + rate * dt, target);
else
return var = max(var - rate * dt, target);
}
static int sign(const T& a)
{
if (a < -SGLimits<T>::min())