相关资料:
https://blog.csdn.net/wb175208/article/details/88376874 OSG粒子效果-雪
https://blog.csdn.net/chlk118/article/details/47009027?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-4.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-4.control
代码实例:
.pro
1 QT += core gui widgets 2 TARGET = TestOsgQt 3 TEMPLATE = app 4 DEFINES += QT_DEPRECATED_WARNINGS 5 CONFIG += c++11 6 7 SOURCES += \ 8 main.cpp 9 10 HEADERS += 11 12 OsgDir = D:\\RuanJian\\osg365R 13 CONFIG(release, debug|release) { 14 LIBS += -L$${OsgDir}/lib/ -losgDB -losgViewer -lOpenThreads -losgAnimation -losg \ 15 -losgEarth -losgEarthAnnotation -losgEarthFeatures -losgEarthSymbology -losgEarthUtil \ 16 -losgQOpenGL -losgUtil -losgText -losgTerrain -losgSim \ 17 -losgShadow -losgParticle -losgManipulator -losgGA -losgFX \ 18 -losgWidget 19 } else { 20 LIBS += -L$${OsgDir}/debug/lib/ -losgDBd -losgViewerd -lOpenThreadsd -losgAnimationd -losgd \ 21 -losgEarthd -losgEarthAnnotationd -losgEarthFeaturesd -losgEarthSymbologyd -losgEarthUtild \ 22 -losgQOpenGLd -losgUtild -losgTextd -losgTerraind -losgSimd \ 23 -losgShadowd -losgParticled -losgManipulatord -losgGAd -losgFXd \ 24 } 25 26 27 INCLUDEPATH += $${OsgDir}/include 28 DEPENDPATH += $${OsgDir}/include
.main
1 #include <QApplication> 2 3 #include <osg/Node> 4 #include <osg/Group> 5 #include <osg/Geode> 6 #include <osg/Geometry> 7 #include <osg/Texture2D> 8 #include <osg/StateSet> 9 #include <osg/PositionAttitudeTransform> 10 #include <osgViewer/Viewer> 11 #include <osgDB/ReadFile> 12 #include <osgParticle/PrecipitationEffect> 13 // 雨雪效果 14 #include <osg/MatrixTransform> 15 // 粒子效果 16 #include <osgParticle/PrecipitationEffect> 17 #include <osgParticle/Particle> 18 #include <osgParticle/LinearInterpolator> 19 #include <osgParticle/ParticleSystem> 20 #include <osgParticle/RandomRateCounter> 21 #include <osgParticle/PointPlacer> 22 #include <osgParticle/RadialShooter> 23 #include <osgParticle/ModularEmitter> 24 #include <osgParticle/ParticleSystemUpdater> 25 #include <osgParticle/ModularProgram> 26 #include <osgUtil/Optimizer> 27 #include <osgUtil/Simplifier> 28 // 雾 29 #include <osg/Fog> 30 #include <osgDB/ReadFile> 31 #include <osgViewer/Viewer> 32 #include <osg/StateSet> 33 #include <osg/StateAttribute> 34 #include <osgViewer/ViewerEventHandlers> 35 #include <osgWidget/ViewerEventHandlers> 36 37 int main(int argc, char *argv[]) 38 { 39 osg::Group* root = new osg::Group(); 40 41 osg::Matrixd mat; 42 mat.makeTranslate(osg::Vec3d(0.0, 1.0, 0.0)); 43 44 osg::ref_ptr<osg::MatrixTransform> trans = new osg::MatrixTransform; 45 trans->setMatrix(mat * osg::Matrixd::scale(10, 10, 10)); 46 // 雪花类 47 osg::ref_ptr<osgParticle::PrecipitationEffect> pe = new osgParticle::PrecipitationEffect; 48 // 设置雪花浓度 49 pe->snow(1); 50 int iLevel = 1; 51 pe->setParticleSize(iLevel / 10.0); 52 // 设置颜色 53 pe->setParticleColor(osg::Vec4(1, 1, 1, 1)); 54 // 设置风向 55 pe->setWind(osg::Vec3(0, 0, 0)); 56 57 trans->addChild(pe); 58 root->addChild(trans); 59 60 //最后,设置视窗类并进入仿真循环。 61 osgViewer::Viewer viewer; 62 //设置图形环境特性 63 osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits(); 64 traits->x = 100; 65 traits->y = 200; 66 traits->width = 600; 67 traits->height = 500; 68 traits->windowDecoration = true; 69 traits->doubleBuffer = true; 70 traits->sharedContext = 0; 71 //创建图形环境特性 72 osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); 73 if (gc.valid()) 74 { 75 osg::notify(osg::INFO)<<" GraphicsWindow has been created successfully."<<std::endl; 76 77 //清除窗口颜色及清除颜色和深度缓冲 78 gc->setClearColor(osg::Vec4f(0.2f,0.2f,0.6f,1.0f)); 79 gc->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 80 } 81 else 82 { 83 osg::notify(osg::NOTICE)<<" GraphicsWindow has not been created successfully."<<std::endl; 84 } 85 //设置视口 86 viewer.getCamera()->setViewport(new osg::Viewport(0,0, traits->width, traits->height)); 87 //设置图形环境 88 viewer.getCamera()->setGraphicsContext(gc.get()); 89 viewer.setSceneData( root ); 90 return viewer.run(); 91 }