|
发表于 2013-3-14 09:50:15
|
显示全部楼层
buaahc 发表于 2013-3-13 23:46
其实最好的方法就是贴出问题代码 让大家给解决一下,你这样说 我不知道怎么判断问题所在
嗯,行上代码,还请大神指点!
class CONDUIT_DLL Conduit
{
public:
Conduit(void);
~Conduit(void);
osgParticle:articleSystem * CreateConduitScene(osg::Group* root);
float m_fTheNum;
float m_fTheSize; //单位:m
float m_fTheSpeech; //单位:米/秒
float m_fmass;// 单位:千克
float m_flifetime;//单位:s
osg::Node * CreateConduit(osg::Group * root);
osg::Vec3 m_VecPosition;
void setconduit(float speed,float size,float num,float mass,float life);
};//Conduit.h 结束
#define CONDUIT_DLL _declspec(dllexport)
#include "Conduit.h"
Conduit::Conduit(void) : m_fTheNum(800)
, m_fTheSize(0.5)
, m_fTheSpeech(1000)
,m_fmass(0.02)
,m_flifetime(5)
{
//默认位置
m_VecPosition.set (15, 64, 3) ;
}
Conduit::~Conduit(void)
{
}
osgParticle::ParticleSystem * Conduit::CreateConduitScene(osg::Group* root)
{
osgParticle::Particle ptemplate;
//生周期为 2,对于喷泉已经够了
ptemplate.setLifeTime(m_flifetime);
ptemplate.setShape(osgParticle::Particle :UAD);
//设置图形变化范围
ptemplate.setSizeRange(osgParticle::rangef(0.1f, 0.5f)); //单位:m
//设置透明度变化范围
ptemplate.setAlphaRange(osgParticle::rangef(1.0f, 0.5f));
//设置颜色范围
ptemplate.setColorRange(osgParticle::rangev4( osg::Vec4(0.7f, 1.0f, 1.0f, 1.5f),
osg::Vec4(0.8f, 0.8f, 1.0f, 0.0f)));
//设置半径
ptemplate.setRadius(m_fTheSize);
// 设置重量
ptemplate.setMass(m_fmass);
osgParticle::ParticleSystem *ps = new osgParticle::ParticleSystem;
ps->setDefaultAttributes("Images/smoke.rgb", true, true);//纹理 ,是否放射粒子,是否光照
//加入模版
ps->setDefaultParticleTemplate(ptemplate);
//建立发射器,中包含发射枪,数目及位置设定
osgParticle::ModularEmitter *emitter = new osgParticle::ModularEmitter;
//加入模版及总属性
emitter->setParticleSystem(ps);
//数目变化
osgParticle::RandomRateCounter *counter = new osgParticle::RandomRateCounter;
//数目变化,当前场景中的粒子数目变化范围
counter->setRateRange(m_fTheNum, m_fTheNum); // 生成 m_fTheNum 到 m_fTheNum 个粒子每秒
//加入到发射器中
emitter->setCounter(counter);
//设置位置
osgParticle::PointPlacer *placer = new osgParticle::PointPlacer;
placer->setCenter(m_VecPosition);
//加入到发射器中
emitter->setPlacer(placer);
//设置发射枪,可以设置初速度等
osgParticle::RadialShooter *shooter = new osgParticle::RadialShooter;
//设置速度范围
shooter->setInitialSpeedRange(m_fTheSpeech, 0);
emitter->setShooter(shooter);
root->addChild(emitter);
//设置影响操作,
osgParticle::ModularProgram *program = new osgParticle::ModularProgram;
program->setParticleSystem(ps);
//速度操作
osgParticle::AccelOperator *op1 = new osgParticle::AccelOperator;
op1->setToGravity();
program->addOperator(op1);
osgParticle::FluidFrictionOperator *op3 = new osgParticle::FluidFrictionOperator;
op3->setFluidToAir();
program->addOperator(op3); //空气阻力
root->addChild(program);
osg::Geode *geode = new osg::Geode;
geode->addDrawable(ps);
root->addChild(geode);
return ps;
}
osg::Node * Conduit::CreateConduit(osg::Group * root)
{
osgParticle::ParticleSystem *ps2 = CreateConduitScene(root);
osgParticle::ParticleSystem *ps3 = CreateConduitScene(root);
osgParticle::ParticleSystemUpdater *psu = new osgParticle::ParticleSystemUpdater;
psu->addParticleSystem(ps2);
psu->addParticleSystem(ps3);
return psu ;
}
void Conduit::setconduit (float speed,float size,float num,float mass,float life)
{
m_fTheSpeech=speed;
m_fTheNum=num;
m_fTheSize=size;
m_fmass=mass;
m_flifetime=life;
}
//Conduit.cpp 结束
int main(int, char**)
{
float speed=1050,size=0.06,num=700,positionx=0;
osg::ref_ptr<osgViewer::Viewer>viewer = new osgViewer::Viewer ();
osg::Group * node = new osg::Group ;
//在此处加入喷泉
Conduit od[3] ;
for(int i=0;i<3;i++)
{
od.setconduit (speed,size,num,0.08f,3.0f);
od.m_VecPosition .set (positionx, 0, 0) ;
node ->addChild (od.CreateConduit (node)) ;
speed+=100;
num+=100;
positionx+=1;
}
viewer->setSceneData(node);
viewer->realize();
viewer->run ();
return 0;
} 谢谢! |
|