CCatmullRomAdvancedSplineInterpolator.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  public:
17 
18  enum EMode
19  {
20  Uniform = 0,
22  Chordal = 2
23  };
24 
26 
27  virtual T Interpolate(ISpline<T> const & Path, int const Index, float const Mu);
28 
29  };
30 
31  template <typename T>
32  T CCatmullRomAdvancedSplineInterpolator<T>::Interpolate(ISpline<T> const & Path, int const Index, float const Mu)
33  {
34  // Uses notation from the Centripetal Catmull-Rom Spline article on Wikipedia.org:
35  // https://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline
36 
37  T const P0 = Path.GetNode(Index - 1);
38  T const P1 = Path.GetNode(Index + 0);
39  T const P2 = Path.GetNode(Index + 1);
40  T const P3 = Path.GetNode(Index + 2);
41 
42  float Alpha = 0;
43  if (Mode == EMode::Uniform)
44  Alpha = 0;
45  else if (Mode == EMode::Centripetal)
46  Alpha = 0.5f;
47  else if (Mode == EMode::Chordal)
48  Alpha = 1;
49 
50  float const t0 = 0;
51  float const t1 = pow((P1 - P0).GetLength(), Alpha) + t0;
52  float const t2 = pow((P2 - P1).GetLength(), Alpha) + t1;
53  float const t3 = pow((P3 - P2).GetLength(), Alpha) + t2;
54 
55  float const t = Mu * (t2 - t1) + t1;
56 
57  T const A1 = P0 * ((t1 - t) / (t1 - t0)) + P1 * ((t - t0) / (t1 - t0));
58  T const A2 = P1 * ((t2 - t) / (t2 - t1)) + P2 * ((t - t1) / (t2 - t1));
59  T const A3 = P2 * ((t3 - t) / (t3 - t2)) + P3 * ((t - t2) / (t3 - t2));
60 
61  T const B1 = A1 * ((t2 - t) / (t2 - t0)) + A2 * ((t - t0) / (t2 - t0));
62  T const B2 = A2 * ((t3 - t) / (t3 - t1)) + A3 * ((t - t1) / (t3 - t1));
63 
64  return B1 * ((t2 - t) / (t2 - t1)) + B2 * ((t - t1) / (t2 - t1));
65  }
66 
67  }
68 }
Definition: CCatmullRomAdvancedSplineInterpolator.h:21
Definition: CCatmullRomAdvancedSplineInterpolator.h:22
Definition: ISplineInterpolator.h:14
Definition: CCatmullRomAdvancedSplineInterpolator.h:7
EMode
Definition: CCatmullRomAdvancedSplineInterpolator.h:18
Definition: CCatmullRomAdvancedSplineInterpolator.h:13
Definition: CCatmullRomAdvancedSplineInterpolator.h:20
Definition: ISpline.h:13
virtual TSplineNode const & GetNode(int const Index) const =0
virtual T Interpolate(ISpline< T > const &Path, int const Index, float const Mu)
Definition: CCatmullRomAdvancedSplineInterpolator.h:32
EMode Mode
Definition: CCatmullRomAdvancedSplineInterpolator.h:25