The bounding volumes in core should not depend on scenery.
Therefore reference material properties relevant for the BVH
tree in BVHMaterial.
{ return _linearVelocity; }
const SGVec3d& getAngularVelocity() const
{ return _angularVelocity; }
- const SGMaterial* getMaterial() const
+ const BVHMaterial* getMaterial() const
{ return _material; }
BVHNode::Id getId() const
{ return _id; }
SGVec3d _normal;
SGVec3d _linearVelocity;
SGVec3d _angularVelocity;
- const SGMaterial* _material;
+ const BVHMaterial* _material;
BVHNode::Id _id;
bool _haveHit;
--- /dev/null
+// 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()
+{
+}
+
+}
--- /dev/null
+// 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
{ return _linearVelocity; }
const SGVec3d& getAngularVelocity() const
{ return _angularVelocity; }
- const SGMaterial* getMaterial() const
+ const BVHMaterial* getMaterial() const
{ return _material; }
BVHNode::Id getId() const
{ return _id; }
SGVec3d _point;
SGVec3d _linearVelocity;
SGVec3d _angularVelocity;
- const SGMaterial* _material;
+ const BVHMaterial* _material;
BVHNode::Id _id;
bool _havePoint;
#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 {
{ 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;
};
}
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())
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)
BVHStaticNode.hxx
BVHStaticTriangle.hxx
BVHSubTreeCollector.hxx
+ BVHMaterial.hxx
BVHTransform.hxx
BVHVisitor.hxx
)
BVHStaticNode.cxx
BVHStaticTriangle.cxx
BVHSubTreeCollector.cxx
+ BVHMaterial.cxx
BVHTransform.cxx
)
}
// 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);
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;
#include <simgear/structure/SGSharedPtr.hxx>
#include <simgear/math/SGMath.hxx>
+#include <simgear/bvh/BVHMaterial.hxx>
namespace simgear
{
* defined in the $FG_ROOT/materials.xml file, and can be changed
* at runtime.
*/
-class SGMaterial : public SGReferenced {
+class SGMaterial : public simgear::BVHMaterial {
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
*/
// 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;
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();
}
{
}
- 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;
if (hasBoundingVolumeTree(geode))
return;
- const SGMaterial* oldMaterial = pushMaterial(&geode);
+ const BVHMaterial* oldMaterial = pushMaterial(&geode);
bool flushHere = getNodePath().size() <= 1 || _dumpIntoLeafs;
if (flushHere) {
PFunctor previousPrimitives;
_primitiveFunctor.swap(previousPrimitives);
- const SGMaterial* mat = previousPrimitives.getCurrentMaterial();
+ const BVHMaterial* mat = previousPrimitives.getCurrentMaterial();
_primitiveFunctor.setCurrentMaterial(mat);
// walk the children
PFunctor previousPrimitives;
_primitiveFunctor.swap(previousPrimitives);
- const SGMaterial* mat = previousPrimitives.getCurrentMaterial();
+ const BVHMaterial* mat = previousPrimitives.getCurrentMaterial();
_primitiveFunctor.setCurrentMaterial(mat);
// walk the children