Hi, I have question about osg.

I make particls as it made it examples, then use MatrixTransform, then attach 
emitter to
MatrixTransform ( MyMatrixTrans->addChild(emitter); ). After that I add 
MatrixTransform to
scene group ( root->addChild(MyMatrixTrans); ). But when I move/rotate 
MyMatrixTrans,
particles moves incorrect (position of MyMatrixTrans and emitter doesn't match).

In the Internet I found this:
Particle system looks strange when I position them in my scene
You are probably rotating both the particle systems and the particle emitters. 
The tranform above the particle system(s) should match your world's (absolute) 
coordinate frame, or the reference frame that "contains" the particles (for 
example, an airplane or a car).
To transform a particle system inside this reference frame you should transform 
only the emitters, not the ParticleSystem drawables. If you apply a transform 
above "fountain.osg" you actually apply a translation/rotation to both emitters 
and particle systems;
To get a correct behavior you should traverse the scene graph and avoid 
applying the transform to any geodes containing ParticleSystem drawables

How can I do this in practice?

[code]
class BaseParticle
{
public:
osgParticle::Particle *ptemplate;
osgParticle::ParticleSystem *ps;
osgParticle::ModularEmitter *emitter;
osgParticle::RandomRateCounter *rrc;
osgParticle::ParticleSystemUpdater *psu;
//созданные обертки (для возможности работать с текстом командами типа 
RSetPosition..)
osg::MatrixTransform* particleMatrix;
};

bool InterfaceForParticle::AddParticle(std::string Name)
{
//+проверка на совпадение имен с уже имеющимися
if (particles.count(Name)!=0)
{
std::cout << "Warning: Particle '" << Name << "' already exsist!" << std::endl;
return false;
}
particles[Name] = new BaseParticle;

particles[Name]->particleMatrix = new osg::MatrixTransform();
particles[Name]->particleMatrix->setName (Name);

particles[Name]->ptemplate = new osgParticle::Particle;
particles[Name]->ptemplate->setLifeTime(3); // 3 seconds of life
particles[Name]->ptemplate->setSizeRange(osgParticle::rangef(0.75f, 3.0f));
particles[Name]->ptemplate->setAlphaRange(osgParticle::rangef(0.0f, 1.5f));
particles[Name]->ptemplate->setColorRange(osgParticle::rangev4(
osg::Vec4(1, 0.5f, 0.3f, 1.5f),
osg::Vec4(0, 0.0f, 0.0f, 0.0f)));
// these are physical properties of the particle
particles[Name]->ptemplate->setRadius(0.05f); // 5 cm wide particles
particles[Name]->ptemplate->setMass(0.05f); // 50 g heavy
//FONTAN->setPosition (osg::Vec3(10, 10, 10));
//particles[Name]->ptemplate->setAngle (osg::Vec3(1,1,1));

particles[Name]->ps = new osgParticle::ParticleSystem;
//particles[Name]->ps->setDefaultAttributes("", true, false);
particles[Name]->ps->setDefaultAttributes("", false, 
false);//D:/DEVELOP/OSG/OpenSceneGraph-2.6.0/bin/Images/smoke.rgb

// assign the particle template to the system.
particles[Name]->ps->setDefaultParticleTemplate(*particles[Name]->ptemplate);

particles[Name]->emitter = new osgParticle::ModularEmitter;
particles[Name]->emitter->setParticleSystem(particles[Name]->ps);
particles[Name]->rrc = static_cast<osgParticle::RandomRateCounter 
*>(particles[Name]->emitter->getCounter());
particles[Name]->rrc->setRateRange(20, 30); // generate 20 to 30 particles per 
second
particles[Name]->particleMatrix->addChild(particles[Name]->emitter);
osg::Geode *geode = new osg::Geode;
geode->addDrawable(particles[Name]->ps);
particles[Name]->particleMatrix->addChild(geode);
particles[Name]->psu = new osgParticle::ParticleSystemUpdater;
particles[Name]->psu->addParticleSystem(particles[Name]->ps);
particles[Name]->particleMatrix->addChild(particles[Name]->psu);
root->addChild(particles[Name]->particleMatrix);
return true;
}
[/code]

osg 2.6.x, 2.7.x; MSVS2009 
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to