/* -*-c++-*- osgVisual - Copyright (C) 2009-2011 Torben Dannhauer * * This library is based on OpenSceneGraph, open source and may be redistributed and/or modified under * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or * (at your option) any later version. The full license is in LICENSE file * included with this distribution, and on the openscenegraph.org website. * * osgVisual requires for some proprietary modules a license from the correspondig manufacturer. * You have to aquire licenses for all used proprietary modules. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * OpenSceneGraph Public License for more details. */ #include #include #include #include using namespace osgVisual; visual_core::visual_core(osg::ArgumentParser& arguments_) : arguments(arguments_) { OSG_NOTIFY( osg::ALWAYS ) << "visual_core instantiated." << std::endl; } visual_core::~visual_core(void) { OSG_NOTIFY( osg::ALWAYS ) << "visual_core destroyed." << std::endl; } void visual_core::initialize() { OSG_NOTIFY( osg::ALWAYS ) << "Initialize visual_core..." << std::endl; // Configure osg to use KdTrees osgDB::Registry::instance()->setBuildKdTreesHint(osgDB::ReaderWriter::Options::BUILD_KDTREES); // Configure Multisampling osg::DisplaySettings::instance()->setNumMultiSamples(4); // Setup pathes osgDB::Registry::instance()->getDataFilePathList().push_back( "D:/DA/osgVisual/models" ); // Setup viewer viewer = new osgViewer::Viewer(arguments); // Setup coordinate system node rootNode = new osg::CoordinateSystemNode; rootNode->setEllipsoidModel(new osg::EllipsoidModel()); //osg::DisplaySettings::instance()->setNumOfDatabaseThreadsHint( 8 ); // Show model viewer->setSceneData( rootNode ); // create the windows and run the threads. viewer->realize(); loadTerrain(arguments); // All modules are initialized - now check arguments for any unused parameter. checkCommandlineArgumentsForFinalErrors(); // Run visual main loop mainLoop(); } void visual_core::mainLoop() { int framestoScenerySetup = 5; // run main loop while( !viewer->done() ) { // setup scenery if(framestoScenerySetup-- == 0) setupScenery(); // next frame please.... viewer->advance(); /*double hat, hot, lat, lon, height; util::getWGS84ofCamera( viewer->getCamera(), rootNode, lat, lon, height); if (util::queryHeightOfTerrain( hot, rootNode, lat, lon) && util::queryHeightAboveTerrainInWGS84( hat, rootNode, lat, lon, height ) ) OSG_NOTIFY( osg::ALWAYS ) << "HOT is: " << hot << ", HAT is: " << hat << std::endl;*/ // perform all queued events viewer->eventTraversal(); // update the scene by traversing it with the the update visitor which will // call all node update callbacks and animations. viewer->updateTraversal(); // Render the Frame. viewer->renderingTraversals(); } // END WHILE } void visual_core::shutdown() { OSG_NOTIFY( osg::ALWAYS ) << "Shutdown visual_core..." << std::endl; // Unset scene data viewer->setSceneData( NULL ); // Shutdown data rootNode = NULL; // Destroy osgViewer viewer = NULL; } bool visual_core::loadTerrain(osg::ArgumentParser& arguments_) { //std::vector terrainFile = util::getTerrainFromXMLConfig(configFilename); // Add each terrain path to the FilePath list to help OSG to find the subtiles. for(unsigned int i=0;igetDataFilePathList().push_back(osgDB::getFilePath(terrainFile[i])); osg::ref_ptr model = osgDB::readNodeFiles(terrainFile); if( model.valid() ) { osgTerrain::Terrain* terrain = util::findTopMostNodeOfType(model.get()); if (!terrain) { terrain = new osgTerrain::Terrain; terrain->addChild(model.get()); model = terrain; } rootNode->addChild( terrain ); return true; } else { OSG_NOTIFY( osg::FATAL ) << "Load terrain: No data loaded" << std::endl; return false; } return false; } bool visual_core::checkCommandlineArgumentsForFinalErrors() { // Setup Application Usage arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName()); arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the a new visualization tool, written by Torben Dannhauer"); arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); // if user request help write it out to cout. if (arguments.read("-h") || arguments.read("--help")) { arguments.getApplicationUsage()->write(std::cout); //cause the viewer to exit and shut down clean. viewer->setDone(true); } // report any errors if they have occurred when parsing the program arguments. if (arguments.errors()) { arguments.writeErrorMessages(std::cout); //cause the viewer to exit and shut down clean. viewer->setDone(true); } // any option left unread are converted into errors to write out later. arguments.reportRemainingOptionsAsUnrecognized(); // report any errors if they have occurred when parsing the program arguments. if (arguments.errors()) { arguments.writeErrorMessages(std::cout); return false; } return true; } void visual_core::setupScenery() { // Nothing }