快速学习OSG(9)——粒子系统

快速学习OSG(9)——粒子系统了解粒子 osg 粒子系统

大家好,欢迎来到IT知识分享网。

一、 粒子系统

二、粒子系统的主要模块

三 粒子系统的模拟过程

四、示例

(一)雪效

#include <osgDB/ReadFile> #include <osgViewer/Viewer> #include <osgParticle/PrecipitationEffect> #include <osg/Node> void main() { osgViewer::Viewer viewer; //设置雪花类 osg::ref_ptr<osgParticle::PrecipitationEffect> precipitationEffect = new osgParticle::PrecipitationEffect; //设置雪花浓度 precipitationEffect->snow(0.5); //设置雪花颜色 precipitationEffect->setParticleColor(osg::Vec4(1, 1, 1, 1)); //设置风向 precipitationEffect->setWind(osg::Vec3(2, 0, 0)); osg::Group* root = new osg::Group(); //把雪花加入到场景结点 root->addChild(precipitationEffect.get()); osg::ref_ptr<osg::Node> glider = osgDB::readNodeFile("glider.osg"); root->addChild(glider.get()); viewer.setSceneData(root); viewer.realize(); viewer.run(); } 

快速学习OSG(9)——粒子系统

 (二)爆炸

#include <osgViewer/Viewer> #include <osg/Node> #include <osg/Geode> #include <osg/Group> #include <osgDB/ReadFile> #include <osgDB/WriteFile> #include <osgParticle/ExplosionDebrisEffect> #include <osgParticle/ExplosionEffect> #include <osgParticle/SmokeEffect> #include <osgParticle/FireEffect> #include <osgUtil/Optimizer> //创建爆炸效果 osg::ref_ptr<osg::Node> createExplode() { osg::ref_ptr<osg::Group> explode = new osg::Group(); //风向 osg::Vec3 wind(1.0f, 0.0f, 0.0f); osg::Vec3 position(0.0f, 0.0f, -1.0f); //爆炸模拟,10.0f为缩放比,默认为1.0f,不缩放 osg::ref_ptr<osgParticle::ExplosionEffect> explosion = new osgParticle::ExplosionEffect(position, 10.0f); osg::ref_ptr<osgParticle::ExplosionDebrisEffect> explosionDebri = new osgParticle::ExplosionDebrisEffect(position, 10.0f); //烟模拟 osg::ref_ptr<osgParticle::SmokeEffect> smoke = new osgParticle::SmokeEffect(position, 10.0f); //火焰模拟 osg::ref_ptr<osgParticle::FireEffect> fire = new osgParticle::FireEffect(position, 10.0f); //设置风向 explosion->setWind(wind); explosionDebri->setWind(wind); smoke->setWind(wind); fire->setWind(wind); //添加子节点 explode->addChild(explosion.get()); explode->addChild(explosionDebri.get()); explode->addChild(smoke.get()); explode->addChild(fire.get()); return explode.get(); } int main() { osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer(); osg::ref_ptr<osg::Group> root = new osg::Group(); //添加爆炸效果 root->addChild(createExplode()); //优化场景数据 osgUtil::Optimizer optimizer; optimizer.optimize(root.get()); //设置场景数据 viewer->setSceneData(root.get()); //初始化并创建窗口 viewer->realize(); //viewer->setUpViewInWindow(200, 200, 800, 800); viewer->run(); }

快速学习OSG(9)——粒子系统

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://haidsoft.com/132715.html

(0)
上一篇 2025-07-29 15:26
下一篇 2025-07-29 15:33

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注微信