17 template <
int N,
typename Real>
48 virtual void Evaluate(Real
t,
unsigned int maxOrder,
59 void GetKeyInfo(Real t,
int& key, Real& dt)
const;
68 template <
int N,
typename Real>
73 template <
int N,
typename Real>
79 if (numPoints < 2 || !points)
86 std::copy(points, points + numPoints,
mA.begin());
100 template <
int N,
typename Real>
107 if (numPoints < 2 || !points)
113 mA.resize(numPoints);
114 std::copy(points, points + numPoints,
mA.begin());
120 template <
int N,
typename Real>
inline 123 return static_cast<int>(
mA.size());
126 template <
int N,
typename Real>
inline 132 template <
int N,
typename Real>
151 values[0] =
mA[key] + dt * (
mB[key] + dt * (
mC[key] + dt *
mD[key]));
155 values[1] =
mB[key] + dt * (((Real)2) *
mC[key] +
156 ((Real)3) * dt *
mD[key]);
160 values[2] = ((Real)2) *
mC[key] + ((Real)6) * dt *
mD[key];
163 values[3] = ((Real)6) * mD[key];
173 template <
int N,
typename Real>
177 std::vector<Real> dt(numSegments);
183 std::vector<Real> d2t(numSegments);
186 d2t[i] = this->
mTime[i + 1] - this->
mTime[i - 1];
189 std::vector<Vector<N, Real>>
alpha(numSegments);
193 d2t[i] *
mA[i] + dt[i] *
mA[i - 1]);
194 Real invDenom = ((Real)1) / (dt[i - 1] * dt[i]);
195 alpha[i] = invDenom * numer;
198 std::vector<Real> ell(numSegments + 1);
199 std::vector<Real> mu(numSegments);
200 std::vector<Vector<N, Real>>
z(numSegments + 1);
208 ell[i] = ((Real)2) * d2t[i] - dt[i - 1] * mu[i - 1];
209 inv = ((Real)1) / ell[i];
211 z[i] = inv * (alpha[i] - dt[i - 1] * z[i - 1]);
216 mB.resize(numSegments);
217 mC.resize(numSegments + 1);
218 mD.resize(numSegments);
220 Real oneThird = ((Real)1) / (Real)3;
222 for (
int i = numSegments - 1; i >= 0; --i)
224 mC[i] = z[i] - mu[i] *
mC[i + 1];
225 inv = ((Real)1) / dt[i];
226 mB[i] = inv * (
mA[i + 1] -
mA[i]) - oneThird * dt[i] * (mC[i + 1] +
228 mD[i] = oneThird * inv * (mC[i + 1] - mC[i]);
232 template <
int N,
typename Real>
241 std::vector<Real> dt(numSegments);
250 mat(0, numSegments) = (Real)-1;
251 for (
int i = 1; i <= numSegments - 1; ++i)
253 mat(i, i - 1) = dt[i - 1];
254 mat(i, i) = ((Real)2) * (dt[i - 1] + dt[i]);
255 mat(i, i + 1) = dt[i];
257 mat(numSegments, numSegments - 1) = dt[numSegments - 1];
258 mat(numSegments, 0) = ((Real)2) * (dt[numSegments - 1] + dt[0]);
259 mat(numSegments, 1) = dt[0];
262 mC.resize(numSegments + 1);
265 for (
int i = 1; i <= numSegments - 1; ++i)
267 inv0 = ((Real)1) / dt[i];
268 inv1 = ((Real)1) / dt[i - 1];
269 mC[i] = ((Real)3) * (inv0 * (
mA[i + 1] -
mA[i]) -
270 inv1*(
mA[i] -
mA[i - 1]));
272 inv0 = ((Real)1) / dt[0];
273 inv1 = ((Real)1) / dt[numSegments - 1];
275 inv1 * (
mA[0] -
mA[numSegments - 1]));
281 for (
int j = 0; j < N; ++j)
287 output = invMat *
input;
290 mC[i][j] = output[i];
294 Real oneThird = ((Real)1) / (Real)3;
295 mB.resize(numSegments);
296 mD.resize(numSegments);
299 inv0 = ((Real)1) / dt[i];
300 mB[i] = inv0 * (
mA[i + 1] -
mA[i]) - oneThird * (
mC[i + 1] +
301 ((Real)2) *
mC[i]) * dt[i];
302 mD[i] = oneThird * inv0 * (
mC[i + 1] -
mC[i]);
306 template <
int N,
typename Real>
311 std::vector<Real> dt(numSegments);
317 std::vector<Real> d2t(numSegments);
320 d2t[i] = this->
mTime[i + 1] - this->
mTime[i - 1];
323 std::vector<Vector<N, Real>>
alpha(numSegments + 1);
324 Real inv = ((Real)1) / dt[0];
325 alpha[0] = ((Real)3) * (inv * (
mA[1] -
mA[0]) - derivative0);
326 inv = ((Real)1) / dt[numSegments - 1];
332 d2t[i] *
mA[i] + dt[i] *
mA[i - 1]);
333 Real invDenom = ((Real)1) / (dt[i - 1] * dt[i]);
334 alpha[i] = invDenom*numer;
337 std::vector<Real> ell(numSegments + 1);
338 std::vector<Real> mu(numSegments);
339 std::vector<Vector<N, Real>>
z(numSegments + 1);
341 ell[0] = ((Real)2) * dt[0];
343 inv = ((Real)1) / ell[0];
344 z[0] = inv * alpha[0];
348 ell[i] = ((Real)2) * d2t[i] - dt[i - 1] * mu[i - 1];
349 inv = ((Real)1) / ell[i];
351 z[i] = inv * (alpha[i] - dt[i - 1] * z[i - 1]);
354 (((Real)2) - mu[numSegments - 1]);
359 mB.resize(numSegments);
360 mC.resize(numSegments + 1);
361 mD.resize(numSegments);
363 Real oneThird = ((Real)1) / (Real)3;
365 for (
int i = numSegments - 1; i >= 0; --i)
367 mC[i] = z[i] - mu[i] *
mC[i + 1];
368 inv = ((Real)1) / dt[i];
369 mB[i] = inv * (
mA[i + 1] -
mA[i]) - oneThird*dt[i] * (mC[i + 1] +
371 mD[i] = oneThird * inv * (mC[i + 1] - mC[i]);
375 template <
int N,
typename Real>
384 else if (t >= this->mTime[numSegments])
386 key = numSegments - 1;
387 dt = this->mTime[
numSegments] - this->mTime[numSegments - 1];
396 dt = t - this->mTime[i];
std::vector< Vector< N, Real > > mA
Vector< N, Real > const * GetPoints() const
GLfloat GLfloat GLfloat alpha
GLfixed GLfixed GLint GLint order
virtual void Evaluate(Real t, unsigned int maxOrder, Vector< N, Real > values[4]) const
std::vector< Real > mTime
void GetKeyInfo(Real t, int &key, Real &dt) const
std::vector< Vector< N, Real > > mB
virtual ~NaturalSplineCurve()
GLenum GLsizei GLsizei GLint * values
void CreateClamped(Vector< N, Real > const &derivative0, Vector< N, Real > const &derivative1)
NaturalSplineCurve(bool isFree, int numPoints, Vector< N, Real > const *points, Real const *times)
GLfixed GLfixed GLint GLint GLfixed points
#define LogError(message)
GLdouble GLdouble GLdouble z
GLenum GLenum GLenum input
std::vector< Vector< N, Real > > mD
GLsizei GLsizei numSegments
Quaternion< Real > Inverse(Quaternion< Real > const &d)
std::vector< Vector< N, Real > > mC