• OsgOsg使用NodeCallback实现Switch(Qt5.14.2+osgE3.6.5+win10)No30NodeCallbackSwitch


    相关资料

    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
    View Code

    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 }
    View Code
  • 相关阅读:
    模拟两位选手进行n羽毛球比赛(15分赛制)并计算模拟胜率
    Pyton实例
    Python图片处理
    jieba库的使用和好玩的词云
    Python汉诺塔问题
    多线程同时操作一个epoll_fd
    Linux tr命令
    iptables 深入分析
    Linux xtables
    Linux IPC 共享内存
  • 原文地址:https://www.cnblogs.com/FKdelphi/p/16591871.html
Copyright © 2020-2023  润新知