diff --git a/VisualStudio/osgPlugins/osg/dot_osg.dsp b/VisualStudio/osgPlugins/osg/dot_osg.dsp index 686bb61ac..e93e1e45b 100755 --- a/VisualStudio/osgPlugins/osg/dot_osg.dsp +++ b/VisualStudio/osgPlugins/osg/dot_osg.dsp @@ -114,6 +114,10 @@ SOURCE=..\..\..\src\osgPlugins\osg\ColorMatrix.cpp # End Source File # Begin Source File +SOURCE=..\..\..\src\osgPlugins\osg\ConvexPlanerPolygon.cpp +# End Source File +# Begin Source File + SOURCE=..\..\..\src\osgPlugins\osg\CullFace.cpp # End Source File # Begin Source File diff --git a/include/osg/BoundingBox b/include/osg/BoundingBox index ffcfa6d82..8e35745de 100644 --- a/include/osg/BoundingBox +++ b/include/osg/BoundingBox @@ -57,6 +57,11 @@ class SG_EXPORT BoundingBox return _max.x()>=_min.x(); } + inline const bool valid() const + { + return _max.x()>=_min.x(); + } + inline void set (float xmin,float ymin,float zmin, float xmax,float ymax,float zmax) { diff --git a/include/osg/BoundingSphere b/include/osg/BoundingSphere index 29994d0d6..1f39176ea 100644 --- a/include/osg/BoundingSphere +++ b/include/osg/BoundingSphere @@ -10,6 +10,8 @@ namespace osg { +class BoundingBox; + /** General purpose bounding sphere class for enclosing nodes/objects/vertices. Used to bound internal osg::Node's in the scene, to assist in view frustum culling etc. Similar in function to BoundingBox @@ -40,6 +42,10 @@ class SG_EXPORT BoundingSphere false if the bounding sphere is effectively unset.*/ inline const bool isValid() const { return _radius>=0.0f; } + /** return true if the bounding sphere contains valid values, + false if the bounding sphere is effectively unset.*/ + inline const bool valid() const { return _radius>=0.0f; } + /** set bounding sphere.*/ inline void set(const Vec3& center,float radius) { @@ -86,6 +92,17 @@ class SG_EXPORT BoundingSphere If this sphere is empty then move the centrer to v and set radius to 0. */ void expandRadiusBy(const BoundingSphere& sh); + /** If incomming box is outwith the sphere expand to ecompass incomming box. + calculates the combination of movement of center and radius which + minimizes the radius increase. If this boz is empty then + move the centrer to v and set radius to 0.*/ + void expandBy(const BoundingBox& bb); + + /** If incomming box is outwith the sphere expand radius to ecompass incomming box. + Unlike update, does not move the center, just increasing the radius. + If this sphere is empty then move the centrer to v and set radius to 0. */ + void expandRadiusBy(const BoundingBox& bb); + /** return true is vertex v is within the sphere.*/ inline const bool contains(const Vec3& v) const { diff --git a/include/osg/ConvexPlanerOccluder b/include/osg/ConvexPlanerOccluder index 4c68c1670..8f3e2f94c 100644 --- a/include/osg/ConvexPlanerOccluder +++ b/include/osg/ConvexPlanerOccluder @@ -6,7 +6,7 @@ #define OSG_CONVEXPLANEROCCLUDER 1 #include -#include +#include namespace osg { @@ -14,14 +14,18 @@ class OccluderVolume; /** A class for representing convex clipping volumes made up. * When adding planes, their normals should point inwards (into the volume) */ -class SG_EXPORT ConvexPlanerOccluder : public Referenced +class SG_EXPORT ConvexPlanerOccluder : public Object { public: - inline ConvexPlanerOccluder() {} + ConvexPlanerOccluder():Object() {} + ConvexPlanerOccluder(const ConvexPlanerOccluder& cpo,const CopyOp& copyop=CopyOp::SHALLOW_COPY): + Object(cpo,copyop), + _occluder(cpo._occluder), + _holeList(cpo._holeList) {} - + META_Object(osg,ConvexPlanerOccluder) void setOccluder(const ConvexPlanerPolygon& cpp) { _occluder = cpp; } @@ -47,9 +51,7 @@ class SG_EXPORT ConvexPlanerOccluder : public Referenced protected: - float _area; - Vec3 _center; - Vec3 _normal; + ~ConvexPlanerOccluder() {} ConvexPlanerPolygon _occluder; HoleList _holeList; diff --git a/include/osg/OccluderNode b/include/osg/OccluderNode index 7f9d5580b..842ea38bd 100644 --- a/include/osg/OccluderNode +++ b/include/osg/OccluderNode @@ -41,6 +41,9 @@ class SG_EXPORT OccluderNode : public Group virtual ~OccluderNode() {} + /** Override's Group's computeBound.*/ + virtual const bool computeBound() const; + ref_ptr _occluder; }; diff --git a/src/osgPlugins/osg/ConvexPlanerOccluder.cpp b/src/osgPlugins/osg/ConvexPlanerOccluder.cpp new file mode 100644 index 000000000..e1af03967 --- /dev/null +++ b/src/osgPlugins/osg/ConvexPlanerOccluder.cpp @@ -0,0 +1,174 @@ +#if defined(_MSC_VER) + #pragma warning( disable : 4786 ) +#endif + +#include "osg/ConvexPlanerOccluder" +#include "osg/Types" +#include "osg/Notify" + +#include "osgDB/Registry" +#include "osgDB/Input" +#include "osgDB/Output" + +using namespace osg; +using namespace osgDB; + +// forward declare functions to use later. +bool ConvexPlanerOccluder_readLocalData(Object& obj, Input& fr); +bool ConvexPlanerOccluder_writeLocalData(const Object& obj, Output& fw); + +// register the read and write functions with the osgDB::Registry. +RegisterDotOsgWrapperProxy g_ConvexPlanerOccluderFuncProxy +( + osgNew osg::ConvexPlanerOccluder, + "ConvexPlanerOccluder", + "Object ConvexPlanerOccluder", + &ConvexPlanerOccluder_readLocalData, + &ConvexPlanerOccluder_writeLocalData, + DotOsgWrapper::READ_AND_WRITE +); + +bool ConvexPlanerOccluder_readLocalData(Object& obj, Input& fr) +{ + bool iteratorAdvanced = false; + + ConvexPlanerOccluder& cpo = static_cast(obj); + + + bool matchFirst; + if ((matchFirst=fr.matchSequence("Occluder {")) || fr.matchSequence("Occluder %i {")) + { + + ConvexPlanerPolygon& cpp = cpo.getOccluder(); + ConvexPlanerPolygon::VertexList& vertexList = cpp.getVertexList(); + + // set up coordinates. + int entry = fr[0].getNoNestedBrackets(); + + if (matchFirst) + { + fr += 2; + } + else + { + int capacity; + fr[1].getInt(capacity); + + vertexList.reserve(capacity); + + fr += 3; + } + + while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) + { + Vec3 v; + if (fr[0].getFloat(v.x()) && fr[1].getFloat(v.y()) && fr[2].getFloat(v.z())) + { + fr += 3; + vertexList.push_back(v); + } + else + { + ++fr; + } + } + iteratorAdvanced = true; + ++fr; + + } + + ConvexPlanerOccluder::HoleList& holeList = cpo.getHoleList(); + + while ((matchFirst=fr.matchSequence("Hole {")) || fr.matchSequence("Hole %i {")) + { + holeList.push_back(ConvexPlanerPolygon()); + + ConvexPlanerPolygon& cpp = holeList.back(); + ConvexPlanerPolygon::VertexList& vertexList = cpp.getVertexList(); + + // set up coordinates. + int entry = fr[0].getNoNestedBrackets(); + + if (matchFirst) + { + fr += 2; + } + else + { + int capacity; + fr[1].getInt(capacity); + + vertexList.reserve(capacity); + + fr += 3; + } + + while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) + { + Vec3 v; + if (fr[0].getFloat(v.x()) && fr[1].getFloat(v.y()) && fr[2].getFloat(v.z())) + { + fr += 3; + vertexList.push_back(v); + } + else + { + ++fr; + } + } + iteratorAdvanced = true; + ++fr; + + } + + return iteratorAdvanced; +} + + +bool ConvexPlanerOccluder_writeLocalData(const Object& obj, Output& fw) +{ + const ConvexPlanerOccluder& cpo = static_cast(obj); + + // write out the occluder polygon. + { + const ConvexPlanerPolygon::VertexList& vertexList = cpo.getOccluder().getVertexList(); + + fw.indent() << "Occluder " << vertexList.size()<< "{"<< std::endl; + fw.moveIn(); + + for(ConvexPlanerPolygon::VertexList::const_iterator itr=vertexList.begin(); + itr!=vertexList.end(); + ++itr) + { + fw.indent() << (*itr)[0] << ' ' << (*itr)[1] << ' ' << (*itr)[2] << std::endl; + } + + fw.moveOut(); + fw.indent()<<"}"<< std::endl; + } + + // write out any holes. + const ConvexPlanerOccluder::HoleList& holeList = cpo.getHoleList(); + for(ConvexPlanerOccluder::HoleList::const_iterator holeItr=holeList.begin(); + holeItr!=holeList.end(); + ++holeItr) + { + const ConvexPlanerPolygon::VertexList& vertexList = holeItr->getVertexList(); + + fw.indent() << "Hole " << vertexList.size() << "{"<< std::endl; + fw.moveIn(); + + for(ConvexPlanerPolygon::VertexList::const_iterator itr=vertexList.begin(); + itr!=vertexList.end(); + ++itr) + { + fw.indent() << (*itr)[0] << ' ' << (*itr)[1] << ' ' << (*itr)[2] << std::endl; + } + + fw.moveOut(); + fw.indent()<<"}"<< std::endl; + } + + + return true; +} diff --git a/src/osgPlugins/osg/Makefile b/src/osgPlugins/osg/Makefile index 2b7391a7e..06dc0ee2c 100644 --- a/src/osgPlugins/osg/Makefile +++ b/src/osgPlugins/osg/Makefile @@ -6,7 +6,7 @@ CXXFILES =\ Billboard.cpp\ ClipPlane.cpp\ ColorMask.cpp\ - ColorMatrix.cpp\ + ConvexPlanerOccluder.cpp\ CullFace.cpp\ Depth.cpp\ Drawable.cpp\ diff --git a/src/osgPlugins/osg/OccluderNode.cpp b/src/osgPlugins/osg/OccluderNode.cpp index 6d9e635ec..66117b079 100644 --- a/src/osgPlugins/osg/OccluderNode.cpp +++ b/src/osgPlugins/osg/OccluderNode.cpp @@ -16,7 +16,7 @@ RegisterDotOsgWrapperProxy g_OccluderNodeProxy ( osgNew osg::OccluderNode, "OccluderNode", - "Object Node Group OccluderNode", + "Object Node OccluderNode Group", &OccluderNode_readLocalData, &OccluderNode_writeLocalData ); @@ -26,6 +26,16 @@ bool OccluderNode_readLocalData(Object& obj, Input& fr) bool iteratorAdvanced = false; OccluderNode& occludernode = static_cast(obj); + + static ref_ptr s_occluder = osgNew ConvexPlanerOccluder; + + ConvexPlanerOccluder* tmpOccluder = static_cast(fr.readObjectOfType(*s_occluder)); + + if (tmpOccluder) + { + occludernode.setOccluder(tmpOccluder); + iteratorAdvanced = true; + } return iteratorAdvanced; } @@ -33,7 +43,12 @@ bool OccluderNode_readLocalData(Object& obj, Input& fr) bool OccluderNode_writeLocalData(const Object& obj, Output& fw) { - const OccluderNode& occludenode = static_cast(obj); + const OccluderNode& occludernode = static_cast(obj); + + if (occludernode.getOccluder()) + { + fw.writeObject(*occludernode.getOccluder()); + } return true; }