50 #define ANIMATIONHELPER_CC
52 #include "AnimationHelper.hh"
56 #define APPROXIMATION_EPSILON 1.0e-09
57 #define VERYSMALL 1.0e-20
58 #define MAXIMUM_ITERATIONS 1000
60 template<
typename Scalar>
61 Scalar AnimationHelper::clampTo01Interval(Scalar _value) {
64 else if (_value > 1.0)
70 template<
typename Scalar>
71 Scalar AnimationHelper::abs(Scalar _value) {
78 template<
typename Scalar>
80 if (_atX - _P0X < VERYSMALL)
83 if (_P1X - _atX < VERYSMALL)
86 long iterationStep = 0;
88 float u = 0.0f;
float v = 1.0f;
91 while (iterationStep < MAXIMUM_ITERATIONS) {
94 Scalar a = (_P0X + _C0X)*0.5;
95 Scalar b = (_C0X + _C1X)*0.5;
96 Scalar c = (_C1X + _P1X)*0.5;
97 Scalar d = (a + b)*0.5;
98 Scalar e = (b + c)*0.5;
99 Scalar f = (d + e)*0.5;
102 if (abs<Scalar>(f - _atX) < APPROXIMATION_EPSILON)
103 return clampTo01Interval<Scalar>((u + v)*0.5f);
112 _C0X = a; _C1X = d; _P1X = f; v = (u + v)*0.5f;
118 return clampTo01Interval<Scalar>((u + v)*0.5f);
121 template<
typename Scalar>
123 unsigned int size = _P0.size();
124 assert(size == _P1.size() && size == _C0.size() && size == _C1.size());
129 std::vector<Scalar> result;
131 for (
unsigned int i=0;i<size;++i) {
132 result.push_back( _P0[i]*sinv*sinv*sinv + 3*_C0[i]*s*sinv*sinv + 3*_C1[i]*s*s*sinv + _P1[i]*s*s*s );
static float approximateCubicBezierParameter(Scalar _atX, Scalar _P0X, Scalar _P1X, Scalar _C0X, Scalar _C1X)
Approximates the parameter value for a Bezier curve to get a certain x value Does an iterative DeCast...
static std::vector< Scalar > evaluateBezier(float at, std::vector< Scalar > _P0, std::vector< Scalar > _P1, std::vector< Scalar > _C0, std::vector< Scalar > _C1)
Evaluates the cubic Bezier curve parameterized by P0, P1, C0 and C1 at the parameter value "at"...