致谢

感谢网友提出这个问题。大家有问题也可以在评论区提出,有问必有答。

问题描述

粒子系统在OSG里好好的,结果放在地球上就看不见了。将代码发给了我,让我长个眼看看。也欢迎大家把问题发给我调试。

本节代码在网盘中:

【击此打开网盘资源链接】

定位过程

怀疑是粒子太小,扒拉着找不到的原因。因此我创建了一个大盒子,长宽高都是10000米,将其移到109,34,0处,大概是陕西附近,然后盒子的面高度就是10000/2=5000。

然后我再将粒子移到109,34,5000处,就可以在盒子的面上找粒子。就找到了。

确实不仔细找,地球那么大,找不到的。

关键代码

将模型移到某处用的是MatrixTransform,然后用EllipsoidModel算出矩阵即可,以下代码是将盒子移到109,34,0处:

    osg::MatrixTransform* mt = new osg::MatrixTransform;//将这个粒子系统移动到109 34 500米osg::EllipsoidModel* em = new osg::EllipsoidModel;osg::Matrixd mtd;em->computeLocalToWorldTransformFromLatLongHeight(osg::inDegrees(34.0), osg::inDegrees(109.0), 0, mtd);mt->setMatrix(mtd);osg::Node* glider = createBox();root->addChild(mt);mt->addChild(glider);

以下是所有代码


#include <osgViewer/Viewer>
#include <osgDB/ReadFile>
#include <osgGA/EventHandler>
#include <osgParticle/ParticleSystem>
#include <osgParticle/LinearInterpolator>
#include <osg/MatrixTransform>
#include <osgParticle/RandomRateCounter>
#include <osgParticle/PointPlacer>
#include <osgParticle/RadialShooter>
#include <osgParticle/ModularEmitter>
#include <osgParticle/ParticleSystemUpdater>
#include <osgParticle/ModularProgram>
#include <osgEarth/EarthManipulator>
#include <osgEarth/ExampleResources>
#include <osgEarth/MapNode>
#include <osgGA/NodeTrackerManipulator>
#include <osg/ShapeDrawable>
#include <osg/Geode>
#include <osg/Geometry>using namespace osgEarth;
using namespace osgEarth::Util;osg::Node* createBox()
{osg::Geode* gnode = new osg::Geode;osg::ShapeDrawable* sd = new osg::ShapeDrawable(new osg::Box(osg::Vec3(0.0, 0.0, 0.0), 10000.0, 10000.0, 10000.0));gnode->addDrawable(sd);return gnode;
}//创建火球
void createFireBall(osg::MatrixTransform* smokeNode)
{// 创建粒子对象,设置其属性并交由粒子系统使用。osgParticle::Particle particleTempalte;particleTempalte.setShape(osgParticle::Particle::QUAD);particleTempalte.setLifeTime(15); // 单位:秒particleTempalte.setSizeRange(osgParticle::rangef(3.0f, 1.0f)); // 单位:米particleTempalte.setAlphaRange(osgParticle::rangef(1, 0));particleTempalte.setColorRange(osgParticle::rangev4(osg::Vec4(1.0f, 0.2f, 0.0f, 1.0f),osg::Vec4(0.1f, 0.1f, 0.1f, 0)));particleTempalte.setPosition(osg::Vec3(0.0f, 0.0f, 0.0f));particleTempalte.setVelocity(osg::Vec3(0.0f, 0.0f, 0.0f));particleTempalte.setMass(0.1f); //单位:千克particleTempalte.setRadius(0.2f);particleTempalte.setSizeInterpolator(new osgParticle::LinearInterpolator);particleTempalte.setAlphaInterpolator(new osgParticle::LinearInterpolator);particleTempalte.setColorInterpolator(new osgParticle::LinearInterpolator);// 创建并初始化粒子系统。osgParticle::ParticleSystem* particleSystem = new osgParticle::ParticleSystem;particleSystem->setDataVariance(osg::Node::STATIC);// 设置材质,是否放射粒子,以及是否使用光照。particleSystem->setDefaultAttributes("Images/smoke.rgb", true, false);osg::Geode* geode = new osg::Geode;geode->addDrawable(particleSystem);smokeNode->addChild(geode);//设置为粒子系统的缺省粒子对象。particleSystem->setDefaultParticleTemplate(particleTempalte);//获取放射极中缺省计数器的句柄,调整每帧增加的新粒子数目osgParticle::RandomRateCounter* particleGenerateRate = new osgParticle::RandomRateCounter();particleGenerateRate->setRateRange(30, 50);// 每秒新生成的粒子范围particleGenerateRate->setDataVariance(osg::Node::DYNAMIC);// 自定义一个放置器,这里创建并初始化一个点放置器osgParticle::PointPlacer* particlePlacer = new osgParticle::PointPlacer;particlePlacer->setCenter(osg::Vec3(0.0f, 0.0f, 0.0f));particlePlacer->setDataVariance(osg::Node::DYNAMIC);// 自定义一个弧度发射器osgParticle::RadialShooter* particleShooter = new osgParticle::RadialShooter;// 设置发射器的属性particleShooter->setDataVariance(osg::Node::DYNAMIC);particleShooter->setThetaRange(-0.1f, 0.1f);// 弧度值,与Z 轴夹角particleShooter->setPhiRange(-0.1f, 0.1f);particleShooter->setInitialSpeedRange(5, 7.5f);//单位:米/秒//创建标准放射极对象osgParticle::ModularEmitter* emitter = new osgParticle::ModularEmitter;emitter->setDataVariance(osg::Node::DYNAMIC);emitter->setCullingActive(false);// 将放射极对象与粒子系统关联。emitter->setParticleSystem(particleSystem);// 设置计数器emitter->setCounter(particleGenerateRate);// 设置放置器emitter->setPlacer(particlePlacer);// 设置发射器emitter->setShooter(particleShooter);// 把放射极添加为变换节点smokeNode->addChild(emitter);// 添加更新器,以实现每帧的粒子管理。osgParticle::ParticleSystemUpdater* particleSystemUpdater = new osgParticle::ParticleSystemUpdater;// 将更新器与粒子系统对象关联。particleSystemUpdater->addParticleSystem(particleSystem);// 将更新器节点添加到场景中。smokeNode->addChild(particleSystemUpdater);// 创建标准编程器对象并与粒子系统相关联。osgParticle::ModularProgram* particleMoveProgram = new osgParticle::ModularProgram;particleMoveProgram->setParticleSystem(particleSystem);// 最后,将编程器添加到场景中。smokeNode->addChild(particleMoveProgram);
}int main()
{osgEarth::initialize();osgViewer::Viewer viewer;osg::Group* root = new osg::Group;root->addChild(osgDB::readNodeFile("simple.earth"));osg::MatrixTransform* mt = new osg::MatrixTransform;//将这个粒子系统移动到109 34 500米osg::EllipsoidModel* em = new osg::EllipsoidModel;osg::Matrixd mtd;em->computeLocalToWorldTransformFromLatLongHeight(osg::inDegrees(34.0), osg::inDegrees(109.0), 0, mtd);mt->setMatrix(mtd);osg::Node* glider = createBox();root->addChild(mt);mt->addChild(glider);//粒子系统osg::MatrixTransform* mt1 = new osg::MatrixTransform;osg::Matrixd mtd1;em->computeLocalToWorldTransformFromLatLongHeight(osg::inDegrees(34.0), osg::inDegrees(109.0), 5000, mtd1);mt1->setMatrix(mtd1);createFireBall(mt1);root->addChild(mt1);viewer.setCameraManipulator(new EarthManipulator());viewer.setSceneData(root);return viewer.run();
}

第16节 调试-粒子系统放在地球上,不见了相关推荐

  1. 招募:500名学生,36元上16节课,报满为止,限时抢购!(含4本实体书包邮)...

    衡中代表什么? 2011年,衡水中学向北大清华输送70人,并占据河北省高考前200名中的一半. 2013年,衡水中学独占清华北大招生人数的80%,104位考入清华北大. 2018年,衡水中学清北录取总 ...

  2. python怎么画地球_第12天|16天搞定Python数据分析,在地球上画个圈

    在数据可视化过程中,有时候,你需要将数据根据其采集的地理位置在地图上显示出来.比如说我们会想要在地图上画出城市,飞机的航线,乃至于城市景点等等.通常来说,一个地理信息系统都会带有这样的功能. 在Pyt ...

  3. 海奥华预言--第三章 地球上的第一个人

    当我们在Haatis,就是以前描述过的那个休息室里重新坐好之后,涛就开始了她那奇怪的故事. "米歇,准确地讲,是在一百三十五万年以前,在人马座星座(Centaur)中一个叫巴卡拉梯尼(Bak ...

  4. 科普知识------地球上的水

    转贴自:http://www.dlgw.net/XuanXiuJiaoCan/ShowArticle.asp?ArticleID=1060   地球不同于其他行星的主要特征之一,是地球上有丰富的水.地 ...

  5. 第二章排错的工具:调试器Windbg(上)

    感谢博主 http://book.51cto.com/art/200711/59731.htm <Windows用户态程序高效排错>第二章主要介绍用户态调试相关的知识和工具.本文主要讲了排 ...

  6. Microbiome:地球上有多大比例的原核生物已经被测序了基因组?

    Microbiome:地球上有多大比例的原核生物已经被测序了基因组? Estimate of the sequenced proportion of the global prokaryotic ge ...

  7. 库克:AR将成为下一个核心科技,苹果是地球上竞争对手最多的企业

    2019-12-11 16:18:53 智东西(公众号:zhidxcom) 编 | 王颖 导语:库克指出,10年后的苹果将是硬件.软件和服务组成的产品企业. 智东西12月11日消息,苹果CEO蒂姆·库 ...

  8. 写好python的代码怎么放在spark上跑_Spark精华问答 | spark的组件构成有哪些?

    戳蓝字"CSDN云计算"关注我们哦! Spark是一个针对超大数据集合的低延迟的集群分布式计算系统,比MapReducer快40倍左右,是hadoop的升级版本,Hadoop作为第 ...

  9. 《Xcode实战开发》——2.8节调试区域

    本节书摘来自异步社区<Xcode实战开发>一书中的第2章,第2.8节调试区域,作者 [美]Maurice Kelly , Joshua Nozzi,更多章节内容可以访问云栖社区" ...

最新文章

  1. 那些复杂的技术设计的开始离我们并不遥远
  2. 数万人的背影|非典型产品经理的生存现状
  3. JavaScript中的立即执行函数
  4. centos 的关机命令
  5. 数据库系统概念总结:第二章 关系模型介绍
  6. PKUWC 2018 滚粗记
  7. 1 京东_推荐好友拿好礼 | 每1积分可兑换30元京东电子卡
  8. 前端学习(3143):react-hello-react之总结生命周期
  9. 论文浅尝 - EMNLP2020 | ConceptBert:视觉问题回答的概念感知表示
  10. IDEA配置tomcat部署web项目时没有artifacts
  11. python判断nan格式_关于Python中Inf与Nan的判断问题详解
  12. UIwebView缩放
  13. python 开发框架_python的web开发框架有哪些
  14. Python程序:输出斐波那契数列
  15. 元素周期表排列的规律_高中化高中化学元素周期表六大常考规律与特征学元素周期表六大常考规律与特征...
  16. Chapter 4 Invitations——18
  17. STORM的DRPC通讯
  18. 网站渗透思路(小白专看,大佬绕道)
  19. 阿里巴巴平台型产品经理
  20. 安装QQ音乐后导致Windows系统程序audiodg.exe频繁报错

热门文章

  1. android wms各个类的作用,Android系统服务 —— WMS
  2. tf神经网络模型预测泰坦尼克号生还
  3. Spring Cloud (Eureka,Feign,Hystrix整合)
  4. Symbol - 听说用了这个方法就能创建出相同的Symbol值
  5. Line 14: Char 23: runtime error: signed integer overflow: 746384741 * 10 cannot be represented
  6. linux编译cu文件,Linux编译安装RTL8192CU芯片驱动
  7. html5 bdi 不起作用,html bdi标签的使用详解
  8. 阿里云天池携手产学研心血管专家,共话心血管AI发展
  9. mumu按键精灵_什么安卓模拟器可实现操作录制?MuMu模拟器成为你的按键精灵_MuMu安卓模拟器/MuMu手游助手...
  10. Proof Compression