osgParticle.AccelOperator是一个加速度操作器,用于给粒子添加加速度。根据粒子的年龄(即存在的时间),该操作器可以按照一定的规则增加粒子的加速度。例如,可以让粒子在刚出现时加速,然后逐渐减速,以模拟抛物线的运动轨迹。
osgParticle.AccelOperator是osgParticle.Operator的一个具体子类,因此使用方法类似。需要调用setToParticle函数将其绑定到一个粒子发射器上,然后将其添加到osgParticle.Emitter或osgParticle.ParticleSystem中,即可对粒子进行加速度操作。
osgParticle.AccelOperator提供了三种不同的加速度模型:线性加速度、二次加速度和阻尼加速度。可以通过setAcceleration函数设置所需的模型。以下是三种模型的示例:
osg::ref_ptr<osgParticle::AccelOperator> accel = new osgParticle::AccelOperator();
osg::ref_ptr<osgParticle::LinearInterpolator> linear = new osgParticle::LinearInterpolator(0.0f, osg::Vec3(0.0f,0.0f,0.0f), 1.0f, osg::Vec3(0.0f,0.0f,5.0f));
accel->setAcceleration(linear.get());
osg::ref_ptr<osgParticle::AccelOperator> accel = new osgParticle::AccelOperator();
osg::ref_ptr<osgParticle::RadialShooter> radial = new osgParticle::RadialShooter(0.0f, osg::Vec3(0.0f,0.0f,0.0f), osg::Vec3(0.0f,0.0f,1.0f), 0.0f, 10.0f);
osg::ref_ptr<osgParticle::Interpolator> interpolator = osg::ref_ptr<osgParticle::Interpolator>(new osgParticle::RadialShooterDebrisInterpolator(radial.get()));
osg::ref_ptr<osgParticle::AccelOperator> accel = new osgParticle::AccelOperator();
osg::ref_ptr<osgParticle::Emitter> emitter = new osgParticle::Emitter();
emitter->setInterpolator(interpolator.get());
emitter->setParticleSystem(particleSystem.get());
accel->setAcceleration(new osgParticle::RadialAccelOperator(0.0f, 100.0f));
emitter->addOperator(accel.get());
osg::ref_ptr<osgParticle::AccelOperator> accel = new osgParticle::AccelOperator();
accel->setAcceleration(new osgParticle::DampingOperator(0.05f));
以下是osgParticle.AccelOperator中定义的类型:
Model
:加速度模型。它是一个抽象接口,有三个子类LinearInterpolator、RadialAccelOperator和DampingOperator实现了这个接口,分别对应线性加速度、二次加速度和阻尼加速度模型。以下是osgParticle.AccelOperator中比较重要或常用的函数:
void setRadiusRange(float minimum,float maximum)
:设置随机半径范围。void setToParticle(osgParticle::Particle *particle,float dt)
:将操作器绑定到指定的粒子上。void operate(osgParticle::Particle *P,float dt)
:对指定的粒子进行加速度操作。