1 /* Copyright (C) 2021 Wildfire Games.
2 * This file is part of 0 A.D.
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
18 #ifndef INCLUDED_SMOOTHEDVALUE
19 #define INCLUDED_SMOOTHEDVALUE
21 #include "maths/MathUtil.h"
24 * A value with exponential decay towards the target value.
29 CSmoothedValue(float value
, float smoothness
, float minDelta
);
31 float GetSmoothedValue() const
36 void SetValueSmoothly(float value
)
41 void AddSmoothly(float value
)
52 float GetValue() const
57 void SetValue(float value
)
63 float GetSmoothness() const
68 void SetSmoothness(float smoothness
)
70 m_Smoothness
= smoothness
;
73 void ClampSmoothly(float min
, float max
)
75 m_Target
= Clamp
<double>(m_Target
, min
, max
);
78 float Update(float time
);
80 // Wrap so 'target' is in the range [min, max]
81 void Wrap(float min
, float max
);
86 double m_Target
; // the value which m_Current is tending towards
88 // (We use double because the extra precision is worthwhile here)
90 float m_MinDelta
; // cutoff where we stop moving (to avoid ugly shimmering effects)
93 #endif // INCLUDED_SMOOTHEDVALUE