]> git.mxchange.org Git - flightgear.git/blobdiff - utils/fgviewer/fgviewer.cxx
Allow setting of NED velocities.
[flightgear.git] / utils / fgviewer / fgviewer.cxx
index ba79ec5f18a366c9bcdbfce5f6dc02f18da062b0..e59a91645a9846f2238d8b20cb07d4c26ebaa441 100644 (file)
@@ -5,8 +5,14 @@
 #include <osgDB/ReadFile>
 #include <osgViewer/Viewer>
 #include <osgViewer/ViewerEventHandlers>
+#include <osgGA/KeySwitchMatrixManipulator>
+#include <osgGA/TrackballManipulator>
+#include <osgGA/FlightManipulator>
+#include <osgGA/DriveManipulator>
+#include <osgGA/TerrainManipulator>
 
 #include <simgear/props/props.hxx>
+#include <simgear/props/props_io.hxx>
 #include <simgear/misc/sg_path.hxx>
 #include <simgear/scene/material/matlib.hxx>
 #include <simgear/scene/tgdb/SGReaderWriterBTGOptions.hxx>
@@ -48,6 +54,21 @@ main(int argc, char** argv)
     // ... for some reason, get rid of that FIXME!
     viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded);
     
+    // set up the camera manipulators.
+    osgGA::KeySwitchMatrixManipulator* keyswitchManipulator;
+    keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator;
+    
+    osgGA::MatrixManipulator* mm = new osgGA::TrackballManipulator;
+    keyswitchManipulator->addMatrixManipulator('1', "Trackball", mm);
+    mm = new osgGA::FlightManipulator;
+    keyswitchManipulator->addMatrixManipulator('2', "Flight", mm);
+    mm = new osgGA::DriveManipulator;
+    keyswitchManipulator->addMatrixManipulator('3', "Drive", mm);
+    mm = new osgGA::TerrainManipulator;
+    keyswitchManipulator->addMatrixManipulator('4', "Terrain", mm);
+    
+    viewer.setCameraManipulator(keyswitchManipulator);
+
     // Usefull stats
     viewer.addEventHandler(new osgViewer::HelpHandler);
     viewer.addEventHandler(new osgViewer::StatsHandler);
@@ -61,7 +82,14 @@ main(int argc, char** argv)
     if (fg_root_env)
         fg_root = fg_root_env;
     else
+#if defined(PKGDATADIR)
+        fg_root = PKGDATADIR;
+#else
         fg_root = ".";
+#endif
+
+    osgDB::FilePathList filePathList;
+    filePathList.push_back(fg_root);
 
     const char *fg_scenery_env = std::getenv("FG_SCENERY");
     string_list path_list;
@@ -72,7 +100,6 @@ main(int argc, char** argv)
         path.append("Scenery");
         path_list.push_back(path.str());
     }
-    osgDB::FilePathList filePathList;
     for (unsigned i = 0; i < path_list.size(); ++i) {
         SGPath pt(path_list[i]), po(path_list[i]);
         pt.append("Terrain");
@@ -83,11 +110,29 @@ main(int argc, char** argv)
     }
 
     SGSharedPtr<SGPropertyNode> props = new SGPropertyNode;
-    props->getNode("sim/startup/season", true)->setStringValue("summer");
+    try {
+        SGPath preferencesFile = fg_root;
+        preferencesFile.append("preferences.xml");
+        readProperties(preferencesFile.str(), props);
+    } catch (...) {
+        // In case of an error, at least make summer :)
+        props->getNode("sim/startup/season", true)->setStringValue("summer");
+
+        std::cerr << "Problems loading FlightGear preferences.\n"
+                  << "Probably FG_ROOT is not properly set." << std::endl;
+    }
     SGMaterialLib* ml = new SGMaterialLib;
     SGPath mpath(fg_root);
     mpath.append("materials.xml");
-    ml->load(fg_root, mpath.str(), props);
+    try {
+        ml->load(fg_root, mpath.str(), props);
+    } catch (...) {
+        std::cerr << "Problems loading FlightGear materials.\n"
+                  << "Probably FG_ROOT is not properly set." << std::endl;
+    }
+
+    // The file path list must be set in the registry.
+    osgDB::Registry::instance()->getDataFilePathList() = filePathList;
     
     SGReaderWriterBTGOptions* btgOptions = new SGReaderWriterBTGOptions;
     btgOptions->getDatabasePathList() = filePathList;
@@ -99,7 +144,7 @@ main(int argc, char** argv)
 
     // if no model has been successfully loaded report failure.
     if (!loadedModel.valid()) {
-        std::cout << arguments.getApplicationName()
+        std::cerr << arguments.getApplicationName()
                   << ": No data loaded" << std::endl;
         return EXIT_FAILURE;
     }