int main(int argc, char **argv)
{
    preloadSharedObject("OSGImageFileIO");
    // OSG init
    osgInit(argc,argv);

    {
        // Set up Window
        WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
        TutorialWindow->initWindow();

        // Create the SimpleSceneManager helper
        SimpleSceneManager sceneManager;
        TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
        TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));

        // Tell the Manager what to manage
        sceneManager.setWindow(TutorialWindow);

        //Attach to events
        TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager));
        TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager));
        TutorialWindow->connectMouseMoved(boost::bind(mouseMoved, _1, &sceneManager));
        TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager));
        TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager));

        // Creating the Particle System Material
        // Here, the image is loaded.  The entire image sequence is conatined in one image,
        // which reduces texture memory overhead and runs faster.
        TextureObjChunkRefPtr QuadTextureChunk = TextureObjChunk::create();
        ImageRefPtr LoadedImage = ImageFileHandler::the()->read("Data/SpriteExplode.png");    
        QuadTextureChunk->setImage(LoadedImage);

        TextureEnvChunkRefPtr QuadTextureEnvChunk = TextureEnvChunk::create();
        QuadTextureEnvChunk->setEnvMode(GL_MODULATE);

        BlendChunkRefPtr PSBlendChunk = BlendChunk::create();
        PSBlendChunk->setSrcFactor(GL_SRC_ALPHA);
        PSBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);

        MaterialChunkRefPtr PSMaterialChunk = MaterialChunk::create();
        PSMaterialChunk->setAmbient(Color4f(0.3f,0.0f,0.0f,1.0f));
        PSMaterialChunk->setDiffuse(Color4f(0.7f,0.0f,0.0f,1.0f));
        PSMaterialChunk->setSpecular(Color4f(0.9f,0.0f,0.0f,1.0f));
        PSMaterialChunk->setColorMaterial(GL_AMBIENT_AND_DIFFUSE);

        ChunkMaterialRefPtr PSMaterial = ChunkMaterial::create();
        PSMaterial->addChunk(QuadTextureChunk);
        PSMaterial->addChunk(QuadTextureEnvChunk);
        PSMaterial->addChunk(PSMaterialChunk);
        PSMaterial->addChunk(PSBlendChunk);

        //Particle System
        ParticleSystemRecPtr ExampleParticleSystem = ParticleSystem::create();
        ExampleParticleSystem->attachUpdateProducer(TutorialWindow);

        //Age Particle Function.  Controls which image is shown when, based on the age of a particle.
        AgeParticleFunctionRecPtr AgeFunc = AgeParticleFunction::create();
        AgeFunc->setSequenceTime(0.1f); // image changes every 0.1 seconds.
        AgeFunc->setSequenceOrder(AgeParticleFunction::CUSTOM); // using the custom sequence below.
        /*
           Here, a custom sequence for the image ordering is assembled.  The image sequence will be shown in 
           the order specified here.  Once the end of the sequence is reached, the sequence repeats.
           */
        AgeFunc->editMFCustomSequence()->push_back(0);
        AgeFunc->editMFCustomSequence()->push_back(1);
        AgeFunc->editMFCustomSequence()->push_back(2);
        AgeFunc->editMFCustomSequence()->push_back(3);
        AgeFunc->editMFCustomSequence()->push_back(4);
        AgeFunc->editMFCustomSequence()->push_back(5);
        AgeFunc->editMFCustomSequence()->push_back(4);
        AgeFunc->editMFCustomSequence()->push_back(3);
        AgeFunc->editMFCustomSequence()->push_back(2);
        AgeFunc->editMFCustomSequence()->push_back(1);

        //Particle System Drawer - 
        QuadSequenceParticleSystemDrawerRecPtr ExampleParticleSystemDrawer = QuadSequenceParticleSystemDrawer::create();
        // image dimensions (in pixels) are required if there is a border on the images.
        ExampleParticleSystemDrawer->setImageDimensions(Vec2us(780,520));
        // The "dimensions" of the sequence contained in the image.  For this image,
        // there are 3 images in the "x" direction, and two in the "y" direction, for a 
        // total of 6.
        ExampleParticleSystemDrawer->setSequenceDimensions(Vec2b(3,2));
        // width of the border on each side of the image, in pixels.
        ExampleParticleSystemDrawer->setBorderOffsets(Vec2b(0,0));
        // this is the age function we just created above.
        ExampleParticleSystemDrawer->setSequenceFunction(AgeFunc);

        RateParticleGeneratorRecPtr ExampleParticleGenerator = RateParticleGenerator::create();
        //Attach the function objects to the Generator
        ExampleParticleGenerator->setPositionDistribution(createPositionDistribution());
        ExampleParticleGenerator->setLifespanDistribution(createLifespanDistribution());
        ExampleParticleGenerator->setVelocityDistribution(createVelocityDistribution());
        ExampleParticleGenerator->setAccelerationDistribution(createAccelerationDistribution());
        ExampleParticleGenerator->setSizeDistribution(createSizeDistribution());
        ExampleParticleGenerator->setGenerationRate(40.0f);

        //Particle System Node
        ParticleSystemCoreRefPtr ParticleNodeCore = ParticleSystemCore::create();
        ParticleNodeCore->setSystem(ExampleParticleSystem);
        ParticleNodeCore->setDrawer(ExampleParticleSystemDrawer);
        ParticleNodeCore->setMaterial(PSMaterial);
        ParticleNodeCore->setSortingMode(ParticleSystemCore::BACK_TO_FRONT);

        NodeRefPtr ParticleNode = Node::create();
        ParticleNode->setCore(ParticleNodeCore);

        ExampleParticleSystem->addParticle(Pnt3f(10.0,0.0,0.0),
                                           Vec3f(0.0,1.0,0.0),
                                           Color4f(1.0,1.0,1.0,1.0),
                                           Vec3f(1.0,1.0,1.0),
                                           0.01,
                                           Vec3f(0.0,0.0,0.0),
                                           Vec3f(0.0,0.0,0.0));

        ExampleParticleSystem->addParticle(Pnt3f(-10.0,0.0,0.0),
                                           Vec3f(0.0,1.0,0.0),
                                           Color4f(1.0,1.0,1.0,1.0),
                                           Vec3f(1.0,1.0,1.0),
                                           0.01,
                                           Vec3f(0.0,0.0,0.0),
                                           Vec3f(0.0,0.0,0.0));

        ExampleParticleSystem->pushToGenerators(ExampleParticleGenerator);
        // Make Main Scene Node and add the Torus
        NodeRefPtr scene = makeCoredNode<Group>();
        scene->addChild(ParticleNode);

        TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1,
                                                    &sceneManager,
                                                    AgeFunc.get()));

        sceneManager.setRoot(scene);

        // Show the whole Scene
        sceneManager.showAll();

        //Open Window
        Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
        Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
        TutorialWindow->openWindow(WinPos,
                                   WinSize,
                                   "05a - QuadSequenceParticleDrawer");

        //Enter main Loop
        TutorialWindow->mainLoop();
    }

    osgExit();

    return 0;
}
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    {
        // Set up Window
        WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
        TutorialWindow->initWindow();

        // Create the SimpleSceneManager helper
        SimpleSceneManager sceneManager;
        TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
        TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));

        // Tell the Manager what to manage
        sceneManager.setWindow(TutorialWindow);

        //Attach to events
        TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager));
        TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager));
        TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager));
        TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager));

        //Particle System Material
        TextureObjChunkRefPtr QuadTextureChunk = TextureObjChunk::create();
        ImageRefPtr LoadedImage = ImageFileHandler::the()->read("Data/Cloud.png");    
        QuadTextureChunk->setImage(LoadedImage);


        TextureEnvChunkRefPtr QuadTextureEnvChunk = TextureEnvChunk::create();
        QuadTextureEnvChunk->setEnvMode(GL_MODULATE);

        BlendChunkRefPtr PSBlendChunk = BlendChunk::create();
        PSBlendChunk->setSrcFactor(GL_SRC_ALPHA);
        PSBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);

        MaterialChunkRefPtr PSMaterialChunk = MaterialChunk::create();
        PSMaterialChunk->setAmbient(Color4f(0.3f,0.3f,0.3f,1.0f));
        PSMaterialChunk->setDiffuse(Color4f(0.7f,0.7f,0.7f,1.0f));
        PSMaterialChunk->setSpecular(Color4f(0.9f,0.9f,0.9f,1.0f));
        PSMaterialChunk->setColorMaterial(GL_AMBIENT_AND_DIFFUSE);

        ChunkMaterialRefPtr PSMaterial = ChunkMaterial::create();
        PSMaterial->addChunk(QuadTextureChunk);
        PSMaterial->addChunk(QuadTextureEnvChunk);
        PSMaterial->addChunk(PSMaterialChunk);
        PSMaterial->addChunk(PSBlendChunk);



        //Particle System

        ParticleSystemRecPtr ExampleParticleSystem = ParticleSystem::create();
        ExampleParticleSystem->attachUpdateProducer(TutorialWindow);

        //Particle System Drawer
        QuadParticleSystemDrawerRefPtr ExampleParticleSystemDrawer = QuadParticleSystemDrawer::create();


        BurstParticleGeneratorRecPtr ExampleBurstGenerator = BurstParticleGenerator::create();
        //Attach the function objects to the Generator
        ExampleBurstGenerator->setPositionDistribution(createPositionDistribution());
        ExampleBurstGenerator->setLifespanDistribution(createLifespanDistribution());
        ExampleBurstGenerator->setBurstAmount(50.0);
        ExampleBurstGenerator->setVelocityDistribution(createVelocityDistribution());
        ExampleBurstGenerator->setAccelerationDistribution(createAccelerationDistribution());
        ExampleBurstGenerator->setSizeDistribution(createSizeDistribution());

        //Particle System Node
        ParticleSystemCoreRefPtr ParticleNodeCore = ParticleSystemCore::create();
        ParticleNodeCore->setSystem(ExampleParticleSystem);
        ParticleNodeCore->setDrawer(ExampleParticleSystemDrawer);
        ParticleNodeCore->setMaterial(PSMaterial);

        NodeRefPtr ParticleNode = Node::create();
        ParticleNode->setCore(ParticleNodeCore);

        //Ground Node
        NodeRefPtr GoundNode = makePlane(30.0,30.0,10,10);

        Matrix GroundTransformation;
        GroundTransformation.setRotate(Quaternion(Vec3f(1.0f,0.0,0.0), -3.14195f));
        TransformRefPtr GroundTransformCore = Transform::create();
        GroundTransformCore->setMatrix(GroundTransformation);

        NodeRefPtr GroundTransformNode = Node::create();
        GroundTransformNode->setCore(GroundTransformCore);
        GroundTransformNode->addChild(GoundNode);


        // Make Main Scene Node and add the Torus
        NodeRefPtr scene = Node::create();
        scene->setCore(Group::create());
        scene->addChild(ParticleNode);
        scene->addChild(GroundTransformNode);


        TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1,
                                                    &sceneManager,
                                                    ExampleParticleSystem.get(),
                                                    ExampleBurstGenerator.get(),
                                                    ExampleParticleSystemDrawer.get()));
        sceneManager.setRoot(scene);

        //Create the Documentation
        SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow);

        // Show the whole Scene
        sceneManager.showAll();


        //Open Window
        Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
        Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
        TutorialWindow->openWindow(WinPos,
                                   WinSize,
                                   "05QuadParticleDrawer");

        //Enter main Loop
        TutorialWindow->mainLoop();
    }

    osgExit();

    return 0;
}
Example #3
0
int main(int argc, char **argv)
{
    preloadSharedObject("OSGImageFileIO");
    // OSG init
    osgInit(argc,argv);

    {
        // Set up Window
        WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
        TutorialWindow->initWindow();

        // Create the SimpleSceneManager helper
        SimpleSceneManager sceneManager;
        TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
        TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));

        // Tell the Manager what to manage
        sceneManager.setWindow(TutorialWindow);

        //Attach to events
        TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager));
        TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager));
        TutorialWindow->connectMouseMoved(boost::bind(mouseMoved, _1, &sceneManager));
        TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager));
        TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager));

        // Creating the Particle System Material
        // Here, the image is loaded.  The entire image sequence is conatined in one image,
        // which reduces texture memory overhead and runs faster.
        TextureObjChunkRefPtr QuadTextureChunk = TextureObjChunk::create();
        ImageRefPtr LoadedImage = ImageFileHandler::the()->read("Data/Explosion.png");
        QuadTextureChunk->setImage(LoadedImage);

        TextureEnvChunkRefPtr QuadTextureEnvChunk = TextureEnvChunk::create();
        QuadTextureEnvChunk->setEnvMode(GL_MODULATE);

        BlendChunkRefPtr PSBlendChunk = BlendChunk::create();
        PSBlendChunk->setSrcFactor(GL_SRC_ALPHA);
        PSBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);

        MaterialChunkRefPtr PSMaterialChunk = MaterialChunk::create();
        PSMaterialChunk->setLit(false);

        ChunkMaterialRefPtr PSMaterial = ChunkMaterial::create();
        PSMaterial->addChunk(QuadTextureChunk);
        PSMaterial->addChunk(QuadTextureEnvChunk);
        PSMaterial->addChunk(PSMaterialChunk);
        PSMaterial->addChunk(PSBlendChunk);

        //Particle System
        ParticleSystemRecPtr ExplosionParticleSystem = ParticleSystem::create();
        ExplosionParticleSystem->attachUpdateProducer(TutorialWindow);

        //Age Particle Function.  Controls which image is shown when, based on the age of a particle.
        AgeParticleFunctionRecPtr AgeFunc = AgeParticleFunction::create();
        AgeFunc->setSequenceTime(0.07f); // image changes every 0.1 seconds.
        AgeFunc->setSequenceOrder(AgeParticleFunction::CUSTOM); // using the custom sequence below.
        /*
           Here, a custom sequence for the image ordering is assembled.  The image sequence will be shown in
           the order specified here.  Once the end of the sequence is reached, the sequence repeats.
           */
        UInt32 NumImages(25);
        for(UInt32 i(0) ; i<NumImages ; ++i)
        {
            AgeFunc->editMFCustomSequence()->push_back(i);
        }

        //Particle System Drawer -
        QuadSequenceParticleSystemDrawerRecPtr ExplosionParticleSystemDrawer = QuadSequenceParticleSystemDrawer::create();
        // image dimensions (in pixels) are required if there is a border on the images.
        ExplosionParticleSystemDrawer->setImageDimensions(Vec2us(320,320));
        // The "dimensions" of the sequence contained in the image.  For this image,
        // there are 3 images in the "x" direction, and two in the "y" direction, for a
        // total of 6.
        ExplosionParticleSystemDrawer->setSequenceDimensions(Vec2b(5,5));
        // width of the border on each side of the image, in pixels.
        ExplosionParticleSystemDrawer->setBorderOffsets(Vec2b(0,0));
        // this is the age function we just created above.
        ExplosionParticleSystemDrawer->setSequenceFunction(AgeFunc);

        RateParticleGeneratorRecPtr ExplosionParticleGenerator = RateParticleGenerator::create();
        //Attach the function objects to the Generator
        ExplosionParticleGenerator->setPositionDistribution(createPositionDistribution());
        ExplosionParticleGenerator->setLifespanDistribution(createLifespanDistribution());
        ExplosionParticleGenerator->setVelocityDistribution(createVelocityDistribution());
        ExplosionParticleGenerator->setAccelerationDistribution(createAccelerationDistribution());
        ExplosionParticleGenerator->setSizeDistribution(createSizeDistribution());
        ExplosionParticleGenerator->setGenerationRate(100.0f);

        //Particle System Node
        ParticleSystemCoreRefPtr ExplosionParticleCore = ParticleSystemCore::create();
        ExplosionParticleCore->setSystem(ExplosionParticleSystem);
        ExplosionParticleCore->setDrawer(ExplosionParticleSystemDrawer);
        ExplosionParticleCore->setMaterial(PSMaterial);
        ExplosionParticleCore->setSortingMode(ParticleSystemCore::BACK_TO_FRONT);

        NodeRefPtr ExplosionParticleNode = Node::create();
        ExplosionParticleNode->setCore(ExplosionParticleCore);

        ExplosionParticleSystem->addParticle(Pnt3f(10.0,0.0,0.0),
                                             Vec3f(0.0,1.0,0.0),
                                             Color4f(1.0,1.0,1.0,1.0),
                                             Vec3f(1.0,1.0,1.0),
                                             0.01,
                                             Vec3f(0.0,0.0,0.0),
                                             Vec3f(0.0,0.0,0.0));

        ExplosionParticleSystem->addParticle(Pnt3f(-10.0,0.0,0.0),
                                             Vec3f(0.0,1.0,0.0),
                                             Color4f(1.0,1.0,1.0,1.0),
                                             Vec3f(1.0,1.0,1.0),
                                             0.01,
                                             Vec3f(0.0,0.0,0.0),
                                             Vec3f(0.0,0.0,0.0));

        ExplosionParticleSystem->pushToGenerators(ExplosionParticleGenerator);

        AgeSizeParticleAffectorRecPtr ExampleAgeSizeParticleAffector = AgeSizeParticleAffector::create();

        //Age and size
        ExampleAgeSizeParticleAffector->editMFAges()->push_back(0.0);
        ExampleAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(0.2,0.2,0.2));
        ExampleAgeSizeParticleAffector->editMFAges()->push_back(1.0);
        ExampleAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(4.0,4.0,4.0));
        ExampleAgeSizeParticleAffector->editMFAges()->push_back(1.8);
        ExampleAgeSizeParticleAffector->editMFSizes()->push_back(Vec3f(2.2,2.2,0.1));

        //Age Fade Affector
        AgeFadeParticleAffectorRecPtr ExampleAgeFadeParticleAffector = AgeFadeParticleAffector::create();

        //Age and size
        ExampleAgeFadeParticleAffector->setStartAlpha(0.0f);
        ExampleAgeFadeParticleAffector->setFadeInTime(0.5f);
        ExampleAgeFadeParticleAffector->setFadeToAlpha(1.0f);
        ExampleAgeFadeParticleAffector->setFadeOutTime(0.5f);
        ExampleAgeFadeParticleAffector->setEndAlpha(0.0f);
        ExplosionParticleSystem->pushToAffectors(ExampleAgeFadeParticleAffector);

        //Smoke Particle System
        VortexParticleAffectorRecPtr SmokeVortexAffector = VortexParticleAffector::create();
        SmokeVortexAffector->setMagnitude(0.2);
        SmokeVortexAffector->setVortexAxis(Vec3f(0.0,1.0,0.0)); // field rotates around y axis
        NodeRefPtr VortexBeacon = makeCoredNode<Group>();
        SmokeVortexAffector->setBeacon(VortexBeacon); // set to 'emulate' from (0,0,0)
        SmokeVortexAffector->setMaxDistance(-1.0); // particles affected regardless of distance
        SmokeVortexAffector->setAttenuation(0.25); // strength of uniform field dimishes by dist^attenuation

        AgeFadeParticleAffectorRecPtr SmokeAgeFadeParticleAffector = AgeFadeParticleAffector::create();

        //Age and size
        SmokeAgeFadeParticleAffector->setStartAlpha(0.0f);
        SmokeAgeFadeParticleAffector->setFadeInTime(0.2f);
        SmokeAgeFadeParticleAffector->setFadeToAlpha(1.0f);
        SmokeAgeFadeParticleAffector->setFadeOutTime(3.5f);
        SmokeAgeFadeParticleAffector->setEndAlpha(0.0f);

        RateParticleGeneratorRecPtr SmokeParticleGenerator = RateParticleGenerator::create();
        SmokeParticleGenerator->setSizeDistribution(createSmokeSizeDistribution());
        SmokeParticleGenerator->setPositionDistribution(createSmokePositionDistribution());
        SmokeParticleGenerator->setLifespanDistribution(createSmokeLifespanDistribution());
        SmokeParticleGenerator->setVelocityDistribution(createSmokeVelocityDistribution());
        SmokeParticleGenerator->setColorDistribution(createSmokeColorDistribution());
        SmokeParticleGenerator->setGenerationRate(80.0f);

        ParticleSystemRecPtr SmokeParticleSystem = ParticleSystem::create();
        SmokeParticleSystem->pushToGenerators(SmokeParticleGenerator);
        SmokeParticleSystem->attachUpdateProducer(TutorialWindow);
        SmokeParticleSystem->pushToAffectors(SmokeAgeFadeParticleAffector);
        SmokeParticleSystem->pushToAffectors(SmokeVortexAffector);

        TextureObjChunkRefPtr SmokeTextureObjChunk = TextureObjChunk::create();
        ImageRefPtr SmokeImage = ImageFileHandler::the()->read("Data/Smoke.png");
        SmokeTextureObjChunk->setImage(SmokeImage);

        ChunkMaterialRefPtr SmokeMaterial = ChunkMaterial::create();
        SmokeMaterial->addChunk(SmokeTextureObjChunk);
        SmokeMaterial->addChunk(QuadTextureEnvChunk);
        SmokeMaterial->addChunk(PSMaterialChunk);
        SmokeMaterial->addChunk(PSBlendChunk);
        SmokeMaterial->setSortKey(-1.0f);

        QuadParticleSystemDrawerRecPtr SmokeParticleSystemDrawer = QuadParticleSystemDrawer::create();

        ParticleSystemCoreRefPtr SmokeParticleCore = ParticleSystemCore::create();
        SmokeParticleCore->setSystem(SmokeParticleSystem);
        SmokeParticleCore->setDrawer(SmokeParticleSystemDrawer);
        SmokeParticleCore->setMaterial(SmokeMaterial);
        SmokeParticleCore->setSortingMode(ParticleSystemCore::BACK_TO_FRONT);

        NodeRefPtr SmokeParticleNode = Node::create();
        SmokeParticleNode->setCore(SmokeParticleCore);

        // Make Main Scene Node and add the Torus
        NodeRefPtr scene = makeCoredNode<Group>();
        scene->addChild(ExplosionParticleNode);
        scene->addChild(SmokeParticleNode);
        scene->addChild(VortexBeacon);

        TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1,
                                        &sceneManager,
                                        AgeFunc.get()));

        sceneManager.setRoot(scene);

        // Show the whole Scene
        sceneManager.showAll();

        //Open Window
        Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
        Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
        TutorialWindow->openWindow(WinPos,
                                   WinSize,
                                   "06Explosion");

        //Enter main Loop
        TutorialWindow->mainLoop();
    }

    osgExit();

    return 0;
}
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    // Set up Window
    TutorialWindow = createNativeWindow();
    TutorialWindow->initWindow();

    TutorialWindow->setDisplayCallback(display);
    TutorialWindow->setReshapeCallback(reshape);

    TutorialKeyListener TheKeyListener;
    TutorialWindow->addKeyListener(&TheKeyListener);
    TutorialMouseListener TheTutorialMouseListener;
    TutorialMouseMotionListener TheTutorialMouseMotionListener;
    TutorialWindow->addMouseListener(&TheTutorialMouseListener);
    TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener);

    // Create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // Tell the Manager what to manage
    mgr->setWindow(TutorialWindow);

    //Particle System Material
    PointChunkRefPtr PSPointChunk = PointChunk::create();
    PSPointChunk->setSize(12.0f);
    PSPointChunk->setSmooth(true);
    BlendChunkRefPtr PSBlendChunk = BlendChunk::create();
    PSBlendChunk->setSrcFactor(GL_SRC_ALPHA);
    PSBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);

    MaterialChunkRefPtr PSMaterialChunkChunk = MaterialChunk::create();
    PSMaterialChunkChunk->setAmbient(Color4f(0.3f,0.3f,0.3f,1.0f));
    PSMaterialChunkChunk->setDiffuse(Color4f(0.7f,0.7f,0.7f,1.0f));
    PSMaterialChunkChunk->setSpecular(Color4f(0.9f,0.9f,0.9f,1.0f));
    PSMaterialChunkChunk->setColorMaterial(GL_AMBIENT_AND_DIFFUSE);

    ChunkMaterialRefPtr PSMaterial = ChunkMaterial::create();
    PSMaterial->addChunk(PSPointChunk);
    PSMaterial->addChunk(PSMaterialChunkChunk);
    PSMaterial->addChunk(PSBlendChunk);

    //Particle System

    ExampleParticleSystem = OSG::ParticleSystem::create();
    ExampleParticleSystem->attachUpdateListener(TutorialWindow);

    //Particle System Drawer
    PointParticleSystemDrawerRefPtr ExampleParticleSystemDrawer = OSG::PointParticleSystemDrawer::create();

    ExampleBurstGenerator = OSG::BurstParticleGenerator::create();
    //Attach the function objects to the Generator
    ExampleBurstGenerator->setPositionDistribution(createPositionDistribution());
    ExampleBurstGenerator->setLifespanDistribution(createLifespanDistribution());
    ExampleBurstGenerator->setBurstAmount(50.0);
    ExampleBurstGenerator->setVelocityDistribution(createVelocityDistribution());
    ExampleBurstGenerator->setAccelerationDistribution(createAccelerationDistribution());



    //Particle System Node
    ParticleSystemCoreRefPtr ParticleNodeCore = OSG::ParticleSystemCore::create();
    ParticleNodeCore->setSystem(ExampleParticleSystem);
    ParticleNodeCore->setDrawer(ExampleParticleSystemDrawer);
    ParticleNodeCore->setMaterial(PSMaterial);

    NodeRefPtr ParticleNode = OSG::Node::create();
    ParticleNode->setCore(ParticleNodeCore);

    // Make Main Scene Node and add the Torus
    NodeRefPtr scene = OSG::Node::create();
    scene->setCore(OSG::Group::create());
    scene->addChild(ParticleNode);

    mgr->setRoot(scene);

    // Show the whole Scene
    mgr->showAll();


    //Open Window
    Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
    Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
    TutorialWindow->openWindow(WinPos,
                               WinSize,
                               "04BurstParticleGenerator");

    //Enter main Loop
    TutorialWindow->mainLoop();

    osgExit();

    return 0;
}
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    // Set up Window
    TutorialWindow = createNativeWindow();
    TutorialWindow->initWindow();

    TutorialWindow->setDisplayCallback(display);
    TutorialWindow->setReshapeCallback(reshape);

    TutorialKeyListener TheKeyListener;
    TutorialWindow->addKeyListener(&TheKeyListener);
    TutorialMouseListener TheTutorialMouseListener;
    TutorialMouseMotionListener TheTutorialMouseMotionListener;
    TutorialWindow->addMouseListener(&TheTutorialMouseListener);
    TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener);

    // Create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // Tell the Manager what to manage
    mgr->setWindow(TutorialWindow);
	
	//Particle System Material
	LineChunkRefPtr PSLineChunk = LineChunk::create();
		PSLineChunk->setWidth(1.0f);

	BlendChunkRefPtr PSBlendChunk = BlendChunk::create();
		PSBlendChunk->setSrcFactor(GL_SRC_ALPHA);
		PSBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);

	MaterialChunkRefPtr PSMaterialChunk = MaterialChunk::create();
		PSMaterialChunk->setAmbient(Color4f(0.3f,0.3f,0.3f,1.0f));
		PSMaterialChunk->setDiffuse(Color4f(0.7f,0.7f,0.7f,1.0f));
		PSMaterialChunk->setSpecular(Color4f(0.9f,0.9f,0.9f,1.0f));
		PSMaterialChunk->setColorMaterial(GL_AMBIENT_AND_DIFFUSE);
		PSMaterialChunk->setLit(false);

	ChunkMaterialRefPtr PSMaterial = ChunkMaterial::create();
		PSMaterial->addChunk(PSLineChunk);
		PSMaterial->addChunk(PSMaterialChunk);
		PSMaterial->addChunk(PSBlendChunk);

	//Particle System
    ParticleSystemRefPtr ExampleParticleSystem = ParticleSystem::create();
    ExampleParticleSystem->attachUpdateListener(TutorialWindow);


	//Create the particles
    UInt32 NumParticlesToGenerate(2500);

	Distribution3DRefPtr PositionDistribution = createPositionDistribution();
	Distribution3DRefPtr NormalDistribution = createNormalDistribution();
	Distribution3DRefPtr ColorDistribution = createColorDistribution();
	Distribution3DRefPtr SizeDistribution = createSizeDistribution();
	Distribution1DRefPtr LifespanDistribution = createLifespanDistribution();
	Distribution3DRefPtr VelocityDistribution = createVelocityDistribution();
	Distribution3DRefPtr AccelerationDistribution = createAccelerationDistribution();

	Pnt3f PositionReturnValue;
	Vec3f NormalReturnValue = Vec3f(0.0,0.0f,1.0f);
	Color4f ColorReturnValue = Color4f(1.0,1.0f,1.0f, 1.0f);
	Vec3f SizeReturnValue;
	Time LifespanReturnValue = -1;
	Vec3f VelocityReturnValue;
	Vec3f AccelerationReturnValue;


    for(UInt32 i(0) ; i< NumParticlesToGenerate ; ++i)
    {
		if(PositionDistribution != NULL)
		{
			PositionReturnValue.setValue(PositionDistribution->generate().getValues());
		}

		
		if(ColorDistribution != NULL)
		{
            Vec3f ColorRGB = ColorDistribution->generate();
			ColorReturnValue.setValuesRGBA(ColorRGB[0],ColorRGB[1],ColorRGB[2],1.0f);
		}

		
		if(SizeDistribution != NULL)
		{
			SizeReturnValue = SizeDistribution->generate();
		}

		if(LifespanDistribution != NULL)
		{
			LifespanReturnValue = LifespanDistribution->generate();
		}
		if(VelocityDistribution != NULL)
		{
			VelocityReturnValue = VelocityDistribution->generate();
		}

		ExampleParticleSystem->addParticle(PositionReturnValue,
			NormalReturnValue,
			ColorReturnValue,
			SizeReturnValue,
			LifespanReturnValue,
			VelocityReturnValue,
			AccelerationReturnValue
			);
	
    }

	//Particle System Drawer
	LineParticleSystemDrawerRefPtr ExampleParticleSystemDrawer = LineParticleSystemDrawer::create();
		ExampleParticleSystemDrawer->setLineDirectionSource(LineParticleSystemDrawer::DIRECTION_VELOCITY);
		ExampleParticleSystemDrawer->setLineLengthSource(LineParticleSystemDrawer::LENGTH_SIZE_X);
		ExampleParticleSystemDrawer->setEndPointFading(Vec2f(0.0f,1.0f));

	//Particle System Node
    ParticleSystemCoreRefPtr ParticleNodeCore = ParticleSystemCore::create();
		ParticleNodeCore->setSystem(ExampleParticleSystem);
		ParticleNodeCore->setDrawer(ExampleParticleSystemDrawer);
		ParticleNodeCore->setMaterial(PSMaterial);
    
	NodeRefPtr ParticleNode = Node::create();
        ParticleNode->setCore(ParticleNodeCore);


    // Make Main Scene Node and add the Torus
    NodeRefPtr scene = Node::create();
        scene->setCore(Group::create());
        scene->addChild(ParticleNode);

    mgr->setRoot(scene);

    // Show the whole Scene
    mgr->showAll();


    //Open Window
    Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
    Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
    TutorialWindow->openWindow(WinPos,
            WinSize,
            "02DynamicDistribution");

    //Enter main Loop
    TutorialWindow->mainLoop();
    
    osgExit();

    return 0;
}
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    // Set up Window
    TutorialWindow = createNativeWindow();
    TutorialWindow->initWindow();

    TutorialWindow->setDisplayCallback(display);
    TutorialWindow->setReshapeCallback(reshape);

    TutorialKeyListener TheKeyListener;
    TutorialWindow->addKeyListener(&TheKeyListener);
    TutorialMouseListener TheTutorialMouseListener;
    TutorialMouseMotionListener TheTutorialMouseMotionListener;
    TutorialWindow->addMouseListener(&TheTutorialMouseListener);
    TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener);

    // Create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // Tell the Manager what to manage
    mgr->setWindow(TutorialWindow);


    BlendChunkRefPtr PSBlendChunk = BlendChunk::create();
    PSBlendChunk->setSrcFactor(GL_SRC_ALPHA);
    PSBlendChunk->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);

    //Particle System Material
    TextureObjChunkRefPtr QuadTextureObjChunk = TextureObjChunk::create();
    ImageRefPtr LoadedImage = ImageFileHandler::the()->read("./Data/Cloud.png");    
    QuadTextureObjChunk->setImage(LoadedImage);

    MaterialChunkRefPtr PSMaterialChunk = MaterialChunk::create();
    PSMaterialChunk->setAmbient(Color4f(0.3f,0.3f,0.3f,1.0f));
    PSMaterialChunk->setDiffuse(Color4f(0.7f,0.7f,0.7f,1.0f));
    PSMaterialChunk->setSpecular(Color4f(0.9f,0.9f,0.9f,1.0f));
    PSMaterialChunk->setColorMaterial(GL_AMBIENT_AND_DIFFUSE);

    ChunkMaterialRefPtr PSMaterial = ChunkMaterial::create();
    PSMaterial->addChunk(QuadTextureObjChunk);
    PSMaterial->addChunk(PSMaterialChunk);
    PSMaterial->addChunk(PSBlendChunk);

    //Particle System Material 2
    TextureObjChunkRefPtr QuadTextureObjChunk2 = TextureObjChunk::create();
    ImageRefPtr LoadedImage2 = ImageFileHandler::the()->read("./Data/Cloud.png");    
    QuadTextureObjChunk2->setImage(LoadedImage2);

    MaterialChunkRefPtr PSMaterialChunk2 = MaterialChunk::create();
    PSMaterialChunk2->setAmbient(Color4f(0.3f,0.3f,0.3f,1.0f));
    PSMaterialChunk2->setDiffuse(Color4f(0.7f,0.7f,0.7f,1.0f));
    PSMaterialChunk2->setSpecular(Color4f(0.9f,0.9f,0.9f,1.0f));
    PSMaterialChunk2->setColorMaterial(GL_AMBIENT_AND_DIFFUSE);

    ChunkMaterialRefPtr PSMaterial2 = ChunkMaterial::create();
    PSMaterial2->addChunk(QuadTextureObjChunk2);
    PSMaterial2->addChunk(PSMaterialChunk2);
    PSMaterial2->addChunk(PSBlendChunk);


    //Particle System

    Example1ParticleSystem = OSG::ParticleSystem::create();
    Example1ParticleSystem->attachUpdateListener(TutorialWindow);

    Example2ParticleSystem = OSG::ParticleSystem::create();
    Example2ParticleSystem->attachUpdateListener(TutorialWindow);

    //Particle System Drawer
    Example1ParticleSystemDrawer = OSG::QuadParticleSystemDrawer::create();
    Example2ParticleSystemDrawer = OSG::QuadParticleSystemDrawer::create();




    //Attach the function objects to the Generator
    //Generator 1 
    ExampleBurstGenerator = OSG::BurstParticleGenerator::create();
    ExampleBurstGenerator->setPositionDistribution(createPositionDistribution());
    ExampleBurstGenerator->setLifespanDistribution(createLifespanDistribution());
    ExampleBurstGenerator->setBurstAmount(50.0);
    ExampleBurstGenerator->setVelocityDistribution(createVelocityDistribution());
    ExampleBurstGenerator->setAccelerationDistribution(createAccelerationDistribution());
    ExampleBurstGenerator->setSizeDistribution(createSizeDistribution());

    //Generator 2
    Example2BurstGenerator = OSG::BurstParticleGenerator::create();
    Example2BurstGenerator->setPositionDistribution(createPositionDistribution());
    Example2BurstGenerator->setLifespanDistribution(createLifespanDistribution());
    Example2BurstGenerator->setBurstAmount(50.0);
    Example2BurstGenerator->setVelocityDistribution(createVelocityDistribution2());
    Example2BurstGenerator->setAccelerationDistribution(createAccelerationDistribution());
    Example2BurstGenerator->setSizeDistribution(createSizeDistribution());



    //Particle System Node
    ParticleSystemCoreRefPtr ParticleNodeCore = OSG::ParticleSystemCore::create();
    ParticleNodeCore->setSystem(Example1ParticleSystem);
    ParticleNodeCore->setDrawer(Example1ParticleSystemDrawer);
    ParticleNodeCore->setMaterial(PSMaterial);

    NodeRefPtr ParticleNode = OSG::Node::create();
    ParticleNode->setCore(ParticleNodeCore);

    //Particle System Node2
    ParticleSystemCoreRefPtr ParticleNodeCore2 = OSG::ParticleSystemCore::create();
    ParticleNodeCore2->setSystem(Example2ParticleSystem);
    ParticleNodeCore2->setDrawer(Example2ParticleSystemDrawer);
    ParticleNodeCore2->setMaterial(PSMaterial2);

    NodeRefPtr ParticleNode2 = OSG::Node::create();
    ParticleNode2->setCore(ParticleNodeCore2);

    //Ground Node
    NodeRefPtr GoundNode = makePlane(30.0,30.0,10,10);

    Matrix GroundTransformation;
    GroundTransformation.setRotate(Quaternion(Vec3f(1.0f,0.0,0.0), -3.14195f));
    TransformRefPtr GroundTransformCore = Transform::create();
    GroundTransformCore->setMatrix(GroundTransformation);

    NodeRefPtr GroundTransformNode = Node::create();
    GroundTransformNode->setCore(GroundTransformCore);
    GroundTransformNode->addChild(GoundNode);


    // Make Main Scene Node and add the Torus
    NodeRefPtr scene = OSG::Node::create();
    scene->setCore(OSG::Group::create());
    scene->addChild(ParticleNode);
    scene->addChild(ParticleNode2);
    scene->addChild(GroundTransformNode);

    mgr->setRoot(scene);

    // Show the whole Scene
    mgr->showAll();


    //Open Window
    Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
    Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
    TutorialWindow->openWindow(WinPos,
                               WinSize,
                               "06Explosion");

    //Enter main Loop
    TutorialWindow->mainLoop();

    osgExit();

    return 0;
}