]> git.mxchange.org Git - simgear.git/commitdiff
bvh: Introduce BVHMaterial independent of SGMaterial.
authorMathias Froehlich <Mathias.Froehlich@web.de>
Fri, 24 Aug 2012 19:20:40 +0000 (21:20 +0200)
committerMathias Froehlich <Mathias.Froehlich@web.de>
Fri, 24 Aug 2012 19:25:11 +0000 (21:25 +0200)
The bounding volumes in core should not depend on scenery.
Therefore reference material properties relevant for the BVH
tree in BVHMaterial.

simgear/bvh/BVHLineSegmentVisitor.hxx
simgear/bvh/BVHMaterial.cxx [new file with mode: 0644]
simgear/bvh/BVHMaterial.hxx [new file with mode: 0644]
simgear/bvh/BVHNearestPointVisitor.hxx
simgear/bvh/BVHStaticData.hxx
simgear/bvh/BVHStaticGeometryBuilder.hxx
simgear/bvh/CMakeLists.txt
simgear/scene/material/mat.cxx
simgear/scene/material/mat.hxx
simgear/scene/model/BoundingVolumeBuildVisitor.hxx

index cca02588bbdf1a571cebff938b71ab2cc8d890aa..40783ef3af4305ac134909fa562097789e34b55a 100644 (file)
@@ -54,7 +54,7 @@ public:
     { return _linearVelocity; }
     const SGVec3d& getAngularVelocity() const
     { return _angularVelocity; }
-    const SGMaterial* getMaterial() const
+    const BVHMaterial* getMaterial() const
     { return _material; }
     BVHNode::Id getId() const
     { return _id; }
@@ -87,7 +87,7 @@ private:
     SGVec3d _normal;
     SGVec3d _linearVelocity;
     SGVec3d _angularVelocity;
-    const SGMaterial* _material;
+    const BVHMaterial* _material;
     BVHNode::Id _id;
     
     bool _haveHit;
diff --git a/simgear/bvh/BVHMaterial.cxx b/simgear/bvh/BVHMaterial.cxx
new file mode 100644 (file)
index 0000000..c04af86
--- /dev/null
@@ -0,0 +1,35 @@
+// Copyright (C) 2008 - 2012  Mathias Froehlich - Mathias.Froehlich@web.de
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Library General Public
+// License as published by the Free Software Foundation; either
+// version 2 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Library General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+//
+
+#include "BVHMaterial.hxx"
+
+namespace simgear {
+
+BVHMaterial::BVHMaterial() :
+    _solid(true),
+    _friction_factor(1),
+    _rolling_friction(0.02),
+    _bumpiness(0),
+    _load_resistance(1e30)
+{
+}
+
+BVHMaterial::~BVHMaterial()
+{
+}
+
+}
diff --git a/simgear/bvh/BVHMaterial.hxx b/simgear/bvh/BVHMaterial.hxx
new file mode 100644 (file)
index 0000000..90c4d38
--- /dev/null
@@ -0,0 +1,75 @@
+// Copyright (C) 2008 - 2012  Mathias Froehlich - Mathias.Froehlich@web.de
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Library General Public
+// License as published by the Free Software Foundation; either
+// version 2 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Library General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+//
+
+#ifndef BVHMaterial_hxx
+#define BVHMaterial_hxx
+
+#include <simgear/structure/SGReferenced.hxx>
+
+namespace simgear {
+
+class BVHMaterial : public SGReferenced {
+public:
+    BVHMaterial();
+    virtual ~BVHMaterial();
+
+    /**
+     * 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
+     */
+    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; }
+    
+    /**
+     * Get the load resistance
+     */
+    double get_load_resistance () const { return _load_resistance; }
+
+protected:    
+    // 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;
+};
+
+}
+
+#endif
index 1c07c66acb8fd99352383181ba24216d8c158a51..5b5e1975291b05cc5959dd578eefc417665b5ecf 100644 (file)
@@ -140,7 +140,7 @@ public:
     { return _linearVelocity; }
     const SGVec3d& getAngularVelocity() const
     { return _angularVelocity; }
-    const SGMaterial* getMaterial() const
+    const BVHMaterial* getMaterial() const
     { return _material; }
     BVHNode::Id getId() const
     { return _id; }
@@ -155,7 +155,7 @@ private:
     SGVec3d _point;
     SGVec3d _linearVelocity;
     SGVec3d _angularVelocity;
-    const SGMaterial* _material;
+    const BVHMaterial* _material;
     BVHNode::Id _id;
 
     bool _havePoint;
index 400632adea004d64545b09c177ae426e86e40bc7..d90bcb80702534e5a2382811b2f2cd7a7094ba58 100644 (file)
 #include <simgear/structure/SGReferenced.hxx>
 #include <simgear/structure/SGSharedPtr.hxx>
 #include <simgear/math/SGGeometry.hxx>
-
-/// FIXME, the SGMaterial class is too much tied to the scenegraph aspects of
-/// the materials. Use some class more decribing the
-/// nature of the surface we live on ...
-class SGMaterial;
+#include "BVHMaterial.hxx"
 
 namespace simgear {
 
@@ -40,20 +36,20 @@ public:
     { return _vertices[i]; }
     
     
-    unsigned addMaterial(const SGMaterial* material)
+    unsigned addMaterial(const BVHMaterial* material)
     { _materials.push_back(material); return _materials.size() - 1; }
-    const SGMaterial* getMaterial(unsigned i) const
+    const BVHMaterial* getMaterial(unsigned i) const
     { if (_materials.size() <= i) return 0; return _materials[i]; }
 
     void trim()
     {
         std::vector<SGVec3f>(_vertices).swap(_vertices);
-        std::vector<const SGMaterial*>(_materials).swap(_materials);
+        std::vector<SGSharedPtr<const BVHMaterial> >(_materials).swap(_materials);
     }
     
 private:
     std::vector<SGVec3f> _vertices;
-    std::vector<const SGMaterial*> _materials;
+    std::vector<SGSharedPtr<const BVHMaterial> > _materials;
 };
 
 }
index 98968162e7bebbf872fbfae878c71efb69e1b969..b390d931d4c7863538db21bad002c5a13985cdf3 100644 (file)
@@ -78,16 +78,16 @@ public:
     typedef std::set<SGVec3<unsigned> > TriangleSet;
     TriangleSet _triangleSet;
 
-    void setCurrentMaterial(const SGMaterial* material)
+    void setCurrentMaterial(const BVHMaterial* material)
     {
         _currentMaterial = material;
         _currentMaterialIndex = addMaterial(material);
     }
-    const SGMaterial* getCurrentMaterial() const
+    const BVHMaterial* getCurrentMaterial() const
     {
         return _currentMaterial;
     }
-    unsigned addMaterial(const SGMaterial* material)
+    unsigned addMaterial(const BVHMaterial* material)
     {
         MaterialMap::const_iterator i = _materialMap.find(material);
         if (i != _materialMap.end())
@@ -97,9 +97,9 @@ public:
         return index;
     }
 
-    typedef std::map<const SGMaterial*, unsigned> MaterialMap;
+    typedef std::map<const BVHMaterial*, unsigned> MaterialMap;
     MaterialMap _materialMap;
-    const SGMaterial* _currentMaterial;
+    const BVHMaterial* _currentMaterial;
     unsigned _currentMaterialIndex;
 
     void addTriangle(const SGVec3f& v1, const SGVec3f& v2, const SGVec3f& v3)
index f1a8340ec8ced95e1f4436d639359f8abbd35077..ee6f9eb5915247787fc381dc8fb156aa13cc198e 100644 (file)
@@ -16,6 +16,7 @@ set(HEADERS
     BVHStaticNode.hxx
     BVHStaticTriangle.hxx
     BVHSubTreeCollector.hxx
+    BVHMaterial.hxx
     BVHTransform.hxx
     BVHVisitor.hxx
 )
@@ -32,6 +33,7 @@ set(SOURCES
     BVHStaticNode.cxx
     BVHStaticTriangle.cxx
     BVHSubTreeCollector.cxx
+    BVHMaterial.cxx
     BVHTransform.cxx
 )
 
index 5f252918008214cf3014e28cf00b24a9200ea746..51b2d2dbe12411b582807d8262f5b89f1502542f 100644 (file)
@@ -347,11 +347,11 @@ SGMaterial::read_properties(const SGReaderWriterOptions* options,
     }
 
     // surface values for use with ground reactions
-    solid = props->getBoolValue("solid", true);
-    friction_factor = props->getDoubleValue("friction-factor", 1.0);
-    rolling_friction = props->getDoubleValue("rolling-friction", 0.02);
-    bumpiness = props->getDoubleValue("bumpiness", 0.0);
-    load_resistance = props->getDoubleValue("load-resistance", 1e30);
+    _solid = props->getBoolValue("solid", _solid);
+    _friction_factor = props->getDoubleValue("friction-factor", _friction_factor);
+    _rolling_friction = props->getDoubleValue("rolling-friction", _rolling_friction);
+    _bumpiness = props->getDoubleValue("bumpiness", _bumpiness);
+    _load_resistance = props->getDoubleValue("load-resistance", _load_resistance);
 
     // Taken from default values as used in ac3d
     ambient[0] = props->getDoubleValue("ambient/r", 0.2);
@@ -425,12 +425,6 @@ SGMaterial::init ()
     light_coverage = 0.0;
     building_coverage = 0.0;
 
-    solid = true;
-    friction_factor = 1;
-    rolling_friction = 0.02;
-    bumpiness = 0;
-    load_resistance = 1e30;
-
     shininess = 1.0;
     for (int i = 0; i < 4; i++) {
         ambient[i]  = (i < 3) ? 0.2 : 1.0;
index 3a4afe87e10b76b66df127d45931f8439a3d32be..1f17579052ed04dfdb64293814ea8ed7dd275c41 100644 (file)
@@ -44,6 +44,7 @@ class StateSet;
 
 #include <simgear/structure/SGSharedPtr.hxx>
 #include <simgear/math/SGMath.hxx>
+#include <simgear/bvh/BVHMaterial.hxx>
 
 namespace simgear
 {
@@ -67,7 +68,7 @@ class SGTexturedTriangleBin;
  * defined in the $FG_ROOT/materials.xml file, and can be changed
  * at runtime.
  */
-class SGMaterial : public SGReferenced {
+class SGMaterial : public simgear::BVHMaterial {
 
 public:
 
@@ -254,32 +255,6 @@ 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
-   */
-  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; }
-
-  /**
-   * Get the load resistance
-   */
-  double get_load_resistance () const { return load_resistance; }
-
   /**
    * Get the list of names for this material
    */
@@ -434,21 +409,6 @@ 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;
-
   // material properties
   SGVec4f ambient, diffuse, specular, emission;
   double shininess;
index f544606b089c60a76e747967497014ab0d1de7e3..5be621bf06b4dbd7ff689d2eb77f194456fb917d 100644 (file)
@@ -334,11 +334,11 @@ public:
             std::swap(_geometryBuilder, primitiveFunctor._geometryBuilder);
         }
 
-        void setCurrentMaterial(const SGMaterial* material)
+        void setCurrentMaterial(const BVHMaterial* material)
         {
             _geometryBuilder->setCurrentMaterial(material);
         }
-        const SGMaterial* getCurrentMaterial() const
+        const BVHMaterial* getCurrentMaterial() const
         {
             return _geometryBuilder->getCurrentMaterial();
         }
@@ -384,10 +384,10 @@ public:
     {
     }
 
-    const SGMaterial* pushMaterial(osg::Geode* geode)
+    const BVHMaterial* pushMaterial(osg::Geode* geode)
     {
-        const SGMaterial* oldMaterial = _primitiveFunctor.getCurrentMaterial();
-        const SGMaterial* material = SGMaterialLib::findMaterial(geode);
+        const BVHMaterial* oldMaterial = _primitiveFunctor.getCurrentMaterial();
+        const BVHMaterial* material = SGMaterialLib::findMaterial(geode);
         if (material)
             _primitiveFunctor.setCurrentMaterial(material);
         return oldMaterial;
@@ -403,7 +403,7 @@ public:
         if (hasBoundingVolumeTree(geode))
             return;
 
-        const SGMaterial* oldMaterial = pushMaterial(&geode);
+        const BVHMaterial* oldMaterial = pushMaterial(&geode);
 
         bool flushHere = getNodePath().size() <= 1 || _dumpIntoLeafs;
         if (flushHere) {
@@ -411,7 +411,7 @@ public:
             PFunctor previousPrimitives;
             _primitiveFunctor.swap(previousPrimitives);
 
-            const SGMaterial* mat = previousPrimitives.getCurrentMaterial();
+            const BVHMaterial* mat = previousPrimitives.getCurrentMaterial();
             _primitiveFunctor.setCurrentMaterial(mat);
 
             // walk the children
@@ -458,7 +458,7 @@ public:
         PFunctor previousPrimitives;
         _primitiveFunctor.swap(previousPrimitives);
 
-        const SGMaterial* mat = previousPrimitives.getCurrentMaterial();
+        const BVHMaterial* mat = previousPrimitives.getCurrentMaterial();
         _primitiveFunctor.setCurrentMaterial(mat);
 
         // walk the children