]>
Dogcows Code - chaz/yoink/blob - src/Moof/Interpolator.hh
2 /*] Copyright (c) 2009-2010, Charles McGarvey [**************************
3 **] All rights reserved.
7 * Distributable under the terms and conditions of the 2-clause BSD license;
8 * see the file COPYING for a complete text of the license.
10 **************************************************************************/
12 #ifndef _MOOF_INTERPOLATOR_HH_
13 #define _MOOF_INTERPOLATOR_HH_
15 #include <Moof/Log.hh>
16 #include <Moof/Math.hh>
35 class Interpolator
: public T
39 Interpolator(Scalar t
= 1.0, Interp::Mode mode
= Interp::STOP
)
44 void reset(Scalar t
= 1.0, Interp::Mode mode
= Interp::STOP
)
52 void update(Scalar t
, Scalar dt
)
56 mPrevState
= T::getValue();
57 mAlpha
+= dt
* mScale
;
59 if (mPrevState
== T::calculate(mAlpha
)) mIsDone
= true;
63 typename
T::Type
getState(Scalar alpha
) const
65 return cml::lerp(mPrevState
, T::getValue(), alpha
);
85 mAlpha
-= SCALAR(1.0);
87 case Interp::OSCILLATE
:
88 mAlpha
= SCALAR(2.0) - mAlpha
;
93 else if (mAlpha
< 0.0)
101 mAlpha
+= SCALAR(1.0);
103 case Interp::OSCILLATE
:
116 typename
T::Type mPrevState
;
120 template <typename T
= Scalar
>
127 void init(const Type
& a
, const Type
& b
)
133 const Type
& calculate(Scalar alpha
)
135 mState
= cml::lerp(mStart
, mFinish
, alpha
);
139 const Type
& getValue() const
152 typedef Interpolator
< Linear
<Scalar
> > Lerp
;
157 #endif // _MOOF_INTERPOLATOR_HH_
This page took 0.042146 seconds and 4 git commands to generate.