Show
Ignore:
Timestamp:
05/14/04 00:09:23 (10 years ago)
Author:
robert
Message:

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

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

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/examples/osgsimulation/osgsimulation.cpp

    r2213 r2995  
    1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield  
    2  * 
    3  * This application is open source and may be redistributed and/or modified    
    4  * 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 of 
    9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
    10 */ 
    11  
    12 #include <osgDB/ReadFile> 
    13 #include <osgUtil/Optimizer> 
    141#include <osgProducer/Viewer> 
    152 
     3#include <osg/Group> 
     4#include <osg/Geode> 
    165 
    17 #include <osgSim/SphereSegment> 
     6#include <osgParticle/ExplosionEffect> 
     7#include <osgParticle/SmokeEffect> 
     8#include <osgParticle/FireEffect> 
     9#include <osgParticle/ParticleSystemUpdater> 
    1810 
    19 using namespace osgSim; 
    2011 
    21 osg::Node* createSphereSegment() 
     12////////////////////////////////////////////////////////////////////////////// 
     13// MAIN SCENE GRAPH BUILDING FUNCTION 
     14////////////////////////////////////////////////////////////////////////////// 
     15 
     16void build_world(osg::Group *root) 
    2217{ 
    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)); 
    2918 
    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; 
    3222 
    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 
    3636} 
    3737 
    3838 
    39 int main( int argc, char **argv ) 
     39////////////////////////////////////////////////////////////////////////////// 
     40// main() 
     41////////////////////////////////////////////////////////////////////////////// 
     42 
     43 
     44int main(int argc, char **argv) 
    4045{ 
    41  
    4246    // use an ArgumentParser object to manage the program arguments. 
    4347    osg::ArgumentParser arguments(&argc,argv); 
    4448     
    4549    // 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"); 
    4952    arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); 
    5053     
     
    7679    } 
    7780     
    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         
    11287    // create the windows and run the threads. 
    11388    viewer.realize(); 
     
    132107    return 0; 
    133108} 
    134