added protected function to cubic hermite spline

This commit is contained in:
amantley 2019-02-21 13:32:28 -08:00
parent 0bdc527ce7
commit 50bc8d3646

View file

@ -66,19 +66,8 @@ public:
memset(_values, 0, sizeof(float) * (NUM_SUBDIVISIONS + 1));
}
CubicHermiteSplineFunctorWithArcLength(const glm::vec3& p0, const glm::vec3& m0, const glm::vec3& p1, const glm::vec3& m1) : CubicHermiteSplineFunctor(p0, m0, p1, m1) {
// initialize _values with the accumulated arcLength along the spline.
const float DELTA = 1.0f / NUM_SUBDIVISIONS;
float alpha = 0.0f;
float accum = 0.0f;
_values[0] = 0.0f;
glm::vec3 prevValue = this->operator()(alpha);
for (int i = 1; i < NUM_SUBDIVISIONS + 1; i++) {
glm::vec3 nextValue = this->operator()(alpha + DELTA);
accum += glm::distance(prevValue, nextValue);
alpha += DELTA;
_values[i] = accum;
prevValue = nextValue;
}
initValues();
}
CubicHermiteSplineFunctorWithArcLength(const glm::quat& tipRot, const glm::vec3& tipTrans, const glm::quat& baseRot, const glm::vec3& baseTrans, float baseGain = 1.0f, float tipGain = 1.0f) : CubicHermiteSplineFunctor() {
@ -89,17 +78,7 @@ public:
_p1 = tipTrans;
_m1 = tipGain * linearDistance * (tipRot * Vectors::UNIT_Y);
// initialize _values with the accumulated arcLength along the spline.
const float DELTA = 1.0f / NUM_SUBDIVISIONS;
float alpha = 0.0f;
float accum = 0.0f;
_values[0] = 0.0f;
for (int i = 1; i < NUM_SUBDIVISIONS + 1; i++) {
accum += glm::distance(this->operator()(alpha),
this->operator()(alpha + DELTA));
alpha += DELTA;
_values[i] = accum;
}
initValues();
}
CubicHermiteSplineFunctorWithArcLength(const CubicHermiteSplineFunctorWithArcLength& orig) : CubicHermiteSplineFunctor(orig) {
@ -131,6 +110,21 @@ public:
}
protected:
float _values[NUM_SUBDIVISIONS + 1];
void initValues() {
// initialize _values with the accumulated arcLength along the spline.
const float DELTA = 1.0f / NUM_SUBDIVISIONS;
float alpha = 0.0f;
float accum = 0.0f;
_values[0] = 0.0f;
for (int i = 1; i < NUM_SUBDIVISIONS + 1; i++) {
accum += glm::distance(this->operator()(alpha),
this->operator()(alpha + DELTA));
alpha += DELTA;
_values[i] = accum;
}
}
};
#endif // hifi_CubicHermiteSpline_h