| 1272 | | |
| 1273 | | // set up the usage document, in case we need to print out how to use this program. |
| 1274 | | arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName()); |
| 1275 | | arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" example interactive demonstrates constrained delaunay traingulation of point dataset."); |
| 1276 | | arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); |
| 1277 | | arguments.getApplicationUsage()->addCommandLineOption("--image <filename>","Load an image and render it on a quad"); |
| 1278 | | arguments.getApplicationUsage()->addCommandLineOption("--dem <filename>","Load an image/DEM and render it on a HeightField"); |
| 1279 | | arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display command line parameters"); |
| 1280 | | arguments.getApplicationUsage()->addCommandLineOption("--help-env","Display environment variables available"); |
| 1281 | | arguments.getApplicationUsage()->addCommandLineOption("--help-keys","Display keyboard & mouse bindings available"); |
| 1282 | | arguments.getApplicationUsage()->addCommandLineOption("--help-all","Display all command line, env vars and keyboard & mouse bindings"); |
| 1283 | | |
| 1284 | | |
| | 1268 | |
| 1286 | | osgProducer::Viewer viewer(arguments); |
| 1287 | | |
| 1288 | | // set up the value with sensible default event handlers. |
| 1289 | | viewer.setUpViewer(osgProducer::Viewer::STANDARD_SETTINGS); |
| 1290 | | |
| 1291 | | // get details on keyboard and mouse bindings used by the viewer. |
| 1292 | | viewer.getUsage(*arguments.getApplicationUsage()); |
| 1293 | | |
| 1294 | | // if user request help write it out to cout. |
| 1295 | | bool helpAll = arguments.read("--help-all"); |
| 1296 | | unsigned int helpType = ((helpAll || arguments.read("-h") || arguments.read("--help"))? osg::ApplicationUsage::COMMAND_LINE_OPTION : 0 ) | |
| 1297 | | ((helpAll || arguments.read("--help-env"))? osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE : 0 ) | |
| 1298 | | ((helpAll || arguments.read("--help-keys"))? osg::ApplicationUsage::KEYBOARD_MOUSE_BINDING : 0 ); |
| 1299 | | if (helpType) |
| 1300 | | { |
| 1301 | | arguments.getApplicationUsage()->write(std::cout, helpType); |
| 1302 | | return 1; |
| 1303 | | } |
| 1304 | | |
| 1305 | | // report any errors if they have occured when parsing the program aguments. |
| 1306 | | if (arguments.errors()) |
| 1307 | | { |
| 1308 | | arguments.writeErrorMessages(std::cout); |
| 1309 | | return 1; |
| 1310 | | } |
| 1311 | | |
| 1312 | | if (arguments.argc()<1) |
| 1313 | | { |
| 1314 | | arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION); |
| 1315 | | return 1; |
| 1316 | | } |
| 1317 | | |
| 1318 | | osg::Timer_t start_tick = osg::Timer::instance()->tick(); |
| 1319 | | |
| | 1270 | osgViewer::Viewer viewer; |
| | 1271 | |
| 1353 | | viewer.getEventHandlerList().push_front(new KeyboardEventHandler(loadedModel.get(), viewer)); |
| 1354 | | |
| 1355 | | // create the windows and run the threads. |
| 1356 | | viewer.realize(); |
| 1357 | | |
| 1358 | | while( !viewer.done() ) |
| 1359 | | { |
| 1360 | | // wait for all cull and draw threads to complete. |
| 1361 | | viewer.sync(); |
| 1362 | | |
| 1363 | | // update the scene by traversing it with the the update visitor which will |
| 1364 | | // call all node update callbacks and animations. |
| 1365 | | viewer.update(); |
| 1366 | | |
| 1367 | | // fire off the cull and draw traversals of the scene. |
| 1368 | | viewer.frame(); |
| 1369 | | |
| 1370 | | } |
| 1371 | | |
| 1372 | | // wait for all cull and draw threads to complete. |
| 1373 | | viewer.sync(); |
| 1374 | | |
| 1375 | | // run a clean up frame to delete all OpenGL objects. |
| 1376 | | viewer.cleanup_frame(); |
| 1377 | | |
| 1378 | | // wait for all the clean up frame to complete. |
| 1379 | | viewer.sync(); |
| 1380 | | |
| 1381 | | return 0; |
| 1382 | | } |
| | 1291 | viewer.addEventHandler(new KeyboardEventHandler(viewer)); |
| | 1292 | |
| | 1293 | return viewer.run(); |
| | 1294 | } |