CKochanekBartelsSplineInterpolator.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "ISplineInterpolator.h"
5 
6 
7 namespace ion
8 {
9  namespace Animation
10  {
11 
12  template <typename T>
14  {
15 
16  protected:
17 
18  float Tension = 0;
19  float Bias = 0;
20 
21  public:
22 
23  virtual T Interpolate(ISpline<T> const & Path, int const Index, float const Mu);
24 
25  void SetBias(float const bias) { Bias = bias; }
26  void SetTension(float const tension) { Tension = tension; }
27 
28  float GetBias() const { return Bias; }
29  float GetTension() const { return Tension; }
30 
31  };
32 
33  template <typename T>
34  T CKochanekBartelsSplineInterpolator<T>::Interpolate(ISpline<T> const & Path, int const Index, float const Mu)
35  {
36  T const y0 = Path.GetNode(Index - 1);
37  T const y1 = Path.GetNode(Index + 0);
38  T const y2 = Path.GetNode(Index + 1);
39  T const y3 = Path.GetNode(Index + 2);
40 
41  float const mu = Mu;
42  float const mu2 = Sq(mu);
43  float const mu3 = mu2 * mu;
44 
45  T m0 = (y1 - y0)*(1 + Bias)*(1 - Tension) / 2;
46  m0 = m0 + (y2 - y1)*(1 - Bias)*(1 - Tension) / 2;
47  T m1 = (y2 - y1)*(1 + Bias)*(1 - Tension) / 2;
48  m1 = m1 + (y3 - y2)*(1 - Bias)*(1 - Tension) / 2;
49 
50  float const a0 = 2.f*mu3 - 3 * mu2 + 1;
51  float const a1 = mu3 - 2 * mu2 + mu;
52  float const a2 = mu3 - mu2;
53  float const a3 = -2.f*mu3 + 3 * mu2;
54 
55  return y1*a0 + m0*a1 + m1*a2 + y2*a3;
56  }
57 
58  }
59 }
virtual T Interpolate(ISpline< T > const &Path, int const Index, float const Mu)
Definition: CKochanekBartelsSplineInterpolator.h:34
Definition: CKochanekBartelsSplineInterpolator.h:13
T Sq(T const &a)
Definition: ionUtils.h:60
float Bias
Definition: CKochanekBartelsSplineInterpolator.h:19
float GetTension() const
Definition: CKochanekBartelsSplineInterpolator.h:29
Definition: ISplineInterpolator.h:14
Definition: CCatmullRomAdvancedSplineInterpolator.h:7
void SetBias(float const bias)
Definition: CKochanekBartelsSplineInterpolator.h:25
Definition: ISpline.h:13
virtual TSplineNode const & GetNode(int const Index) const =0
void SetTension(float const tension)
Definition: CKochanekBartelsSplineInterpolator.h:26
float GetBias() const
Definition: CKochanekBartelsSplineInterpolator.h:28
float Tension
Definition: CKochanekBartelsSplineInterpolator.h:18