| 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. |
| | 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. |
| 38 | | arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName()); |
| 39 | | arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the standard OpenSceneGraph example which loads and visualises 3d models."); |
| 40 | | arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); |
| 41 | | arguments.getApplicationUsage()->addCommandLineOption("--image <filename>","Load an image and render it on a quad"); |
| 42 | | arguments.getApplicationUsage()->addCommandLineOption("--dem <filename>","Load an image/DEM and render it on a HeightField"); |
| 43 | | arguments.getApplicationUsage()->addCommandLineOption("--login <url> <username> <password>","Provide authentication information for http file access."); |
| | 45 | arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName()); |
| | 46 | arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the standard OpenSceneGraph example which loads and visualises 3d models."); |
| | 47 | arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); |
| | 48 | arguments.getApplicationUsage()->addCommandLineOption("--image <filename>","Load an image and render it on a quad"); |
| | 49 | arguments.getApplicationUsage()->addCommandLineOption("--dem <filename>","Load an image/DEM and render it on a HeightField"); |
| | 50 | arguments.getApplicationUsage()->addCommandLineOption("--login <url> <username> <password>","Provide authentication information for http file access."); |
| 47 | | unsigned int helpType = 0; |
| 48 | | if ((helpType = arguments.readHelpType())) |
| | 54 | unsigned int helpType = 0; |
| | 55 | if ((helpType = arguments.readHelpType())) |
| | 56 | { |
| | 57 | arguments.getApplicationUsage()->write(std::cout, helpType); |
| | 58 | return 1; |
| | 59 | } |
| | 60 | |
| | 61 | // report any errors if they have occurred when parsing the program arguments. |
| | 62 | if (arguments.errors()) |
| | 63 | { |
| | 64 | arguments.writeErrorMessages(std::cout); |
| | 65 | return 1; |
| | 66 | } |
| | 67 | |
| | 68 | if (arguments.argc()<=1) |
| | 69 | { |
| | 70 | arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION); |
| | 71 | return 1; |
| | 72 | } |
| | 73 | |
| | 74 | std::string url, username, password; |
| | 75 | while(arguments.read("--login",url, username, password)) |
| | 76 | { |
| | 77 | if (!osgDB::Registry::instance()->getAuthenticationMap()) |
| 53 | | |
| 54 | | // report any errors if they have occurred when parsing the program arguments. |
| 55 | | if (arguments.errors()) |
| | 85 | } |
| | 86 | |
| | 87 | // set up the camera manipulators. |
| | 88 | { |
| | 89 | osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator; |
| | 90 | |
| | 91 | keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() ); |
| | 92 | keyswitchManipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() ); |
| | 93 | keyswitchManipulator->addMatrixManipulator( '3', "Drive", new osgGA::DriveManipulator() ); |
| | 94 | keyswitchManipulator->addMatrixManipulator( '4', "Terrain", new osgGA::TerrainManipulator() ); |
| | 95 | |
| | 96 | std::string pathfile; |
| | 97 | char keyForAnimationPath = '5'; |
| | 98 | while (arguments.read("-p",pathfile)) |
| 57 | | arguments.writeErrorMessages(std::cout); |
| 58 | | return 1; |
| 59 | | } |
| 60 | | |
| 61 | | if (arguments.argc()<=1) |
| 62 | | { |
| 63 | | arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION); |
| 64 | | return 1; |
| | 100 | osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile); |
| | 101 | if (apm || !apm->valid()) |
| | 102 | { |
| | 103 | unsigned int num = keyswitchManipulator->getNumMatrixManipulators(); |
| | 104 | keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm ); |
| | 105 | keyswitchManipulator->selectMatrixManipulator(num); |
| | 106 | ++keyForAnimationPath; |
| | 107 | } |
| 67 | | std::string url, username, password; |
| 68 | | while(arguments.read("--login",url, username, password)) |
| 69 | | { |
| 70 | | if (!osgDB::Registry::instance()->getAuthenticationMap()) |
| 71 | | { |
| 72 | | osgDB::Registry::instance()->setAuthenticationMap(new osgDB::AuthenticationMap); |
| 73 | | osgDB::Registry::instance()->getAuthenticationMap()->addAuthenticationDetails( |
| 74 | | url, |
| 75 | | new osgDB::AuthenticationDetails(username, password) |
| 76 | | ); |
| 77 | | } |
| 78 | | } |
| | 110 | viewer.setCameraManipulator( keyswitchManipulator.get() ); |
| | 111 | } |
| 84 | | keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() ); |
| 85 | | keyswitchManipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() ); |
| 86 | | keyswitchManipulator->addMatrixManipulator( '3', "Drive", new osgGA::DriveManipulator() ); |
| 87 | | keyswitchManipulator->addMatrixManipulator( '4', "Terrain", new osgGA::TerrainManipulator() ); |
| 88 | | keyswitchManipulator->addMatrixManipulator( '5', "Spherical", new osgGA::SphericalManipulator() ); |
| | 116 | // add the thread model handler |
| | 117 | viewer.addEventHandler(new osgViewer::ThreadingHandler); |
| 90 | | std::string pathfile; |
| 91 | | char keyForAnimationPath = '6'; |
| 92 | | while (arguments.read("-p",pathfile)) |
| 93 | | { |
| 94 | | osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile); |
| 95 | | if (apm || !apm->valid()) |
| 96 | | { |
| 97 | | unsigned int num = keyswitchManipulator->getNumMatrixManipulators(); |
| 98 | | keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm ); |
| 99 | | keyswitchManipulator->selectMatrixManipulator(num); |
| 100 | | ++keyForAnimationPath; |
| 101 | | } |
| 102 | | } |
| | 119 | // add the window size toggle handler |
| | 120 | viewer.addEventHandler(new osgViewer::WindowSizeHandler); |
| 131 | | // load the data |
| 132 | | osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments); |
| 133 | | if (!loadedModel) |
| 134 | | { |
| 135 | | std::cout << arguments.getApplicationName() <<": No data loaded" << std::endl; |
| 136 | | return 1; |
| 137 | | } |
| 138 | | |
| 139 | | // any option left unread are converted into errors to write out later. |
| 140 | | arguments.reportRemainingOptionsAsUnrecognized(); |
| 141 | | |
| 142 | | // report any errors if they have occurred when parsing the program arguments. |
| 143 | | if (arguments.errors()) |
| 144 | | { |
| 145 | | arguments.writeErrorMessages(std::cout); |
| 146 | | return 1; |
| 147 | | } |
| | 148 | // report any errors if they have occurred when parsing the program arguments. |
| | 149 | if (arguments.errors()) |
| | 150 | { |
| | 151 | arguments.writeErrorMessages(std::cout); |
| | 152 | return 1; |
| | 153 | } |
| 158 | | return viewer.run(); |
| | 165 | { |
| | 166 | char tmp[256]; |
| | 167 | tmp[sizeof(tmp) - 1] = 0; |
| | 168 | getcwd(tmp, sizeof(tmp) - 1); |
| | 169 | |
| | 170 | std::string path(tmp); |
| | 171 | path += "\\system\\cache\\planet"; |
| | 172 | |
| | 173 | tmp[sizeof(tmp) - 1] = 0; |
| | 174 | snprintf(tmp, sizeof(tmp) - 1, "%s", path.c_str()); |
| | 175 | //_putenv(tmp); |
| | 176 | // osgDB::Registry::instance()->setFileCache(new osgDB::FileCache( tmp ) ); |
| | 177 | viewer.getDatabasePager()->setTargetMaximumNumberOfPageLOD(500); |
| | 178 | |
| | 179 | #ifdef _WINDOWS |
| | 180 | osg::ref_ptr<baronvsync::CVsyncDrawable> vsync = new baronvsync::CVsyncDrawable(); |
| | 181 | osg::ref_ptr<osg::Geode> vsyncGeode = new osg::Geode(); |
| | 182 | vsyncGeode->addDrawable(vsync.get()); |
| | 183 | vsync->SetVSync(false); |
| | 184 | group->addChild(vsyncGeode.get()); |
| | 185 | #endif |
| | 186 | |
| | 187 | } |
| | 188 | |
| | 189 | viewer.realize(); |
| | 190 | |
| | 191 | return viewer.run(); |