mirror of
https://github.com/lubosz/overte.git
synced 2025-08-08 03:08:00 +02:00
added protected function to cubic hermite spline
This commit is contained in:
parent
0bdc527ce7
commit
50bc8d3646
1 changed files with 18 additions and 24 deletions
|
@ -66,19 +66,8 @@ public:
|
||||||
memset(_values, 0, sizeof(float) * (NUM_SUBDIVISIONS + 1));
|
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) {
|
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;
|
initValues();
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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() {
|
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;
|
_p1 = tipTrans;
|
||||||
_m1 = tipGain * linearDistance * (tipRot * Vectors::UNIT_Y);
|
_m1 = tipGain * linearDistance * (tipRot * Vectors::UNIT_Y);
|
||||||
|
|
||||||
// initialize _values with the accumulated arcLength along the spline.
|
initValues();
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CubicHermiteSplineFunctorWithArcLength(const CubicHermiteSplineFunctorWithArcLength& orig) : CubicHermiteSplineFunctor(orig) {
|
CubicHermiteSplineFunctorWithArcLength(const CubicHermiteSplineFunctorWithArcLength& orig) : CubicHermiteSplineFunctor(orig) {
|
||||||
|
@ -131,6 +110,21 @@ public:
|
||||||
}
|
}
|
||||||
protected:
|
protected:
|
||||||
float _values[NUM_SUBDIVISIONS + 1];
|
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
|
#endif // hifi_CubicHermiteSpline_h
|
||||||
|
|
Loading…
Reference in a new issue