|
我的程序是基于osgearth开发的场景,包括地形和影像数据。我参考arrary的osgRecipes工程中的osgspark的demo,将雨滴粒子添加到场景,但是在地形场景中看不到粒子效果。请教这是什么原因?
我的代码如下:
//创建spark节点
osg::ref_ptr<osg::Node> osgspark::createSparkNode(const osg::BoundingBox& bbox)
{
SPK::randomSeed = static_cast<unsigned int>( time(NULL) );
SPK::System::setClampStep( true, 0.1f );
SPK::System::useAdaptiveStep( 0.001f, 0.01f );
osg::ref_ptr<SparkDrawable> spark = new SparkDrawable;
switch ( m_sparkType )
{
case 1: // Explosion
spark->setBaseSystemCreator( &createExplosion );
spark->addParticleSystem();
spark->setSortParticles( true );
spark->addImage( "explosion", osgDB::readImageFile(m_strexplosion), GL_ALPHA );
spark->addImage( "flash", osgDB::readImageFile(m_strflash), GL_RGB );
spark->addImage( "spark1", osgDB::readImageFile(m_strspark1), GL_RGB );
spark->addImage( "spark2", osgDB::readImageFile(m_strspark2), GL_ALPHA );
spark->addImage( "wave", osgDB::readImageFile(m_strwave), GL_RGBA );
break;
case 2: // Fire
spark->setBaseSystemCreator( &createFire );
spark->addParticleSystem();
spark->addImage( "fire", osgDB::readImageFile(m_strfire), GL_ALPHA );
spark->addImage( "explosion", osgDB::readImageFile(m_strexplosion), GL_ALPHA );
break;
case 3: // Rain
spark->setBaseSystemCreator( &createRain, true ); // Must use the proto type directly
spark->addImage( "waterdrops", osgDB::readImageFile(m_strwaterdrops), GL_ALPHA );
break;
case 4: // Smoke
spark->setBaseSystemCreator( &createSmoke );
spark->addParticleSystem();
spark->addImage( "smoke", osgDB::readImageFile(m_strsmoke), GL_RGBA );
//trackingModel = true;
break;
default: // Simple
spark->setBaseSystemCreator( &createSimpleSystem );
spark->addParticleSystem();
spark->addImage( "flare", osgDB::readImageFile(m_strflare), GL_ALPHA );
break;
}
sparkhander = new SparkUpdatingHandler;
sparkhander->addSpark( spark.get() );
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
geode->addDrawable( spark.get() );
geode->getOrCreateStateSet()->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );
geode->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
geode->getOrCreateStateSet()->setRenderBinDetails(10,"DepthSortedBin");
return geode.get();
}
//添加spark节点
osgspark* pspark = new osgspark(SPARK_RAIN);
//Explosion
pspark->m_strexplosion = "explosion.bmp";
pspark->m_strflash = "flash.bmp";
pspark->m_strspark1 = "data\\spark1.bmp";
pspark->m_strspark2 = "point.bmp";
pspark->m_strwave = "wave.bmp";
//Fire
pspark->m_strfire = "fire2.bmp";
//Rain
pspark->m_strwaterdrops = "waterdrops.bmp";
//Smoke
pspark->m_strsmoke = "smoke.png";
//Simple
pspark->m_strflare = "flare.bmp";
//get boundingbox
osg::ComputeBoundsVisitor boundsVistor ;
root->accept(boundsVistor);
osg::BoundingBox bbox = boundsVistor.getBoundingBox();
root->getBound();
osg::ref_ptr<osg::Node> pNode = pspark->createSparkNode(bbox);
sceneview->addEventHandler( pspark->sparkhander.get() );
osg::ref_ptr<osg::MatrixTransform> geode_matrix = new osg::MatrixTransform;
geode_matrix->addChild(pNode.get());
geode_matrix->setMatrix(osg::Matrix::scale(bbox.radius()/2.0,bbox.radius()/2.0,bbox.radius()/2.0)*osg::Matrix::translate(bbox.center()));
root->addChild(geode_matrix.get());
|
|