osgAnimation.InCircFunction类表示一个包含了一个输入值和输出值之间的动画函数,其作用是对输入值进行计算并返回动画的输出值。
该类实现了InCirc函数,该函数是常用的Easing函数之一。Easing函数是动画中常用的函数,用于平滑过渡动画的执行。
float operator()(float t) const;
#include <osgAnimation/EaseMotion>
#include <osgAnimation/InOutCircMotion>
osg::ref_ptr<osgAnimation::InOutCircMotion> ic_motion = new osgAnimation::InOutCircMotion;
ic_motion->setAmplitude(0.5f);
ic_motion->setPeriod(1.0f);
osg::ref_ptr<osgAnimation::Vec3LinearSampler> sampler = new osgAnimation::Vec3LinearSampler;
sampler->getOrCreateKeyframeContainer()->push_back(osgAnimation::Vec3Keyframe(0.0f, osg::Vec3(0.0f, 0.0f, 0.0f)));
sampler->getOrCreateKeyframeContainer()->push_back(osgAnimation::Vec3Keyframe(1.0f, osg::Vec3(1.0f, 1.0f, 1.0f)));
osg::ref_ptr<osgAnimation::LinearMotion> linear_motion = new osgAnimation::LinearMotion;
linear_motion->setDuration(1.0f);
linear_motion->setVelocity(osg::Vec3(1.0f, 1.0f, 1.0f));
osg::ref_ptr<osgAnimation::EaseMotion> ease_motion = new osgAnimation::EaseMotion;
ease_motion->setMotion(ic_motion);
ease_motion->setChild(linear_motion);
osg::ref_ptr<osgAnimation::SamplerAnimation> animation = new osgAnimation::SamplerAnimation;
animation->setSampler(sampler);
animation->setPlayMode(osgAnimation::Animation::LOOP);
animation->setDuration(1.0f);
osg::ref_ptr<osg::MatrixTransform> mt = new osg::MatrixTransform;
mt->setDataVariance(osg::Object::DYNAMIC);
mt->addChild(geode);
osg::ref_ptr<osgAnimation::StackedTransform> transform = new osgAnimation::StackedTransform;
transform->addChild(mt);
transform->addMotion(ease_motion);
transform->addAnimation(animation);