|
我在osg中做了一个喷泉效果,如图1,状态正常,当我在地球表面获得一个世界坐标以后(坐标值:osg::Vec3d(-1460944.73106, 5518487.81601, 2839320.897);)出现了如图2的失真现象,希望各位大神帮帮忙,代码:
- osg::Vec3d worldPos = osg::Vec3d(-1460944.73106, 5518487.81601, 2839320.897);
- osg::Vec3d offset = worldPos;
- offset.normalize();
- worldPos += offset*20;
- osg::Vec3d spherePos = osg::Vec3d(-1460948.82485, 5518482.83934, 2839320.358);
- osg::Group* fountainNode = new osg::Group;
- osg::ref_ptr<osgParticle::ParticleSystem> parSystem = new osgParticle::ParticleSystem;
- parSystem->setDefaultAttributesUsingShaders("Images/smoke.rgb", true, 0);
- parSystem->getDefaultParticleTemplate().setLifeTime(5.0f);
- parSystem->getDefaultParticleTemplate().setShape(osgParticle::Particle::POINT);
- parSystem->setVisibilityDistance(-1.0f);
- osg::StateSet* stateset = parSystem->getOrCreateStateSet();
- stateset->setAttribute(new osg::Point(3));
- stateset->setTextureAttributeAndModes(0, new osg::PointSprite, osg::StateAttribute::ON);
- osg::ref_ptr<osgParticle::RandomRateCounter> counter = new osgParticle::RandomRateCounter;
- counter->setRateRange(15000, 20000);
-
- //重力模拟对象;
- osg::ref_ptr<osgParticle::AccelOperator> accelOperator = new osgParticle::AccelOperator();
- osg::Vec3d asoff = offset*-50;
- accelOperator->setAcceleration(asoff);
- //阻尼运动模拟;
- osg::ref_ptr<osgParticle::DampingOperator> dampingOperator = new osgParticle::DampingOperator;
- dampingOperator->setDamping(0.9f);
- //跳跃模拟;
- osg::ref_ptr<osgParticle::BounceOperator> bounceOperator = new osgParticle::BounceOperator;
- bounceOperator->setFriction(-0.05);
- bounceOperator->setResilience(0.35);
- bounceOperator->addDiskDomain(worldPos-offset*2, offset, 6.0);
- //bounceOperator->addPlaneDomain(osg::Plane(worldPos, 6.0));
- //水槽模拟;
- osg::ref_ptr<osgParticle::SinkOperator> sinkOperator = new osgParticle::SinkOperator;
- sinkOperator->setSinkStrategy(osgParticle::SinkOperator::SINK_OUTSIDE);
- sinkOperator->addSphereDomain(worldPos, 5.5);
- //标准编程对象模块;
- osg::ref_ptr<osgParticle::ModularProgram> program = new osgParticle::ModularProgram;
- program->setParticleSystem(parSystem);
- program->addOperator(accelOperator);
- program->addOperator(dampingOperator);
- //program->addOperator(bounceOperator);
- program->addOperator(sinkOperator);
- osg::ref_ptr<osgParticle::SectorPlacer> placer = new osgParticle::SectorPlacer;
- placer->setCenter(worldPos);
- osg::ref_ptr<osgParticle::RadialShooter> shooter = NULL;
-
- //发射器模块;
- osg::ref_ptr<osgParticle::ModularEmitter> emitter = new osgParticle::ModularEmitter;
- emitter->setParticleSystem(parSystem);
- emitter->setCounter(counter);
- emitter->setPlacer(placer);
- shooter = dynamic_cast<osgParticle::RadialShooter*>(emitter->getShooter());
- shooter->setPhiRange(0, osg::PI);
- shooter->setThetaRange(0, osg::PI*2);
- shooter->setInitialSpeedRange(5, 10);
- if (shooter)
- {
- osgParticle::rangef phiRange = shooter->getPhiRange();
- osgParticle::rangef theRange = shooter->getThetaRange();
- }
- osg::ref_ptr<osg::Geode> geode = new osg::Geode;
- geode->addDrawable(parSystem);
- osg::ref_ptr<osgParticle::ParticleSystemUpdater> parUpdater = new osgParticle::ParticleSystemUpdater;
- parUpdater->addParticleSystem(parSystem);
- fountainNode->addChild(emitter.get());
- fountainNode->addChild(program.get());
- fountainNode->addChild(geode);
- fountainNode->addChild(parUpdater);
复制代码 |
-
图1
-
图2
|