Added computation of the bounding volume of osg::OccluderNodes.
Added support for osg::BoundingSphere::expandBy*(osg::BoundingBox) and have added osg::BoundingSphere/Box::valid() which deprecates isValid(), this is to be more consistent with other classes in the OSG.
This commit is contained in:
@@ -107,6 +107,8 @@ osg::Node* createOccluder(const osg::Vec3& v1,const osg::Vec3& v2,const osg::Vec
|
||||
|
||||
geoset->setPrimType(osg::GeoSet::QUADS);
|
||||
geoset->setNumPrims(1);
|
||||
// geoset->setPrimType(osg::GeoSet::POINTS);
|
||||
// geoset->setNumPrims(4);
|
||||
|
||||
osg::Geode* geode = osgNew osg::Geode;
|
||||
geode->addDrawable(geoset);
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
#include <osg/BoundingSphere>
|
||||
#include <osg/BoundingBox>
|
||||
|
||||
using namespace osg;
|
||||
|
||||
void BoundingSphere::expandBy(const Vec3& v)
|
||||
{
|
||||
if (isValid())
|
||||
if (valid())
|
||||
{
|
||||
Vec3 dv = v-_center;
|
||||
float r = dv.length();
|
||||
@@ -13,7 +14,7 @@ void BoundingSphere::expandBy(const Vec3& v)
|
||||
float dr = (r-_radius)*0.5f;
|
||||
_center += dv*(dr/r);
|
||||
_radius += dr;
|
||||
} // else do nothing as vertex is within sphere.
|
||||
} // else do nothing as vertex is within sphere.
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -25,7 +26,7 @@ void BoundingSphere::expandBy(const Vec3& v)
|
||||
|
||||
void BoundingSphere::expandRadiusBy(const Vec3& v)
|
||||
{
|
||||
if (isValid())
|
||||
if (valid())
|
||||
{
|
||||
float r = (v-_center).length();
|
||||
if (r>_radius) _radius = r;
|
||||
@@ -41,15 +42,14 @@ void BoundingSphere::expandRadiusBy(const Vec3& v)
|
||||
|
||||
void BoundingSphere::expandBy(const BoundingSphere& sh)
|
||||
{
|
||||
if (sh.isValid())
|
||||
if (sh.valid())
|
||||
{
|
||||
if (isValid())
|
||||
if (valid())
|
||||
{
|
||||
Vec3 dv = sh._center-_center;
|
||||
float dv_len = dv.length();
|
||||
if (dv_len+sh._radius>_radius)
|
||||
{
|
||||
|
||||
Vec3 e1 = _center-(dv*(_radius/dv_len));
|
||||
Vec3 e2 = sh._center+(dv*(sh._radius/dv_len));
|
||||
_center = (e1+e2)*0.5f;
|
||||
@@ -68,9 +68,9 @@ void BoundingSphere::expandBy(const BoundingSphere& sh)
|
||||
|
||||
void BoundingSphere::expandRadiusBy(const BoundingSphere& sh)
|
||||
{
|
||||
if (sh.isValid())
|
||||
if (sh.valid())
|
||||
{
|
||||
if (isValid())
|
||||
if (valid())
|
||||
{
|
||||
float r = (sh._center-_center).length()+sh._radius;
|
||||
if (r>_radius) _radius = r;
|
||||
@@ -83,3 +83,51 @@ void BoundingSphere::expandRadiusBy(const BoundingSphere& sh)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BoundingSphere::expandBy(const BoundingBox& bb)
|
||||
{
|
||||
if (bb.valid())
|
||||
{
|
||||
if (valid())
|
||||
{
|
||||
BoundingBox newbb(bb);
|
||||
|
||||
for(unsigned int c=0;c<8;++c)
|
||||
{
|
||||
Vec3 v = bb.corner(c)-_center; // get the direction vector from corner
|
||||
v.normalize(); // normalise it.
|
||||
v *= -_radius; // move the vector in the opposite direction distance radius.
|
||||
v += _center; // move to absolute position.
|
||||
newbb.expandBy(v); // add it into the new bounding box.
|
||||
}
|
||||
|
||||
_center = newbb.center();
|
||||
_radius = newbb.radius();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
_center = bb.center();
|
||||
_radius = bb.radius();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BoundingSphere::expandRadiusBy(const BoundingBox& bb)
|
||||
{
|
||||
if (bb.valid())
|
||||
{
|
||||
if (valid())
|
||||
{
|
||||
for(unsigned int c=0;c<8;++c)
|
||||
{
|
||||
expandRadiusBy(bb.corner(c));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_center = bb.center();
|
||||
_radius = bb.radius();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,25 +111,9 @@ const bool Geode::computeBound() const
|
||||
bb.expandBy((*itr)->getBound());
|
||||
}
|
||||
|
||||
if (bb.isValid())
|
||||
if (bb.valid())
|
||||
{
|
||||
|
||||
_bsphere._center = bb.center();
|
||||
_bsphere._radius = 0.0f;
|
||||
|
||||
for(itr=_drawables.begin();
|
||||
itr!=_drawables.end();
|
||||
++itr)
|
||||
{
|
||||
const BoundingBox& bbox = (*itr)->getBound();
|
||||
for(unsigned int c=0;c<8;++c)
|
||||
{
|
||||
_bsphere.expandRadiusBy(bbox.corner(c));
|
||||
}
|
||||
}
|
||||
|
||||
// if (_occluder.valid()) _occluder->computeBound(_bsphere);
|
||||
|
||||
_bsphere.expandBy(bb);
|
||||
_bsphere_computed=true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -11,3 +11,27 @@ OccluderNode::OccluderNode(const OccluderNode& node,const CopyOp& copyop):
|
||||
_occluder(dynamic_cast<ConvexPlanerOccluder*>(copyop(node._occluder.get())))
|
||||
{
|
||||
}
|
||||
|
||||
const bool OccluderNode::computeBound() const
|
||||
{
|
||||
bool result = Group::computeBound();
|
||||
|
||||
if (getOccluder())
|
||||
{
|
||||
BoundingBox bb;
|
||||
const ConvexPlanerPolygon::VertexList& vertexList = getOccluder()->getOccluder().getVertexList();
|
||||
for(ConvexPlanerPolygon::VertexList::const_iterator itr=vertexList.begin();
|
||||
itr!=vertexList.end();
|
||||
++itr)
|
||||
{
|
||||
bb.expandBy(*itr);
|
||||
}
|
||||
if (bb.valid())
|
||||
{
|
||||
_bsphere.expandBy(bb);
|
||||
_bsphere_computed=true;
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user