]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Interpolator.hh
fixed layer bugs; generalized octree
[chaz/yoink] / src / Moof / Interpolator.hh
index 2c33844262db6835cc5eaf02258f09cf5d11d767..4de3f6974bd3a7ceeaf93945b9d7ca5323126c07 100644 (file)
 #ifndef _MOOF_INTERPOLATOR_HH_
 #define _MOOF_INTERPOLATOR_HH_
 
+#include <Moof/Log.hh>
 #include <Moof/Math.hh>
 
 
 namespace Mf {
 
 
+// TODO - cleanup these classes
+
 class Interpolator
 {
        void clamp(Scalar& value)
@@ -45,7 +48,7 @@ class Interpolator
                        {
                                case STOP:
                                        value = 1.0;
-                                       stopped_ = true;
+                                       done_ = true;
                                        break;
                                case REPEAT:
                                        value -= 1.0;
@@ -62,7 +65,7 @@ class Interpolator
                        {
                                case STOP:
                                        value = 0.0;
-                                       stopped_ = true;
+                                       done_ = true;
                                        break;
                                case REPEAT:
                                        value += 1.0;
@@ -94,13 +97,13 @@ public:
        void setMode(Mode mode)
        {
                mode_ = mode;
-               stopped_ = false;
+               done_ = false;
        }
 
 
-       void update(Scalar dt)
+       void update(Scalar t, Scalar dt)
        {
-               if (!stopped_)
+               if (!done_)
                {
                        alpha_ += dt * scale_;
                        clamp(alpha_);
@@ -108,16 +111,22 @@ public:
                }
        }
 
+       bool isDone() const
+       {
+               return done_;
+       }
+
        virtual void calculate(Scalar alpha) = 0;
 
 private:
+
        Scalar  alpha_;
        Mode    mode_;
        Scalar  scale_;
-       bool    stopped_;
+       bool    done_;
 };
 
-template <class T>
+template <class T = Scalar>
 class InterpolatorBase : public Interpolator
 {
 public:
@@ -137,12 +146,12 @@ public:
 
        virtual void calculate(T& value, Scalar alpha) = 0;
 
-       const T& getValue()
+       const T& getValue() const
        {
                return value_;
        }
 
-       const T getState(Scalar alpha)
+       const T getState(Scalar alpha) const
        {
                return cml::lerp(previous_, value_, alpha);
        }
@@ -153,13 +162,13 @@ private:
 };
 
 
-template <class T, int D>
-class BinomialInterpolator : public InterpolatorBase<T>
+template <int D, class T = Scalar>
+class PolynomialInterpolator : public InterpolatorBase<T>
 {
 public:
-       BinomialInterpolator() {}
+       PolynomialInterpolator() {}
 
-       explicit BinomialInterpolator(const T coefficients[D+1],
+       PolynomialInterpolator(const T coefficients[D+1],
                        Scalar seconds = 1.0, Interpolator::Mode mode = Interpolator::STOP)
        {
                init(coefficients, seconds, mode);
@@ -174,13 +183,13 @@ public:
                fac[1] = 1.0;
 
                // build an array of the computed factorials we will need
-               for (int i = 2; i <= D; i++)
+               for (int i = 2; i <= D; ++i)
                {
                        fac[i] = i * fac[i - 1];
                }
 
                // combine the coefficients for fast updating
-               for (int i = 0; i <= D; i++)
+               for (int i = 0; i <= D; ++i)
                {
                        // n! / (k! * (n - k)!)
                        coefficients_[i] = coefficients[i] * fac[D] / (fac[i] * fac[D - i]);
@@ -196,7 +205,7 @@ public:
 
                value = coefficients_[0] * std::pow(beta, D);
 
-               for (int i = 1; i <= D; i++)
+               for (int i = 1; i <= D; ++i)
                {
                        value += coefficients_[i] * std::pow(beta, D - i) *
                                std::pow(alpha, i);
@@ -208,13 +217,15 @@ private:
 };
 
 
+// specialized linear interpolator
+
 template <class T>
-class BinomialInterpolator<T,1> : public InterpolatorBase<T>
+class PolynomialInterpolator<1,T> : public InterpolatorBase<T>
 {
 public:
-       BinomialInterpolator() {}
+       PolynomialInterpolator() {}
 
-       explicit BinomialInterpolator(const T coefficients[2], Scalar seconds = 1.0,
+       PolynomialInterpolator(const T coefficients[2], Scalar seconds = 1.0,
                        Interpolator::Mode mode = Interpolator::STOP)
                //InterpolatorBase<T>(seconds, mode)
        {
@@ -246,20 +257,20 @@ private:
 // interpolation functions in cml for other types of interpolation such as
 // slerp and some multi-alpha interpolators.
 
-typedef BinomialInterpolator<Scalar, 1>        Lerps;  // linear
-typedef BinomialInterpolator<Vector2,1>        Lerpv2;
-typedef BinomialInterpolator<Vector3,1>        Lerpv3;
-typedef BinomialInterpolator<Vector4,1>        Lerpv4;
+typedef PolynomialInterpolator<1>                      Lerp;   // linear
+typedef PolynomialInterpolator<1,Vector2>      Lerp2;
+typedef PolynomialInterpolator<1,Vector3>      Lerp3;
+typedef PolynomialInterpolator<1,Vector4>      Lerp4;
 
-typedef BinomialInterpolator<Scalar ,2>        Qerps;  // quadratic
-typedef BinomialInterpolator<Vector2,2>        Qerpv2;
-typedef BinomialInterpolator<Vector3,2>        Qerpv3;
-typedef BinomialInterpolator<Vector4,2>        Qerpv4;
+typedef PolynomialInterpolator<2>                      Qerp;   // quadratic
+typedef PolynomialInterpolator<2,Vector2>      Qerp2;
+typedef PolynomialInterpolator<2,Vector3>      Qerp3;
+typedef PolynomialInterpolator<2,Vector4>      Qerp4;
 
-typedef BinomialInterpolator<Scalar ,3>        Cerps;  // cubic
-typedef BinomialInterpolator<Vector2,3>        Cerpv2;
-typedef BinomialInterpolator<Vector3,3>        Cerpv3;
-typedef BinomialInterpolator<Vector4,3>        Cerpv4;
+typedef PolynomialInterpolator<3>                      Cerp;   // cubic
+typedef PolynomialInterpolator<3,Vector2>      Cerp2;
+typedef PolynomialInterpolator<3,Vector3>      Cerp3;
+typedef PolynomialInterpolator<3,Vector4>      Cerp4;
 
 
 } // namespace Mf
This page took 0.026035 seconds and 4 git commands to generate.