Osg-Osg使用NodeCallback实现Switch(Qt5.14.2+osgE3.6.5+win10)-No30-NodeCallback-Switch
相关资料
https://zhuanlan.zhihu.com/p/39737602
实例代码
.pro
1 QT += core gui widgets 2 QT += opengl 3 TARGET = TestOsgQt 4 TEMPLATE = app 5 DEFINES += QT_DEPRECATED_WARNINGS 6 CONFIG += c++11 7 8 SOURCES += \ 9 main.cpp 10 11 HEADERS += 12 13 OsgDir = D:\\Gitee\\osg365R 14 CONFIG(release, debug|release) { 15 LIBS += -L$${OsgDir}/lib/ -losgDB -losgViewer -lOpenThreads -losgAnimation -losg \ 16 -losgEarth -losgEarthAnnotation -losgEarthFeatures -losgEarthSymbology -losgEarthUtil \ 17 -losgQOpenGL -losgUtil -losgText -losgTerrain -losgSim \ 18 -losgShadow -losgParticle -losgManipulator -losgGA -losgFX \ 19 -losgWidget 20 } else { 21 LIBS += -L$${OsgDir}/debug/lib/ -losgDBd -losgViewerd -lOpenThreadsd -losgAnimationd -losgd \ 22 -losgEarthd -losgEarthAnnotationd -losgEarthFeaturesd -losgEarthSymbologyd -losgEarthUtild \ 23 -losgQOpenGLd -losgUtild -losgTextd -losgTerraind -losgSimd \ 24 -losgShadowd -losgParticled -losgManipulatord -losgGAd -losgFXd \ 25 } 26 27 LIBS += -lOpenGL32 28 LIBS += -lGlU32 29 30 INCLUDEPATH += $${OsgDir}/include 31 DEPENDPATH += $${OsgDir}/include
main.cpp
1 #include <osg/Switch> 2 #include <osgDB/ReadFile> 3 #include <osgViewer/Viewer> 4 5 class SwitchingCallback : public osg::NodeCallback 6 { 7 public: 8 SwitchingCallback() : _count(0) {} 9 10 virtual void operator()( osg::Node* node, osg::NodeVisitor* nv ) 11 { 12 osg::Switch* switchNode = static_cast<osg::Switch*>( node ); 13 if ( !((++_count)%60) && switchNode ) 14 { 15 switchNode->setValue( 0, !switchNode->getValue(0) ); 16 switchNode->setValue( 1, !switchNode->getValue(1) ); 17 } 18 traverse( node, nv ); 19 } 20 21 protected: 22 unsigned int _count; 23 }; 24 25 int main( int argc, char** argv ) 26 { 27 osg::ref_ptr<osg::Node> model1 = osgDB::readNodeFile( "D:\\Gitee\\data\\cow.osg" ); 28 osg::ref_ptr<osg::Node> model2 = osgDB::readNodeFile( "D:\\Gitee\\data\\nathan.osg" ); 29 30 osg::ref_ptr<osg::Switch> root = new osg::Switch; 31 root->addChild( model1.get(), false ); 32 root->addChild( model2.get(), true ); 33 root->setUpdateCallback( new SwitchingCallback ); 34 35 osgViewer::Viewer viewer; 36 viewer.setSceneData( root.get() ); 37 viewer.setUpViewInWindow(50,50,500,400); 38 return viewer.run(); 39 }
作者:疯狂Delphi
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
欢迎关注我,一起进步!扫描下方二维码即可加我