On Tue, May 20, 2008 at 8:18 PM, Robert Osfield <[EMAIL PROTECTED]> wrote:
> > The intention of this code is that with defaults things would work as > before so if > things aren't then its a bug on the OSG side. I guess there could be > an issue on your side w.r.t > assumptions of how things work, however, since I don't know anything about > your > code save for it now being broken I can't really provide much guidance. > > > Hi Robert, After further investigations, I've made a test program that reproduce the "bug" in my application. The same code with the last changes on ParticleSystem reverted works fine in all cases. To make it flicker, just uncomment the line 117 (and don't forget to press space to center the view on the object). Any idea on what I am doing wrong or where to investigate on ParticleSystem to make it work like before ? Thanks ! -- Serge Lages http://www.tharsis-software.com
#include <osg/Notify>
#include <osg/Geode>
#include <osg/PolygonOffset>
#include <osg/Geometry>
#include <osg/BlendFunc>
#include <osg/MatrixTransform>
#include <osg/PositionAttitudeTransform>
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgDB/ReadFile>
#include <osgDB/Registry>
#include <osgGA/TrackballManipulator>
#include <osgParticle/ParticleSystemUpdater>
#include <osgParticle/ParticleSystem>
#include <osgParticle/ModularEmitter>
#include <osgParticle/FireEffect>
#include <osgParticle/FluidProgram>
#include <osgParticle/ParticleSystemUpdater>
osg::Geode *createQuad(const osg::Vec2 &corner, float width, float height, osg::Image *image)
{
// Geometry
osg::Geode *geode = new osg::Geode();
osg::Geometry *geom = new osg::Geometry();
osg::Vec3Array *coords = new osg::Vec3Array(4);
(*coords)[0] = osg::Vec3(corner.x(), corner.y(), 0);
(*coords)[1] = osg::Vec3(corner.x() + width, corner.y(), 0);
(*coords)[2] = osg::Vec3(corner.x() + width, corner.y() + height, 0);
(*coords)[3] = osg::Vec3(corner.x(), corner.y() + height, 0);
geom->setVertexArray(coords);
// Normal
osg::Vec3Array *norms = new osg::Vec3Array(1);
(*norms)[0] = osg::Vec3(width, 0, 0) ^ osg::Vec3(0, 0, height);
(*norms)[0].normalize();
geom->setNormalArray(norms);
geom->setNormalBinding(osg::Geometry::BIND_OVERALL);
// Texture coords
osg::Vec2Array *tcoords = new osg::Vec2Array(4);
(*tcoords)[0].set(0.0f,0.0f);
(*tcoords)[1].set(1.0f,0.0f);
(*tcoords)[2].set(1.0f,1.0f);
(*tcoords)[3].set(0.0f,1.0f);
geom->setTexCoordArray(0,tcoords);
geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 0, 4));
// Color
osg::Vec4Array *colors = new osg::Vec4Array(1);
(*colors)[0] = osg::Vec4(1, 1, 1, 1);
geom->setColorArray(colors);
geom->setColorBinding(osg::Geometry::BIND_OVERALL);
// Texture
if (image)
{
osg::StateSet *stateset = new osg::StateSet();
osg::Texture2D *texture = new osg::Texture2D();
osg::BlendFunc *blendFunc = new osg::BlendFunc();
texture->setImage(image);
texture->setUnRefImageDataAfterApply(true);
texture->setInternalFormatMode(osg::Texture::USE_S3TC_DXT5_COMPRESSION);
stateset->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON);
blendFunc->setSource(osg::BlendFunc::SRC_ALPHA);
blendFunc->setDestination(osg::BlendFunc::ONE_MINUS_SRC_ALPHA);
stateset->setAttributeAndModes(blendFunc, osg::StateAttribute::ON);
geode->setStateSet(stateset);
}
// Geode
geode->addDrawable(geom);
return (geode);
}
int main(int ac, char **av)
{
osgViewer::Viewer viewer;
osg::PositionAttitudeTransform *root = new osg::PositionAttitudeTransform();
osg::PositionAttitudeTransform *group = new osg::PositionAttitudeTransform();
osg::PositionAttitudeTransform *pat = new osg::PositionAttitudeTransform();
osgParticle::ModularEmitter *emitter = new osgParticle::ModularEmitter();
osgParticle::ParticleSystem *ps = new osgParticle::ParticleSystem();
osgParticle::ParticleSystemUpdater *psu = new osgParticle::ParticleSystemUpdater();
osg::Geode *geode = new osg::Geode();
osgParticle::RandomRateCounter *rrc = static_cast<osgParticle::RandomRateCounter *>(emitter->getCounter());
osgParticle::RadialShooter *rs = static_cast<osgParticle::RadialShooter *>(emitter->getShooter());
emitter->setParticleSystem(ps);
psu->addParticleSystem(ps);
geode->addDrawable(ps);
ps->setDefaultAttributes("cloud1.png", true, true);
ps->getDefaultParticleTemplate().setSizeRange(osgParticle::rangef(0.05, 0.7));
ps->getDefaultParticleTemplate().setLifeTime(4);
ps->getDefaultParticleTemplate().setColorRange(osgParticle::rangev4(osg::Vec4(1, 1, 1, 1), osg::Vec4(1, 1, 1, 0)));
ps->getDefaultParticleTemplate().setAlphaRange(osgParticle::rangef(1, 0));
rrc->setRateRange(100, 110);
rs->setInitialRotationalSpeedRange(osg::Vec3(0,3,0), osg::Vec3(0,0,0));
rs->setPhiRange(0, 2 * osg::PI);
rs->setThetaRange(-(10.0f * 0.5f * osg::PI / 180.0f), (10.0f * 0.5f * osg::PI / 180.0f));
rs->setInitialSpeedRange(100, 50);
pat->setScale(osg::Vec3d(0.00540154, 0.00540154, 0.00540154));
pat->setAttitude(osg::Quat(osg::inDegrees(90.0f), osg::Vec3(0, 1, 0)));
// Uncomment to get it flicker
//group->setPosition(osg::Vec3(-13780.700760771135, -10472.028869998918, 1587.4449121964917));
pat->addChild(emitter);
group->addChild(createQuad(osg::Vec2(-2, -2), 4, 4, NULL));
group->addChild(pat);
root->addChild(geode);
root->addChild(psu);
root->addChild(group);
viewer.getCamera()->setProjectionMatrixAsPerspective(30, 1.25, 0.01, 10000);
viewer.getCamera()->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
viewer.setSceneData(root);
viewer.setCameraManipulator(new osgGA::TrackballManipulator());
viewer.setUpViewInWindow(100, 100, 800, 600);
viewer.run();
return (0);
}<<attachment: cloud1.png>>
_______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

