12 positionVec.reserve(3);
14 timeVec.push_back(0.0f);
15 positionVec.push_back(0.0f);
16 timeVec.push_back(finalTime);
17 positionVec.push_back(finalPosition);
25 int size = timeVec.size();
27 bool notFinished =
true;
28 while ((next < size) && notFinished)
30 if (timeVec[next] >= linearIndex)
37 int previous = next - 1;
39 const float tension = 0.25;
40 float prevPos = positionVec[previous];
41 float nextPos = positionVec[next];
42 float befPrevPos = positionVec[WarpIndex(previous - 1)];
43 float aftNextPos = positionVec[WarpIndex(next + 1)];
45 float prevTg = tension * (nextPos - befPrevPos);
47 float nextTg = tension * (prevPos - aftNextPos);
49 float t = (linearIndex - timeVec[previous]) / (timeVec[next] - timeVec[previous]);
51 return Interpolate(prevPos, prevTg, nextPos, nextTg, t);
56 int lastIndex = positionVec.size() - 1;
58 positionVec.push_back(positionVec[lastIndex]);
59 timeVec.push_back(timeVec[lastIndex]);
61 positionVec[lastIndex] = pos;
62 timeVec[lastIndex] = time;
70 float result = ((2 * t3) - (3 * t2) + 1) * p1
71 + ((3 * t2) - (2 * t3)) * p2
72 + (t3 - (2 * t2) + t) * tg1
74 cout << p1 <<
" " << tg1 <<
" " << p2 <<
" " << tg2 <<
" " << t <<
" => " << result <<
"\n";
81 int size = positionVec.size();
static float Interpolate(float p1, float tg1, float p2, float tg2, float t)
Hermite 1D interpolation.
void AddControlPosition(float pos, float time)
Adds a control position for interpolation.
virtual float GetValue(float linearIndex, float initialPos, float range) const
Evaluates a goal position for DOF interpolation.
HermiteInterpolator(float finalTime, float finalPosition)
Header file for V-ART class "HermiteInterpolator".
int WarpIndex(int i) const
Warp index around valid vector indices.