19#ifndef OSGANIMATION_INTERPOLATOR
20#define OSGANIMATION_INTERPOLATOR 1
28 template <
class TYPE,
class KEY>
40 int key_size = keys.
size();
42 osg::notify(
osg::WARN) <<
"TemplateInterpolatorBase::getKeyIndexFromTime the container is empty, impossible to get key index from time" << std::endl;;
50 double time1 = keysVector[mid].
getTime();
63 template <
class TYPE,
class KEY=TYPE>
72 if (time >= keyframes.
back().getTime())
74 result = keyframes.
back().getValue();
77 else if (time <= keyframes.
front().getTime())
79 result = keyframes.
front().getValue();
84 result = keyframes[i].getValue();
89 template <
class TYPE,
class KEY=TYPE>
98 if (time >= keyframes.
back().getTime())
100 result = keyframes.
back().getValue();
103 else if (time <= keyframes.
front().getTime())
105 result = keyframes.
front().getValue();
110 float blend = (time - keyframes[i].getTime()) / ( keyframes[i+1].getTime() - keyframes[i].getTime());
111 const TYPE& v1 = keyframes[i].getValue();
112 const TYPE& v2 = keyframes[i+1].getValue();
113 result = v1*(1-blend) + v2*blend;
118 template <
class TYPE,
class KEY=TYPE>
125 if (time >= keyframes.
back().getTime())
127 result = keyframes.
back().getValue();
130 else if (time <= keyframes.
front().getTime())
132 result = keyframes.
front().getValue();
137 float blend = (time - keyframes[i].getTime()) / ( keyframes[i+1].getTime() - keyframes[i].getTime());
138 const TYPE& q1 = keyframes[i].getValue();
139 const TYPE& q2 = keyframes[i+1].getValue();
140 result.slerp(blend,q1,q2);
145 template <
class TYPE,
class KEY>
153 if (time >= keyframes.
back().getTime())
155 keyframes.
back().getValue().uncompress(keyframes.mScale, keyframes.mMin, result);
158 else if (time <= keyframes.
front().getTime())
160 keyframes.
front().getValue().uncompress(keyframes.mScale, keyframes.mMin, result);
165 float blend = (time - keyframes[i].getTime()) / ( keyframes[i+1].getTime() - keyframes[i].getTime());
167 keyframes[i].getValue().uncompress(keyframes.mScale, keyframes.mMin, v1);
168 keyframes[i+1].getValue().uncompress(keyframes.mScale, keyframes.mMin, v2);
169 result = v1*(1-blend) + v2*blend;
175 template <
class TYPE,
class KEY=TYPE>
184 if (time >= keyframes.
back().getTime())
186 result = keyframes.
back().getValue().getPosition();
189 else if (time <= keyframes.
front().getTime())
191 result = keyframes.
front().getValue().getPosition();
197 float t = (time - keyframes[i].getTime()) / ( keyframes[i+1].getTime() - keyframes[i].getTime());
198 float one_minus_t = 1.0-t;
199 float one_minus_t2 = one_minus_t * one_minus_t;
200 float one_minus_t3 = one_minus_t2 * one_minus_t;
203 TYPE v0 = keyframes[i].getValue().getPosition() * one_minus_t3;
204 TYPE v1 = keyframes[i].getValue().getControlPointIn() * (3.0 * t * one_minus_t2);
205 TYPE v2 = keyframes[i].getValue().getControlPointOut() * (3.0 * t2 * one_minus_t);
206 TYPE v3 = keyframes[i+1].getValue().getPosition() * (t2 * t);
208 result = v0 + v1 + v2 + v3;
double getTime() const
Definition Keyframe:36
Definition osgAnimation/Interpolator:177
TemplateCubicBezierInterpolator()
Definition osgAnimation/Interpolator:180
void getValue(const TemplateKeyframeContainer< KEY > &keyframes, double time, TYPE &result) const
Definition osgAnimation/Interpolator:181
Definition osgAnimation/Interpolator:30
KEY KeyframeType
Definition osgAnimation/Interpolator:32
TYPE UsingType
Definition osgAnimation/Interpolator:33
int getKeyIndexFromTime(const TemplateKeyframeContainer< KEY > &keys, double time) const
Definition osgAnimation/Interpolator:38
TemplateInterpolatorBase()
Definition osgAnimation/Interpolator:36
virtual unsigned int size() const
Definition Keyframe:86
Definition osgAnimation/Interpolator:91
TemplateLinearInterpolator()
Definition osgAnimation/Interpolator:94
void getValue(const TemplateKeyframeContainer< KEY > &keyframes, double time, TYPE &result) const
Definition osgAnimation/Interpolator:95
Definition osgAnimation/Interpolator:147
TemplateLinearPackedInterpolator()
Definition osgAnimation/Interpolator:150
void getValue(const TemplateKeyframeContainer< KEY > &keyframes, double time, TYPE &result) const
Definition osgAnimation/Interpolator:151
Definition osgAnimation/Interpolator:120
void getValue(const TemplateKeyframeContainer< KEY > &keyframes, double time, TYPE &result) const
Definition osgAnimation/Interpolator:123
TemplateSphericalLinearInterpolator()
Definition osgAnimation/Interpolator:122
Definition osgAnimation/Interpolator:65
TemplateStepInterpolator()
Definition osgAnimation/Interpolator:68
void getValue(const TemplateKeyframeContainer< KEY > &keyframes, double time, TYPE &result) const
Definition osgAnimation/Interpolator:69
const_reference back() const
Definition MixinVector:136
const_reference front() const
Definition MixinVector:138
TemplateCubicBezierInterpolator< float, FloatCubicBezier > FloatCubicBezierInterpolator
Definition osgAnimation/Interpolator:229
TemplateStepInterpolator< osg::Vec3, Vec3Packed > Vec3PackedStepInterpolator
Definition osgAnimation/Interpolator:216
TemplateLinearInterpolator< osg::Vec3, osg::Vec3 > Vec3LinearInterpolator
Definition osgAnimation/Interpolator:223
TemplateStepInterpolator< osg::Vec4, osg::Vec4 > Vec4StepInterpolator
Definition osgAnimation/Interpolator:217
TemplateLinearInterpolator< osg::Vec3, Vec3Packed > Vec3PackedLinearInterpolator
Definition osgAnimation/Interpolator:224
TemplateLinearInterpolator< float, float > FloatLinearInterpolator
Definition osgAnimation/Interpolator:221
TemplateStepInterpolator< osg::Vec2, osg::Vec2 > Vec2StepInterpolator
Definition osgAnimation/Interpolator:214
TemplateCubicBezierInterpolator< osg::Vec2, Vec2CubicBezier > Vec2CubicBezierInterpolator
Definition osgAnimation/Interpolator:231
TemplateLinearInterpolator< osg::Vec4, osg::Vec4 > Vec4LinearInterpolator
Definition osgAnimation/Interpolator:225
TemplateStepInterpolator< osg::Vec3, osg::Vec3 > Vec3StepInterpolator
Definition osgAnimation/Interpolator:215
TemplateCubicBezierInterpolator< osg::Vec3, Vec3CubicBezier > Vec3CubicBezierInterpolator
Definition osgAnimation/Interpolator:232
TemplateStepInterpolator< float, float > FloatStepInterpolator
Definition osgAnimation/Interpolator:213
TemplateStepInterpolator< double, double > DoubleStepInterpolator
Definition osgAnimation/Interpolator:212
TemplateCubicBezierInterpolator< osg::Vec4, Vec4CubicBezier > Vec4CubicBezierInterpolator
Definition osgAnimation/Interpolator:233
TemplateStepInterpolator< osg::Quat, osg::Quat > QuatStepInterpolator
Definition osgAnimation/Interpolator:218
TemplateCubicBezierInterpolator< double, DoubleCubicBezier > DoubleCubicBezierInterpolator
Definition osgAnimation/Interpolator:230
TemplateLinearInterpolator< osg::Matrixf, osg::Matrixf > MatrixLinearInterpolator
Definition osgAnimation/Interpolator:227
TemplateSphericalLinearInterpolator< osg::Quat, osg::Quat > QuatSphericalLinearInterpolator
Definition osgAnimation/Interpolator:226
TemplateLinearInterpolator< double, double > DoubleLinearInterpolator
Definition osgAnimation/Interpolator:220
TemplateLinearInterpolator< osg::Vec2, osg::Vec2 > Vec2LinearInterpolator
Definition osgAnimation/Interpolator:222
@ WARN
Definition Notify:33
std::ostream & notify(void)
Definition Notify:80