]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/material/mat.hxx
Work around apparent OSG 3.2.0 normal binding bug.
[simgear.git] / simgear / scene / material / mat.hxx
index f607f7fb32a4805428e0ab27ca9fdc07c6dc5b69..7d03b5772dc610a40e90033dc0e187a9d9bcf7c0 100644 (file)
 #ifndef _SG_MAT_HXX
 #define _SG_MAT_HXX
 
-#ifndef __cplusplus
-# error This library requires C++
-#endif
-
 #include <simgear/compiler.h>
 
 #include <string>      // Standard C++ string library
 #include <vector>
 #include <map>
 
-#include <simgear/math/SGMath.hxx>
 #include "Effect.hxx"
-#include <simgear/scene/tgdb/SGTexturedTriangleBin.hxx>
 
 #include <osg/ref_ptr>
 #include <osg/Texture2D>
@@ -48,21 +42,22 @@ namespace osg
 class StateSet;
 }
 
-#include <simgear/scene/util/SGReaderWriterOptions.hxx>
-#include <simgear/props/props.hxx>
 #include <simgear/structure/SGSharedPtr.hxx>
-#include <simgear/scene/util/SGSceneFeatures.hxx>
-#include <simgear/props/condition.hxx>
-
-#include "matmodel.hxx"
+#include <simgear/math/SGMath.hxx>
+#include <simgear/bvh/BVHMaterial.hxx>
 
 namespace simgear
 {
 class Effect;
 void reload_shaders();
+class SGReaderWriterOptions;
 }
 
+class SGMatModelGroup;
+class SGCondition;
+class SGPropertyNode;
 class SGMaterialGlyph;
+class SGTexturedTriangleBin;
 
 /**
  * A material in the scene graph.
@@ -73,7 +68,7 @@ class SGMaterialGlyph;
  * defined in the $FG_ROOT/materials.xml file, and can be changed
  * at runtime.
  */
-class SGMaterial : public SGReferenced {
+class SGMaterial : public simgear::BVHMaterial {
 
 public:
 
@@ -110,13 +105,13 @@ public:
   /**
    * Get the textured state.
    */
-  simgear::Effect* get_effect(SGTexturedTriangleBin triangleBin);
+  simgear::Effect* get_effect(const SGTexturedTriangleBin& triangleBin);
   simgear::Effect* get_effect();
 
   /**
    * Get the textured state.
    */
-  osg::Texture2D* get_object_mask(SGTexturedTriangleBin triangleBin);
+  osg::Texture2D* get_object_mask(const SGTexturedTriangleBin& triangleBin);
 
 
   /**
@@ -172,6 +167,15 @@ public:
    * @return The texture for auto-generated buildings.
    */
   inline std::string get_building_texture () const { return building_texture; }
+
+  /**
+   * Get the building lightmap.
+   *
+   * This is the lightmap used for auto-generated buildings.
+   *
+   * @return The lightmap for auto-generated buildings.
+   */
+  inline std::string get_building_lightmap () const { return building_lightmap; }
   
   // Ratio of the 3 random building sizes
   inline double get_building_small_fraction () const { return building_small_ratio / (building_small_ratio + building_medium_ratio + building_large_ratio); }
@@ -206,6 +210,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.
@@ -252,31 +261,23 @@ public:
   inline std::string get_tree_texture () const { return  tree_texture; }
   
   /**
-   * Return if the surface material is solid, if it is not solid, a fluid
-   * can be assumed, that is usually water.
-   */
-  bool get_solid () const { return solid; }
-
-  /**
-   * Get the friction factor for that material
+   * 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.
    */
-  double get_friction_factor () const { return friction_factor; }
-
-  /**
-   * Get the rolling friction for that material
-   */
-  double get_rolling_friction () const { return rolling_friction; }
-
-  /**
-   * Get the bumpines for that material
-   */
-  double get_bumpiness () const { return bumpiness; }
-
+  inline double get_cos_tree_max_density_slope_angle () const { return cos_tree_max_density_slope_angle; }
+  
   /**
-   * Get the load resistance
+   * 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.
    */
-  double get_load_resistance () const { return load_resistance; }
-
+  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
    */
@@ -303,13 +304,7 @@ public:
    * Evaluate whether this material is valid given the current global
    * property state.
    */
-   bool valid() { 
-     if (condition) {
-       return condition->test();       
-     } else {
-       return true;
-     }
-   }
+     bool valid() const;
 
   /**
    * Return pointer to glyph class, or 0 if it doesn't exist.
@@ -329,7 +324,7 @@ public:
     return SGVec2f((0 < tex_width) ? 1000.0f/tex_width : 1.0f,
                    (0 < tex_height) ? 1000.0f/tex_height : 1.0f);
   }
-
+  
 protected:
 
 \f
@@ -384,8 +379,9 @@ private:
   // building spacing
   double building_spacing;
   
-  // building texture
+  // building texture & lightmap
   std::string building_texture;
+  std::string building_lightmap;
 
   // Ratio of the 3 random building sizes
   double building_small_ratio;
@@ -421,6 +417,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;
 
@@ -435,21 +439,11 @@ private:
 
   // Number of varieties of tree texture
   int tree_varieties;
-
-  // True if the material is solid, false if it is a fluid
-  bool solid;
-
-  // the friction factor of that surface material
-  double friction_factor;
-
-  // the rolling friction of that surface material
-  double rolling_friction;
-
-  // the bumpiness of that surface material
-  double bumpiness;
-
-  // the load resistance of that surface material
-  double load_resistance;
+  
+  // 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;
@@ -475,6 +469,9 @@ private:
   
   // Condition, indicating when this material is active
   SGSharedPtr<const SGCondition> condition;
+  
+  // Parameters from the materials file
+  const SGPropertyNode* parameters;
 
   ////////////////////////////////////////////////////////////////////
   // Internal constructors and methods.