root/OpenSceneGraph/trunk/examples/osgsimulation/osgsimulation.cpp @ 2995

Revision 2995, 3.4 kB (checked in by robert, 10 years ago)

Added the beginings of new osgParticle Explosion, Fire and SmokeEffects?.

Added support for generation explosion, fire and smoke effects in osgsimulation

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1#include <osgProducer/Viewer>
2
3#include <osg/Group>
4#include <osg/Geode>
5
6#include <osgParticle/ExplosionEffect>
7#include <osgParticle/SmokeEffect>
8#include <osgParticle/FireEffect>
9#include <osgParticle/ParticleSystemUpdater>
10
11
12//////////////////////////////////////////////////////////////////////////////
13// MAIN SCENE GRAPH BUILDING FUNCTION
14//////////////////////////////////////////////////////////////////////////////
15
16void build_world(osg::Group *root)
17{
18
19    osgParticle::ExplosionEffect* explosion = new osgParticle::ExplosionEffect;
20    osgParticle::SmokeEffect* smoke = new osgParticle::SmokeEffect;
21    osgParticle::FireEffect* fire = new osgParticle::FireEffect;
22
23    root->addChild(explosion);
24    root->addChild(smoke);
25    root->addChild(fire);
26
27    osgParticle::ParticleSystemUpdater *psu = new osgParticle::ParticleSystemUpdater;
28
29    psu->addParticleSystem(explosion->getParticleSystem());
30    psu->addParticleSystem(smoke->getParticleSystem());
31    psu->addParticleSystem(fire->getParticleSystem());
32
33    // add the updater node to the scene graph
34    root->addChild(psu);
35
36}
37
38
39//////////////////////////////////////////////////////////////////////////////
40// main()
41//////////////////////////////////////////////////////////////////////////////
42
43
44int main(int argc, char **argv)
45{
46    // use an ArgumentParser object to manage the program arguments.
47    osg::ArgumentParser arguments(&argc,argv);
48   
49    // set up the usage document, in case we need to print out how to use this program.
50    arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which demonstrates use of particle systems.");
51    arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] image_file_left_eye image_file_right_eye");
52    arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information");
53   
54
55    // construct the viewer.
56    osgProducer::Viewer viewer(arguments);
57
58    // set up the value with sensible default event handlers.
59    viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS);
60
61    // get details on keyboard and mouse bindings used by the viewer.
62    viewer.getUsage(*arguments.getApplicationUsage());
63
64    // if user request help write it out to cout.
65    if (arguments.read("-h") || arguments.read("--help"))
66    {
67        arguments.getApplicationUsage()->write(std::cout);
68        return 1;
69    }
70
71    // any option left unread are converted into errors to write out later.
72    arguments.reportRemainingOptionsAsUnrecognized();
73
74    // report any errors if they have occured when parsing the program aguments.
75    if (arguments.errors())
76    {
77        arguments.writeErrorMessages(std::cout);
78        return 1;
79    }
80   
81    osg::Group *root = new osg::Group;
82    build_world(root);
83   
84    // add a viewport to the viewer and attach the scene graph.
85    viewer.setSceneData(root);
86       
87    // create the windows and run the threads.
88    viewer.realize();
89
90    while( !viewer.done() )
91    {
92        // wait for all cull and draw threads to complete.
93        viewer.sync();
94
95        // update the scene by traversing it with the the update visitor which will
96        // call all node update callbacks and animations.
97        viewer.update();
98         
99        // fire off the cull and draw traversals of the scene.
100        viewer.frame();
101       
102    }
103   
104    // wait for all cull and draw threads to complete before exit.
105    viewer.sync();
106
107    return 0;
108}
Note: See TracBrowser for help on using the browser.