widget.cpp:170:33: error: no viable conversion from 'osgEarth::SkyNode *' to 'osg::ref_ptr<osg::Drawable>' ref_ptr:37:9: note: candidate constructor not viable: no known conversion from 'osgEarth::SkyNode *' to 'osg::Drawable *' for 1st argument ref_ptr:38:9: note: candidate constructor not viable: no known conversion from 'osgEarth::SkyNode *' to 'const osg::ref_ptr<osg::Drawable> &' for 1st argument ref_ptr:40:9: note: candidate constructor not viable: no known conversion from 'osgEarth::SkyNode *' to 'observer_ptr<osg::Drawable> &' for 1st argument ref_ptr:39:31: note: candidate template ignored: could not match 'ref_ptr<type-parameter-0-0>' against 'osgEarth::SkyNode *'
时间: 2024-02-06 07:01:58 浏览: 155
widget.cpp
看起来你正在将 `osgEarth::SkyNode` 类型的对象直接赋值给了 `osg::ref_ptr<osg::Drawable>` 类型的变量,这是不兼容的,因为 `SkyNode` 并不是继承自 `Drawable`。
正确的写法应该是创建一个 `osg::Geode` 对象,将 `SkyNode` 添加到 `osg::Geode` 中,然后将 `osg::Geode` 添加到场景图中。以下是一个示例代码:
```
osg::ref_ptr<osg::Geode> skyGeode = new osg::Geode();
osg::ref_ptr<osgEarth::Util::SkyNode> skyNode = new osgEarth::Util::SkyNode(osgEarth::Util::SkyOptions());
skyGeode->addDrawable(skyNode.get());
root->addChild(skyGeode.get());
```
这将创建一个 `osgEarth::Util::SkyNode` 对象,并将其添加到 `osg::Geode` 中,然后将 `osg::Geode` 添加到场景图中。
阅读全文