Skip to content

Commit

Permalink
Main: SimpleSpline - make coeffs static and simplify constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
paroj committed Feb 3, 2024
1 parent 6b8123a commit d5f3150
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 27 deletions.
6 changes: 0 additions & 6 deletions OgreMain/include/OgreSimpleSpline.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,6 @@ namespace Ogre {

std::vector<Vector3> mPoints;
std::vector<Vector3> mTangents;

/// Matrix of coefficients
Matrix4 mCoeffs;



};

/** @} */
Expand Down
32 changes: 11 additions & 21 deletions OgreMain/src/OgreSimpleSpline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,6 @@ namespace Ogre {
//---------------------------------------------------------------------
SimpleSpline::SimpleSpline()
{
// Set up matrix
// Hermite polynomial
mCoeffs[0][0] = 2;
mCoeffs[0][1] = -2;
mCoeffs[0][2] = 1;
mCoeffs[0][3] = 1;
mCoeffs[1][0] = -3;
mCoeffs[1][1] = 3;
mCoeffs[1][2] = -2;
mCoeffs[1][3] = -1;
mCoeffs[2][0] = 0;
mCoeffs[2][1] = 0;
mCoeffs[2][2] = 1;
mCoeffs[2][3] = 0;
mCoeffs[3][0] = 1;
mCoeffs[3][1] = 0;
mCoeffs[3][2] = 0;
mCoeffs[3][3] = 0;

mAutoCalc = true;
}
//---------------------------------------------------------------------
Expand Down Expand Up @@ -108,6 +89,15 @@ namespace Ogre {
return mPoints[fromIndex + 1];
}

// Set up matrix
// Hermite polynomial
static Matrix4 hCoeffs = {
2, -2, 1, 1,
-3, 3, -2, -1,
0, 0, 1, 0,
1, 0, 0, 0
};

// Real interpolation
// Form a vector of powers of t
Real t2, t3;
Expand All @@ -116,7 +106,7 @@ namespace Ogre {
Vector4 powers(t3, t2, t, 1);


// Algorithm is ret = powers * mCoeffs * Matrix4(point1, point2, tangent1, tangent2)
// Algorithm is ret = powers * hCoeffs * Matrix4(point1, point2, tangent1, tangent2)
const Vector3& point1 = mPoints[fromIndex];
const Vector3& point2 = mPoints[fromIndex+1];
const Vector3& tan1 = mTangents[fromIndex];
Expand All @@ -140,7 +130,7 @@ namespace Ogre {
pt[3][2] = tan2.z;
pt[3][3] = 1.0f;

Vector4 ret = powers * mCoeffs * pt;
Vector4 ret = powers * hCoeffs * pt;


return Vector3(ret.x, ret.y, ret.z);
Expand Down

0 comments on commit d5f3150

Please sign in to comment.