Add computeBound support to TerrainNode and Layer.
This commit is contained in:
@@ -40,6 +40,8 @@ class OSGTERRAIN_EXPORT Layer : public osg::Object
|
||||
|
||||
const Locator* getLocator() const { return _locator.get(); }
|
||||
|
||||
virtual osg::BoundingSphere computeBound() const;
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~Layer();
|
||||
|
||||
@@ -33,8 +33,8 @@ class OSGTERRAIN_EXPORT Locator : public osg::Object
|
||||
|
||||
META_Object(osgTerrain, Locator);
|
||||
|
||||
virtual bool convertLocalToModel(const osg::Vec3d& /*local*/, osg::Vec3d& /*world*/) { return false; };
|
||||
virtual bool convertModelToWorld(const osg::Vec3d& /*world*/, osg::Vec3d& /*local*/) { return false; };
|
||||
virtual bool convertLocalToModel(const osg::Vec3d& /*local*/, osg::Vec3d& /*world*/) const { return false; }
|
||||
virtual bool convertModelToWorld(const osg::Vec3d& /*world*/, osg::Vec3d& /*local*/) const { return false; }
|
||||
|
||||
protected:
|
||||
|
||||
@@ -62,8 +62,8 @@ public:
|
||||
osg::EllipsoidModel* getEllipsoidModel() { return _em.get(); }
|
||||
const osg::EllipsoidModel* getEllipsoidModel() const { return _em.get(); }
|
||||
|
||||
bool convertLocalToModel(const osg::Vec3d& local, osg::Vec3d& world);
|
||||
bool convertModelToWorld(const osg::Vec3d& world, osg::Vec3d& local);
|
||||
bool convertLocalToModel(const osg::Vec3d& local, osg::Vec3d& world) const;
|
||||
bool convertModelToWorld(const osg::Vec3d& world, osg::Vec3d& local) const;
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
@@ -73,6 +73,9 @@ class OSGTERRAIN_EXPORT TerrainNode : public osg::Group
|
||||
osg::TransferFunction* getColorTransferFunction() { return _colorTransferFunction.get(); }
|
||||
const osg::TransferFunction* getColorTransferFunction() const { return _colorTransferFunction.get(); }
|
||||
|
||||
/** Compute the bounding volume of the terrain by computing the union of the bounding volumes of all layers.*/
|
||||
virtual osg::BoundingSphere computeBound() const;
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~TerrainNode();
|
||||
|
||||
@@ -28,6 +28,36 @@ Layer::~Layer()
|
||||
{
|
||||
}
|
||||
|
||||
osg::BoundingSphere Layer::computeBound() const
|
||||
{
|
||||
osg::BoundingSphere bs;
|
||||
if (!getLocator()) return bs;
|
||||
|
||||
osg::Vec3d v;
|
||||
if (getLocator()->convertLocalToModel(osg::Vec3d(0.0,0.0,0.0), v))
|
||||
{
|
||||
bs.expandBy(v);
|
||||
}
|
||||
|
||||
if (getLocator()->convertLocalToModel(osg::Vec3d(1.0,0.0,0.0), v))
|
||||
{
|
||||
bs.expandBy(v);
|
||||
}
|
||||
|
||||
if (getLocator()->convertLocalToModel(osg::Vec3d(1.0,1.0,0.0), v))
|
||||
{
|
||||
bs.expandBy(v);
|
||||
}
|
||||
|
||||
if (getLocator()->convertLocalToModel(osg::Vec3d(0.0,1.0,0.0), v))
|
||||
{
|
||||
bs.expandBy(v);
|
||||
}
|
||||
|
||||
return bs;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// ImageLayer
|
||||
|
||||
@@ -58,7 +58,7 @@ void EllipsoidLocator::setExtents(double longitude, double latitude, double delt
|
||||
_height = height;
|
||||
}
|
||||
|
||||
bool EllipsoidLocator::convertLocalToModel(const osg::Vec3d& local, osg::Vec3d& world)
|
||||
bool EllipsoidLocator::convertLocalToModel(const osg::Vec3d& local, osg::Vec3d& world) const
|
||||
{
|
||||
double longitude = _longitude + local.x() * _deltaLongitude;
|
||||
double latitude = _latitude + local.y() * _deltaLatitude;
|
||||
@@ -70,7 +70,7 @@ bool EllipsoidLocator::convertLocalToModel(const osg::Vec3d& local, osg::Vec3d&
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EllipsoidLocator::convertModelToWorld(const osg::Vec3d& world, osg::Vec3d& local)
|
||||
bool EllipsoidLocator::convertModelToWorld(const osg::Vec3d& world, osg::Vec3d& local) const
|
||||
{
|
||||
double longitude, latitude, height;
|
||||
|
||||
|
||||
@@ -75,3 +75,14 @@ void TerrainNode::setColorTransferFunction(osg::TransferFunction* tf)
|
||||
{
|
||||
_colorTransferFunction = tf;
|
||||
}
|
||||
|
||||
osg::BoundingSphere TerrainNode::computeBound() const
|
||||
{
|
||||
osg::BoundingSphere bs;
|
||||
|
||||
if (_elevationLayer.valid()) bs.expandBy(_elevationLayer->computeBound());
|
||||
|
||||
if (_colorLayer.valid()) bs.expandBy(_colorLayer->computeBound());
|
||||
|
||||
return bs;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user