查看: 2049|回复: 1

关于在osgEarth上创建粒子效果不正常问题

[复制链接]

该用户从未签到

发表于 2015-1-16 18:08:54 | 显示全部楼层 |阅读模式
我在osg中做了一个喷泉效果,如图1,状态正常,当我在地球表面获得一个世界坐标以后(坐标值:osg::Vec3d(-1460944.73106, 5518487.81601, 2839320.897);)出现了如图2的失真现象,希望各位大神帮帮忙,代码:

  1. osg::Vec3d worldPos = osg::Vec3d(-1460944.73106, 5518487.81601, 2839320.897);
  2.         osg::Vec3d offset = worldPos;
  3.         offset.normalize();
  4.         worldPos += offset*20;
  5.         osg::Vec3d spherePos = osg::Vec3d(-1460948.82485, 5518482.83934, 2839320.358);
  6.         osg::Group* fountainNode = new osg::Group;
  7.         osg::ref_ptr<osgParticle::ParticleSystem> parSystem = new osgParticle::ParticleSystem;
  8.         parSystem->setDefaultAttributesUsingShaders("Images/smoke.rgb", true, 0);
  9.         parSystem->getDefaultParticleTemplate().setLifeTime(5.0f);
  10.         parSystem->getDefaultParticleTemplate().setShape(osgParticle::Particle::POINT);
  11.         parSystem->setVisibilityDistance(-1.0f);
  12.         osg::StateSet* stateset = parSystem->getOrCreateStateSet();
  13.         stateset->setAttribute(new osg::Point(3));
  14.         stateset->setTextureAttributeAndModes(0, new osg::PointSprite, osg::StateAttribute::ON);

  15.         osg::ref_ptr<osgParticle::RandomRateCounter> counter = new osgParticle::RandomRateCounter;
  16.         counter->setRateRange(15000, 20000);
  17.        
  18.         //重力模拟对象;
  19.         osg::ref_ptr<osgParticle::AccelOperator> accelOperator = new osgParticle::AccelOperator();
  20.         osg::Vec3d asoff = offset*-50;
  21.         accelOperator->setAcceleration(asoff);

  22.         //阻尼运动模拟;
  23.         osg::ref_ptr<osgParticle::DampingOperator> dampingOperator = new osgParticle::DampingOperator;
  24.         dampingOperator->setDamping(0.9f);

  25.         //跳跃模拟;
  26.         osg::ref_ptr<osgParticle::BounceOperator> bounceOperator = new osgParticle::BounceOperator;
  27.         bounceOperator->setFriction(-0.05);
  28.         bounceOperator->setResilience(0.35);
  29.         bounceOperator->addDiskDomain(worldPos-offset*2, offset, 6.0);
  30.         //bounceOperator->addPlaneDomain(osg::Plane(worldPos, 6.0));

  31.         //水槽模拟;
  32.         osg::ref_ptr<osgParticle::SinkOperator> sinkOperator = new osgParticle::SinkOperator;
  33.         sinkOperator->setSinkStrategy(osgParticle::SinkOperator::SINK_OUTSIDE);
  34.         sinkOperator->addSphereDomain(worldPos, 5.5);

  35.         //标准编程对象模块;
  36.         osg::ref_ptr<osgParticle::ModularProgram> program = new osgParticle::ModularProgram;
  37.         program->setParticleSystem(parSystem);
  38.         program->addOperator(accelOperator);
  39.         program->addOperator(dampingOperator);
  40.         //program->addOperator(bounceOperator);
  41.         program->addOperator(sinkOperator);

  42.         osg::ref_ptr<osgParticle::SectorPlacer> placer = new osgParticle::SectorPlacer;
  43.         placer->setCenter(worldPos);

  44.         osg::ref_ptr<osgParticle::RadialShooter> shooter = NULL;
  45.        
  46.         //发射器模块;
  47.         osg::ref_ptr<osgParticle::ModularEmitter> emitter = new osgParticle::ModularEmitter;
  48.         emitter->setParticleSystem(parSystem);
  49.         emitter->setCounter(counter);
  50.         emitter->setPlacer(placer);
  51.         shooter = dynamic_cast<osgParticle::RadialShooter*>(emitter->getShooter());
  52.         shooter->setPhiRange(0, osg::PI);
  53.         shooter->setThetaRange(0, osg::PI*2);
  54.         shooter->setInitialSpeedRange(5, 10);
  55.         if (shooter)
  56.         {
  57.                 osgParticle::rangef phiRange = shooter->getPhiRange();
  58.                 osgParticle::rangef theRange = shooter->getThetaRange();
  59.         }
  60.         osg::ref_ptr<osg::Geode> geode = new osg::Geode;
  61.         geode->addDrawable(parSystem);
  62.         osg::ref_ptr<osgParticle::ParticleSystemUpdater> parUpdater = new osgParticle::ParticleSystemUpdater;
  63.         parUpdater->addParticleSystem(parSystem);
  64.         fountainNode->addChild(emitter.get());
  65.         fountainNode->addChild(program.get());
  66.         fountainNode->addChild(geode);
  67.         fountainNode->addChild(parUpdater);
复制代码

图1

图1

图2

图2

该用户从未签到

发表于 2015-1-16 18:10:33 | 显示全部楼层
心魔还需心药医
您需要登录后才可以回帖 登录 | 注册

本版积分规则

OSG中国官方论坛-有您OSG在中国才更好

网站简介:osgChina是国内首个三维相关技术开源社区,旨在为国内更多的技术开发人员提供最前沿的技术资讯,为更多的三维从业者提供一个学习、交流的技术平台。

联系我们

  • 工作时间:09:00--18:00
  • 反馈邮箱:1315785073@qq.com
快速回复 返回顶部 返回列表