]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/material/mat.hxx
Fix removal of directories.
[simgear.git] / simgear / scene / material / mat.hxx
index 1f17579052ed04dfdb64293814ea8ed7dd275c41..ee094fa61d2c85d2748e1e99916b259cf8ed08b1 100644 (file)
@@ -43,9 +43,17 @@ class StateSet;
 }
 
 #include <simgear/structure/SGSharedPtr.hxx>
+#include <simgear/threads/SGThread.hxx> // for SGMutex
+#include <simgear/math/SGLimits.hxx>
+#include <simgear/math/SGMisc.hxx>
 #include <simgear/math/SGMath.hxx>
+#include <simgear/math/SGVec2.hxx>
+#include <simgear/math/SGRect.hxx>
 #include <simgear/bvh/BVHMaterial.hxx>
 
+typedef osg::ref_ptr<osg::Texture2D> Texture2DRef;
+typedef std::vector<SGRect <float> > AreaList;
+
 namespace simgear
 {
 class Effect;
@@ -84,13 +92,19 @@ public:
    * state information for the material.  This node is usually
    * loaded from the $FG_ROOT/materials.xml file.
    */
-  SGMaterial( const osgDB::Options*, 
-              const SGPropertyNode *props, 
-              SGPropertyNode *prop_root);
+  SGMaterial(const osgDB::Options*,
+             const SGPropertyNode *props,
+             SGPropertyNode *prop_root,
+             AreaList *a,
+                        SGSharedPtr<const SGCondition> c);
+
 
   SGMaterial(const simgear::SGReaderWriterOptions*,
              const SGPropertyNode *props,
-             SGPropertyNode *prop_root);
+             SGPropertyNode *prop_root,
+             AreaList *a,
+                        SGSharedPtr<const SGCondition> c);
+
   /**
    * Destructor.
    */
@@ -105,13 +119,13 @@ public:
   /**
    * Get the textured state.
    */
-  simgear::Effect* get_effect(const SGTexturedTriangleBin& triangleBin);
+  simgear::Effect* get_one_effect(int texIndex);
   simgear::Effect* get_effect();
 
   /**
    * Get the textured state.
    */
-  osg::Texture2D* get_object_mask(const SGTexturedTriangleBin& triangleBin);
+  osg::Texture2D* get_one_object_mask(int texIndex);
 
 
   /**
@@ -210,6 +224,11 @@ public:
   inline double get_building_large_max_width () const { return building_large_max_width; }
   inline double get_building_large_min_depth () const { return building_large_min_depth; }
   inline double get_building_large_max_depth () const { return building_large_max_depth; }
+  
+  inline double get_building_range () const { return building_range; }
+  
+  inline double get_cos_object_max_density_slope_angle () const { return cos_object_max_density_slope_angle; }
+  inline double get_cos_object_zero_density_slope_angle () const { return cos_object_zero_density_slope_angle; }
 
   /**
    * Get the wood coverage.
@@ -254,6 +273,32 @@ public:
    * @return the texture to use for trees.
    */
   inline std::string get_tree_texture () const { return  tree_texture; }
+
+
+  /**
+   * Get the effect file name to use for trees
+   *
+   * @return the effect to use for this set of trees.
+   */
+  inline std::string get_tree_effect () const { return  tree_effect; }
+  
+  /**
+   * Get the cosine of the maximum tree density slope angle. We
+   * use the cosine as it can be compared directly to the z component
+   * of a triangle normal.
+   * 
+   * @return the cosine of the maximum tree density slope angle.
+   */
+  inline double get_cos_tree_max_density_slope_angle () const { return cos_tree_max_density_slope_angle; }
+  
+  /**
+   * Get the cosine of the maximum tree density slope angle. We
+   * use the cosine as it can be compared directly to the z component
+   * of a triangle normal.
+   * 
+   * @return the cosine of the maximum tree density slope angle.
+   */
+  inline double get_cos_tree_zero_density_slope_angle () const { return cos_tree_zero_density_slope_angle; }
   
   /**
    * Get the list of names for this material
@@ -279,9 +324,9 @@ public:
   
   /**
    * Evaluate whether this material is valid given the current global
-   * property state.
+   * property state and the tile location.
    */
-     bool valid() const;
+     bool valid(SGVec2f loc) const;
 
   /**
    * Return pointer to glyph class, or 0 if it doesn't exist.
@@ -301,7 +346,7 @@ public:
     return SGVec2f((0 < tex_width) ? 1000.0f/tex_width : 1.0f,
                    (0 < tex_height) ? 1000.0f/tex_height : 1.0f);
   }
-
+  
 protected:
 
 \f
@@ -394,6 +439,14 @@ private:
   double building_large_min_depth;
   double building_large_max_depth;
   
+  double building_range;
+  
+  // Cosine of the angle of maximum and zero density, 
+  // used to stop buildings and random objects from being 
+  // created on too steep a slope.
+  double cos_object_max_density_slope_angle;
+  double cos_object_zero_density_slope_angle;
+  
   // coverage of woods
   double wood_coverage;
 
@@ -408,6 +461,11 @@ private:
 
   // Number of varieties of tree texture
   int tree_varieties;
+  
+  // cosine of the tile angle of maximum and zero density,
+  // used to stop trees from being created on too steep a slope.
+  double cos_tree_max_density_slope_angle;
+  double cos_tree_zero_density_slope_angle;
 
   // material properties
   SGVec4f ambient, diffuse, specular, emission;
@@ -426,17 +484,26 @@ private:
   
   // Tree texture, typically a strip of applicable tree textures
   std::string tree_texture;
+
+  // Tree effect to be used for a particular material
+  std::string tree_effect;
   
   // Object mask, a simple RGB texture used as a mask when placing
   // random vegetation, objects and buildings
-  std::vector<osg::Texture2D*> _masks;
+  std::vector<Texture2DRef> _masks;
   
   // Condition, indicating when this material is active
   SGSharedPtr<const SGCondition> condition;
   
+  // List of geographical rectangles for this material
+  AreaList* areas;
+
   // Parameters from the materials file
   const SGPropertyNode* parameters;
 
+  // per-material lock for entrypoints called from multiple threads
+  SGMutex _lock;
+
   ////////////////////////////////////////////////////////////////////
   // Internal constructors and methods.
   ////////////////////////////////////////////////////////////////////