- Timestamp:
- 05/14/04 00:09:23 (9 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/examples/osgsimulation/osgsimulation.cpp
r2213 r2995 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield2 *3 * This application is open source and may be redistributed and/or modified4 * freely and without restriction, both in commericial and non commericial applications,5 * as long as this copyright notice is maintained.6 *7 * This application is distributed in the hope that it will be useful,8 * but WITHOUT ANY WARRANTY; without even the implied warranty of9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.10 */11 12 #include <osgDB/ReadFile>13 #include <osgUtil/Optimizer>14 1 #include <osgProducer/Viewer> 15 2 3 #include <osg/Group> 4 #include <osg/Geode> 16 5 17 #include <osgSim/SphereSegment> 6 #include <osgParticle/ExplosionEffect> 7 #include <osgParticle/SmokeEffect> 8 #include <osgParticle/FireEffect> 9 #include <osgParticle/ParticleSystemUpdater> 18 10 19 using namespace osgSim;20 11 21 osg::Node* createSphereSegment() 12 ////////////////////////////////////////////////////////////////////////////// 13 // MAIN SCENE GRAPH BUILDING FUNCTION 14 ////////////////////////////////////////////////////////////////////////////// 15 16 void build_world(osg::Group *root) 22 17 { 23 osgSim::SphereSegment* ss = new osgSim::SphereSegment(osg::Vec3(0.0f,0.0f,0.0f), 1.0f,24 osg::Vec3(0.0f,1.0f,0.0f),25 osg::DegreesToRadians(360.0f),26 osg::DegreesToRadians(45.0f),27 40);28 ss->setAllColors(osg::Vec4(1.0f,1.0f,1.0f,0.5f));29 18 30 return ss; 31 } 19 osgParticle::ExplosionEffect* explosion = new osgParticle::ExplosionEffect; 20 osgParticle::SmokeEffect* smoke = new osgParticle::SmokeEffect; 21 osgParticle::FireEffect* fire = new osgParticle::FireEffect; 32 22 33 osg::Node* createModel() 34 { 35 return createSphereSegment(); 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 36 } 37 37 38 38 39 int main( int argc, char **argv ) 39 ////////////////////////////////////////////////////////////////////////////// 40 // main() 41 ////////////////////////////////////////////////////////////////////////////// 42 43 44 int main(int argc, char **argv) 40 45 { 41 42 46 // use an ArgumentParser object to manage the program arguments. 43 47 osg::ArgumentParser arguments(&argc,argv); 44 48 45 49 // set up the usage document, in case we need to print out how to use this program. 46 arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName()); 47 arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the standard OpenSceneGraph example which loads and visualises 3d models."); 48 arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); 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"); 49 52 arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); 50 53 … … 76 79 } 77 80 78 if (arguments.argc()<=1) 79 { 80 arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION); 81 return 1; 82 } 83 84 // osg::Timer timer; 85 // osg::Timer_t start_tick = timer.tick(); 86 // 87 // // read the scene from the list of file specified commandline args. 88 // osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments); 89 // 90 // // if no model has been successfully loaded report failure. 91 // if (!loadedModel) 92 // { 93 // std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl; 94 // return 1; 95 // } 96 // 97 // osg::Timer_t end_tick = timer.tick(); 98 // 99 // std::cout << "Time to load = "<<timer.delta_s(start_tick,end_tick)<<std::endl; 100 101 osg::ref_ptr<osg::Node> loadedModel = createModel(); 102 103 104 // optimize the scene graph, remove rendundent nodes and state etc. 105 osgUtil::Optimizer optimizer; 106 optimizer.optimize(loadedModel.get()); 107 108 109 // set the scene to render 110 viewer.setSceneData(loadedModel.get()); 111 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 112 87 // create the windows and run the threads. 113 88 viewer.realize(); … … 132 107 return 0; 133 108 } 134
