osgAnimation.TemplateKeyframeContainer是一个模板类,用于存储关键帧并实现插值。继承自osgAnimation.KeyframeContainerBase。
ValueType:存储在关键帧中的值的类型。TargetType:目标类型,需要实现插值功能。默认为ValueType。TemplateKeyframeContainer类的公共成员函数如下:
addKeyframevoid addKeyframe(double time, const ValueType& value)
向容器中添加一个指定时间和值的关键帧。
time:关键帧时间。value:关键帧的值。getDurationdouble getDuration() const
获取最后一个关键帧与第一个关键帧之间的时间差,即容器中的动画时长。
getValueAtValueType getValueAt(double time) const
获取时间上最接近的关键帧的值,并使用插值方法来获取给定时间的值。
time:需要获取值的时间。getValueAtvoid getValueAt(double time, TargetType& outValue) const
获取时间上最接近的关键帧的值,并使用插值方法来获取给定时间的值。将计算的结果存储在outValue中。
time:需要获取值的时间。outValue:计算结果存储的变量。getValueRangeosg::Vec2 getValueRange() const
获取容器中存储的值的范围。
animatevoid animate(double time, TargetType& outValue) const
使用插值方法计算给定时间的值,并将结果存储在outValue中。
time:需要计算值的时间。outValue:计算结果存储的变量。getInterpolationtemplate<typename Interpolator>
Interpolator getInterpolation() const
获取指定类型的插值器。
Interpolator:需要获取的插值器类型。setInterpolationtemplate<typename Interpolator>
void setInterpolation(const Interpolator& interp)
设置指定类型的插值器。
interp:需要设置的插值器类型。// 创建容器并添加关键帧
osgAnimation::TemplateKeyframeContainer<float> container;
container.addKeyframe(0.0, 10.0);
container.addKeyframe(1.0, 20.0);
container.addKeyframe(2.0, 30.0);
// 获取动画时长
double duration = container.getDuration();
// 获取给定时间的值
float value = container.getValueAt(1.5);
// 计算给定时间的值
float animatedValue;
container.animate(1.5, animatedValue);