]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/material/matmodel.cxx
Random buildings - initial commit.
[simgear.git] / simgear / scene / material / matmodel.cxx
index d8c9e3f1e7541aa5525ed51818b822d56870bd26..2ff665d9c638f6f1c55d2d938e1f7e5da3246504 100644 (file)
@@ -28,7 +28,7 @@
 #include <simgear/compiler.h>
 
 #include <map>
-using std::map;
+
 
 #include <osg/AlphaFunc>
 #include <osg/Group>
@@ -37,6 +37,7 @@ using std::map;
 #include <osg/Transform>
 
 #include <simgear/debug/logstream.hxx>
+#include <simgear/math/SGMath.hxx>
 #include <simgear/math/sg_random.h>
 #include <simgear/misc/sg_path.hxx>
 #include <simgear/misc/sgstream.hxx>
@@ -45,8 +46,8 @@ using std::map;
 #include "matmodel.hxx"
 
 using namespace simgear;
-
-\f
+using std::string;
+using std::map;\f
 ////////////////////////////////////////////////////////////////////////
 // Implementation of SGMatModel.
 ////////////////////////////////////////////////////////////////////////
@@ -54,6 +55,7 @@ using namespace simgear;
 SGMatModel::SGMatModel (const SGPropertyNode * node, double range_m)
   : _models_loaded(false),
     _coverage_m2(node->getDoubleValue("coverage-m2", 1000000)),
+    _spacing_m(node->getDoubleValue("spacing-m", 20)),
     _range_m(range_m)
 {
                                // Sanity check
@@ -64,7 +66,7 @@ SGMatModel::SGMatModel (const SGPropertyNode * node, double range_m)
   }
 
                                // Note all the model paths
-  vector <SGPropertyNode_ptr> path_nodes = node->getChildren("path");
+  std::vector <SGPropertyNode_ptr> path_nodes = node->getChildren("path");
   for (unsigned int i = 0; i < path_nodes.size(); i++)
     _paths.push_back(path_nodes[i]->getStringValue());
 
@@ -76,6 +78,8 @@ SGMatModel::SGMatModel (const SGPropertyNode * node, double range_m)
     _heading_type = HEADING_BILLBOARD;
   } else if (hdg == "random") {
     _heading_type = HEADING_RANDOM;
+  } else if (hdg == "mask") {
+    _heading_type = HEADING_MASK;
   } else {
     _heading_type = HEADING_FIXED;
     SG_LOG(SG_INPUT, SG_ALERT, "Unknown heading type: " << hdg
@@ -134,14 +138,11 @@ SGMatModel::load_models( SGPropertyNode *prop_root )
 }
 
 osg::Node*
-SGMatModel::get_random_model( SGPropertyNode *prop_root )
+SGMatModel::get_random_model( SGPropertyNode *prop_root, mt* seed )
 {
   load_models( prop_root ); // comment this out if preloading models
   int nModels = _models.size();
-  int index = int(sg_random() * nModels);
-  if (index >= nModels)
-    index = 0;
-  return _models[index].get();
+  return _models[mt_rand(seed) * nModels].get();
 }
 
 double
@@ -155,6 +156,11 @@ double SGMatModel::get_range_m() const
   return _range_m;
 }
 
+double SGMatModel::get_spacing_m() const
+{
+  return _spacing_m;
+}
+
 double SGMatModel::get_randomized_range_m(mt* seed) const
 {
   double lrand = mt_rand(seed);
@@ -184,7 +190,7 @@ SGMatModelGroup::SGMatModelGroup (SGPropertyNode * node)
   : _range_m(node->getDoubleValue("range-m", 2000))
 {
                                // Load the object subnodes
-  vector<SGPropertyNode_ptr> object_nodes =
+  std::vector<SGPropertyNode_ptr> object_nodes =
     ((SGPropertyNode *)node)->getChildren("object");
   for (unsigned int i = 0; i < object_nodes.size(); i++) {
     const SGPropertyNode * object_node = object_nodes[i];