widget.cpp:243:14: error: no member named 'setInterpolator' in 'osgAnimation::TemplateChannel<osgAnimation::TemplateSampler<osgAnimation::TemplateLinearInterpolator<osg::Vec3f, osg::Vec3f> > >'
时间: 2023-08-08 11:04:25 浏览: 108
这个错误是因为您尝试在osgAnimation::TemplateChannel对象上调用setInterpolator()方法,但是该类没有定义setInterpolator()方法。相反,您应该为osgAnimation::TemplateSampler对象设置插值器,然后将其附加到通道上。
例如,将上述代码修改为:
```cpp
osg::ref_ptr<osgAnimation::Vec3LinearChannel> channel = new osgAnimation::Vec3LinearChannel;
channel->setName("translate");
osg::ref_ptr<osgAnimation::Vec3LinearSampler> sampler = new osgAnimation::Vec3LinearSampler;
sampler->setInterpolator(new osgAnimation::Vec3LinearInterpolator);
sampler->addTimeControlPoint(0.0, osg::Vec3(0.0, 0.0, 0.0));
sampler->addTimeControlPoint(1.0, osg::Vec3(0.0, 0.0, 10.0));
channel->setSampler(sampler.get());
osg::ref_ptr<osgAnimation::Animation> animation = new osgAnimation::Animation;
animation->setPlayMode(osgAnimation::Animation::LOOP);
animation->setDuration(1.0);
animation->addChannel(channel);
osg::ref_ptr<osgAnimation::BasicAnimationManager> manager = new osgAnimation::BasicAnimationManager;
manager->registerAnimation(animation);
manager->playAnimation(animation);
model->setUpdateCallback(manager);
```
在这个版本的代码中,我们首先创建了osgAnimation::Vec3LinearSampler对象的引用,并为其设置插值器和关键帧。然后,我们将采样器附加到通道上,而不是直接为通道设置插值器。这样就可以避免setInterpolator()方法不存在的问题。
阅读全文