Added new Node/Drawable::s/getInitialBound and Node/Drawable::s/getComputeBoundCallback

methods and reimplement computeBound so that it passes back a bounding volume rather
than modifying the local one.
This commit is contained in:
Robert Osfield 2005-05-12 14:03:22 +00:00
parent ad2bd31ac8
commit bf4d63f6ea
52 changed files with 337 additions and 377 deletions

View File

@ -418,11 +418,11 @@ void GeoSet::computeNumVerts() const
// just use the base Drawable's PrimitiveFunctor based implementation. // just use the base Drawable's PrimitiveFunctor based implementation.
bool GeoSet::computeBound() const osg::BoundingBox GeoSet::computeBound() const
{ {
_bbox.init(); osg::BoundingBox bbox;
if( _iaformat == IA_OFF && _coords == (Vec3 *)0 ) return false; if( _iaformat == IA_OFF && _coords == (Vec3 *)0 ) return bbox;
if( _numcoords == 0 ) if( _numcoords == 0 )
{ {
@ -430,7 +430,7 @@ bool GeoSet::computeBound() const
} }
if( _numcoords == 0 ) if( _numcoords == 0 )
return false; return bbox;
Vec3 center(0.0f,0.0f,0.0f); Vec3 center(0.0f,0.0f,0.0f);
@ -442,7 +442,7 @@ bool GeoSet::computeBound() const
for( i = 0; i < int(_cindex._size); i++ ) for( i = 0; i < int(_cindex._size); i++ )
{ {
center += _coords[_cindex[i]]; center += _coords[_cindex[i]];
_bbox.expandBy(_coords[_cindex[i]]); bbox.expandBy(_coords[_cindex[i]]);
} }
} }
else else
@ -450,7 +450,7 @@ bool GeoSet::computeBound() const
for( i = 0; i < _numcoords; i++ ) for( i = 0; i < _numcoords; i++ )
{ {
center += _coords[i]; center += _coords[i];
_bbox.expandBy(_coords[i]); bbox.expandBy(_coords[i]);
} }
} }
} }
@ -474,7 +474,7 @@ bool GeoSet::computeBound() const
_iaformat == IA_T4F_C4F_N3F_V4F ? 15 : -1; _iaformat == IA_T4F_C4F_N3F_V4F ? 15 : -1;
if( stride == -1 ) // INTERNAL ERROR!! if( stride == -1 ) // INTERNAL ERROR!!
return false; return bbox;
int offset = int offset =
_iaformat == IA_V2F ? 0 : _iaformat == IA_V2F ? 0 :
@ -518,7 +518,7 @@ bool GeoSet::computeBound() const
float z = ncomp >= 3 ? fptr[2] : 0.0f; float z = ncomp >= 3 ? fptr[2] : 0.0f;
Vec3 vv(x,y,z); Vec3 vv(x,y,z);
center += vv; center += vv;
_bbox.expandBy(vv); bbox.expandBy(vv);
fptr += stride; fptr += stride;
} }
@ -526,9 +526,7 @@ bool GeoSet::computeBound() const
center /= (float)_numcoords; center /= (float)_numcoords;
_bbox_computed=true; return bbox;
return true;
} }
bool GeoSet::checkConsistency() const bool GeoSet::checkConsistency() const
@ -653,7 +651,6 @@ void GeoSet::setNormals( Vec3 *cp, IndexPointer& ip )
{ {
_normals = cp; _normals = cp;
_nindex = ip; _nindex = ip;
_bbox_computed = false;
if( _normal_binding == BIND_OFF ) if( _normal_binding == BIND_OFF )
setNormalBinding( BIND_DEFAULT ); setNormalBinding( BIND_DEFAULT );
} }
@ -692,7 +689,6 @@ void GeoSet::setColors( Vec4 *cp, IndexPointer& ip )
{ {
_colors = cp; _colors = cp;
_colindex = ip; _colindex = ip;
_bbox_computed = false;
if( _color_binding == BIND_OFF ) if( _color_binding == BIND_OFF )
setColorBinding( BIND_DEFAULT ); setColorBinding( BIND_DEFAULT );
} }
@ -733,7 +729,6 @@ void GeoSet::setTextureCoords( Vec2 *cp, IndexPointer& ip )
{ {
_tcoords = cp; _tcoords = cp;
_tindex = ip; _tindex = ip;
_bbox_computed = false;
if( _texture_binding == BIND_OFF ) if( _texture_binding == BIND_OFF )
setTextureBinding( BIND_DEFAULT ); setTextureBinding( BIND_DEFAULT );
} }

View File

@ -360,14 +360,14 @@ class GeoSet : public Drawable
/** convinience function for converting GeoSet's to equivilant Geometry nodes.*/ /** convinience function for converting GeoSet's to equivilant Geometry nodes.*/
Geometry* convertToGeometry(); Geometry* convertToGeometry();
virtual osg::BoundingBox computeBound() const;
protected: protected:
GeoSet& operator = (const GeoSet&) { return *this;} GeoSet& operator = (const GeoSet&) { return *this;}
virtual ~GeoSet(); virtual ~GeoSet();
virtual bool computeBound() const;
ref_ptr<AttributeDeleteFunctor> _adf; ref_ptr<AttributeDeleteFunctor> _adf;
int _numprims; int _numprims;

View File

@ -226,15 +226,11 @@ class Teapot : public osg::Drawable
} }
protected:
virtual ~Teapot() {}
// we need to set up the bounding box of the data too, so that the scene graph knows where this // we need to set up the bounding box of the data too, so that the scene graph knows where this
// objects is, for both positioning the camera at start up, and most importantly for culling. // objects is, for both positioning the camera at start up, and most importantly for culling.
virtual bool computeBound() const virtual osg::BoundingBox computeBound() const
{ {
_bbox.init(); osg::BoundingBox bbox;
// follow is some truely horrible code required to calculate the // follow is some truely horrible code required to calculate the
// bounding box of the teapot. Have used the original code above to do // bounding box of the teapot. Have used the original code above to do
@ -265,13 +261,13 @@ class Teapot : public osg::Drawable
} }
} }
_bbox.expandBy(osg::Vec3(p[j][k][0],p[j][k][1],p[j][k][2])); bbox.expandBy(osg::Vec3(p[j][k][0],p[j][k][1],p[j][k][2]));
_bbox.expandBy(osg::Vec3(q[j][k][0],q[j][k][1],q[j][k][2])); bbox.expandBy(osg::Vec3(q[j][k][0],q[j][k][1],q[j][k][2]));
if (i < 6) if (i < 6)
{ {
_bbox.expandBy(osg::Vec3(r[j][k][0],r[j][k][1],r[j][k][2])); bbox.expandBy(osg::Vec3(r[j][k][0],r[j][k][1],r[j][k][2]));
_bbox.expandBy(osg::Vec3(s[j][k][0],s[j][k][1],s[j][k][2])); bbox.expandBy(osg::Vec3(s[j][k][0],s[j][k][1],s[j][k][2]));
} }
@ -279,9 +275,13 @@ class Teapot : public osg::Drawable
} }
} }
_bbox_computed = true; return bbox;
return true;
} }
protected:
virtual ~Teapot() {}
}; };

View File

@ -97,12 +97,12 @@ class OSG_EXPORT Billboard : public Geode
bool computeMatrix(Matrix& modelview, const Vec3& eye_local, const Vec3& pos_local) const; bool computeMatrix(Matrix& modelview, const Vec3& eye_local, const Vec3& pos_local) const;
virtual BoundingSphere computeBound() const;
protected: protected:
virtual ~Billboard(); virtual ~Billboard();
virtual bool computeBound() const;
enum AxisAligned enum AxisAligned
{ {
AXIAL_ROT_X_AXIS=AXIAL_ROT+1, AXIAL_ROT_X_AXIS=AXIAL_ROT+1,

View File

@ -40,6 +40,12 @@ class OSG_EXPORT BoundingSphere
/** Creates a bounding sphere initialized to the given extents. */ /** Creates a bounding sphere initialized to the given extents. */
BoundingSphere(const Vec3& center,float radius) : _center(center),_radius(radius) {} BoundingSphere(const Vec3& center,float radius) : _center(center),_radius(radius) {}
/** Creates a bounding sphere initialized to the given extents. */
BoundingSphere(const BoundingSphere& bs) : _center(bs._center),_radius(bs._radius) {}
/** Creates a bounding sphere initialized to the given extents. */
BoundingSphere(const BoundingBox& bb) : _center(0.0f,0.0f,0.0f),_radius(-1.0f) { expandBy(bb); }
/** Clear the bounding sphere. Reset to default values. */ /** Clear the bounding sphere. Reset to default values. */
inline void init() inline void init()
{ {

View File

@ -75,12 +75,12 @@ class OSG_EXPORT ClipNode : public Group
/** Set up the local StateSet. */ /** Set up the local StateSet. */
void setLocalStateSetModes(StateAttribute::GLModeValue=StateAttribute::ON); void setLocalStateSetModes(StateAttribute::GLModeValue=StateAttribute::ON);
virtual BoundingSphere computeBound() const;
protected: protected:
virtual ~ClipNode(); virtual ~ClipNode();
virtual bool computeBound() const;
StateAttribute::GLModeValue _value; StateAttribute::GLModeValue _value;
ClipPlaneList _planes; ClipPlaneList _planes;
}; };

View File

@ -59,6 +59,7 @@ class OSG_EXPORT DrawPixels : public Drawable
virtual void drawImplementation(State& state) const; virtual void drawImplementation(State& state) const;
virtual BoundingBox computeBound() const;
protected: protected:
@ -66,8 +67,6 @@ class OSG_EXPORT DrawPixels : public Drawable
virtual ~DrawPixels(); virtual ~DrawPixels();
virtual bool computeBound() const;
Vec3 _position; Vec3 _position;
ref_ptr<Image> _image; ref_ptr<Image> _image;

View File

@ -149,6 +149,12 @@ class OSG_EXPORT Drawable : public Object
StateSet* getOrCreateStateSet(); StateSet* getOrCreateStateSet();
/** Set the intial bounding volume to use when computing the overall bounding volume.*/
void setInitialBound(const osg::BoundingBox& bbox) { _initialBound = bbox; dirtyBound(); }
/** Set the intial bounding volume to use when computing the overall bounding volume.*/
const BoundingBox& getInitialBound() const { return _initialBound; }
/** Dirty the bounding box, forcing a computeBound() on the next call /** Dirty the bounding box, forcing a computeBound() on the next call
* to getBound(). Should be called in the internal geometry of the Drawable * to getBound(). Should be called in the internal geometry of the Drawable
* is modified.*/ * is modified.*/
@ -160,10 +166,37 @@ class OSG_EXPORT Drawable : public Object
*/ */
inline const BoundingBox& getBound() const inline const BoundingBox& getBound() const
{ {
if( !_bbox_computed) if(!_boundingBoxComputed)
computeBound(); {
return _bbox; _boundingBox = _initialBound;
if (_computeBoundCallback.valid())
_boundingBox.expandBy(_computeBoundCallback->computeBound(*this));
else
_boundingBox.expandBy(computeBound());
_boundingBoxComputed = true;
} }
return _boundingBox;
}
/** Compute the bounding box around Drawables's geometry.*/
virtual BoundingBox computeBound() const;
/** Callback to allow users to override the default computation of bounding volume.*/
struct ComputeBoundCallback : public osg::Referenced
{
virtual BoundingBox computeBound(const osg::Drawable&) const = 0;
};
/** Set the compute bound callback to override the default computeBound.*/
void setComputeBoundCallback(ComputeBoundCallback* callback) { _computeBoundCallback = callback; }
/** Get the compute bound callback.*/
ComputeBoundCallback* getComputeBoundCallback() { return _computeBoundCallback.get(); }
/** Get the const compute bound callback.*/
const ComputeBoundCallback* getComputeBoundCallback() const { return _computeBoundCallback.get(); }
/** Set the Shape of the \c Drawable. The shape can be used to /** Set the Shape of the \c Drawable. The shape can be used to
@ -694,9 +727,6 @@ class OSG_EXPORT Drawable : public Object
virtual ~Drawable(); virtual ~Drawable();
/** Compute the bounding box of the drawable. Method must be
implemented by subclasses.*/
virtual bool computeBound() const;
/** set the bounding box .*/ /** set the bounding box .*/
void setBound(const BoundingBox& bb) const; void setBound(const BoundingBox& bb) const;
@ -711,8 +741,10 @@ class OSG_EXPORT Drawable : public Object
ref_ptr<StateSet> _stateset; ref_ptr<StateSet> _stateset;
mutable BoundingBox _bbox; BoundingBox _initialBound;
mutable bool _bbox_computed; ref_ptr<ComputeBoundCallback> _computeBoundCallback;
mutable BoundingBox _boundingBox;
mutable bool _boundingBoxComputed;
ref_ptr<Shape> _shape; ref_ptr<Shape> _shape;

View File

@ -128,20 +128,22 @@ class OSG_EXPORT Geode : public Node
* bounding boxes of the geode's drawables.*/ * bounding boxes of the geode's drawables.*/
inline const BoundingBox& getBoundingBox() const inline const BoundingBox& getBoundingBox() const
{ {
if(!_bsphere_computed) computeBound(); if(!_boundingSphereComputed) getBound();
return _bbox; return _bbox;
} }
virtual BoundingSphere computeBound() const;
/** If State is non-zero, this function releases any associated OpenGL objects for /** If State is non-zero, this function releases any associated OpenGL objects for
* the specified graphics context. Otherwise, releases OpenGL objexts * the specified graphics context. Otherwise, releases OpenGL objexts
* for all graphics contexts. */ * for all graphics contexts. */
virtual void releaseGLObjects(osg::State* = 0) const; virtual void releaseGLObjects(osg::State* = 0) const;
protected: protected:
virtual ~Geode(); virtual ~Geode();
virtual bool computeBound() const;
mutable osg::BoundingBox _bbox; mutable osg::BoundingBox _bbox;
DrawableList _drawables; DrawableList _drawables;

View File

@ -130,7 +130,7 @@ class OSG_EXPORT Group : public Node
virtual ~Group(); virtual ~Group();
virtual bool computeBound() const; virtual BoundingSphere computeBound() const;
virtual void childRemoved(unsigned int /*pos*/, unsigned int /*numChildrenToRemove*/) {} virtual void childRemoved(unsigned int /*pos*/, unsigned int /*numChildrenToRemove*/) {}
virtual void childInserted(unsigned int /*pos*/) {} virtual void childInserted(unsigned int /*pos*/) {}

View File

@ -119,11 +119,11 @@ class OSG_EXPORT LOD : public Group
/** return the list of MinMax ranges for each child.*/ /** return the list of MinMax ranges for each child.*/
inline const RangeList& getRangeList() const { return _rangeList; } inline const RangeList& getRangeList() const { return _rangeList; }
virtual BoundingSphere computeBound() const;
protected : protected :
virtual ~LOD() {} virtual ~LOD() {}
virtual bool computeBound() const;
virtual void childRemoved(unsigned int pos, unsigned int numChildrenToRemove); virtual void childRemoved(unsigned int pos, unsigned int numChildrenToRemove);
virtual void childInserted(unsigned int pos); virtual void childInserted(unsigned int pos);

View File

@ -72,12 +72,12 @@ class OSG_EXPORT LightSource : public Group
/** Set up the local StateSet. */ /** Set up the local StateSet. */
void setLocalStateSetModes(StateAttribute::GLModeValue value = StateAttribute::ON); void setLocalStateSetModes(StateAttribute::GLModeValue value = StateAttribute::ON);
virtual BoundingSphere computeBound() const;
protected: protected:
virtual ~LightSource(); virtual ~LightSource();
virtual bool computeBound() const;
StateAttribute::GLModeValue _value; StateAttribute::GLModeValue _value;
ref_ptr<Light> _light; ref_ptr<Light> _light;

View File

@ -231,22 +231,57 @@ class OSG_EXPORT Node : public Object
/** Return the node's StateSet. returns NULL if a stateset is not attached.*/ /** Return the node's StateSet. returns NULL if a stateset is not attached.*/
inline osg::StateSet* getStateSet() { return _stateset.get(); } inline osg::StateSet* getStateSet() { return _stateset.get(); }
/** return the node's const StateSet. Returns NULL if a stateset is not attached.*/ /** Return the node's const StateSet. Returns NULL if a stateset is not attached.*/
inline const osg::StateSet* getStateSet() const { return _stateset.get(); } inline const osg::StateSet* getStateSet() const { return _stateset.get(); }
/** get the bounding sphere of node. /** Set the intial bounding volume to use when computing the overall bounding volume.*/
Using lazy evaluation computes the bounding sphere if it is 'dirty'.*/ void setInitialBound(const osg::BoundingSphere& bsphere) { _initialBound = bsphere; dirtyBound(); }
inline const BoundingSphere& getBound() const
{
if(!_bsphere_computed) computeBound();
return _bsphere;
}
/** Set the intial bounding volume to use when computing the overall bounding volume.*/
const BoundingSphere& getInitialBound() const { return _initialBound; }
/** Mark this node's bounding sphere dirty. /** Mark this node's bounding sphere dirty.
Forcing it to be computed on the next call to getBound().*/ Forcing it to be computed on the next call to getBound().*/
void dirtyBound(); void dirtyBound();
/** Get the bounding sphere of node.
Using lazy evaluation computes the bounding sphere if it is 'dirty'.*/
inline const BoundingSphere& getBound() const
{
if(!_boundingSphereComputed)
{
_boundingSphere = _initialBound;
if (_computeBoundCallback.valid())
_boundingSphere.expandBy(_computeBoundCallback->computeBound(*this));
else
_boundingSphere.expandBy(computeBound());
_boundingSphereComputed = true;
}
return _boundingSphere;
}
/** Compute the bounding sphere around Node's geometry or children.
This method is automatically called by getBound() when the bounding
sphere has been marked dirty via dirtyBound().*/
virtual BoundingSphere computeBound() const;
/** Callback to allow users to override the default computation of bounding volume.*/
struct ComputeBoundCallback : public osg::Referenced
{
virtual BoundingSphere computeBound(const osg::Node&) const = 0;
};
/** Set the compute bound callback to override the default computeBound.*/
void setComputeBoundCallback(ComputeBoundCallback* callback) { _computeBoundCallback = callback; }
/** Get the compute bound callback.*/
ComputeBoundCallback* getComputeBoundCallback() { return _computeBoundCallback.get(); }
/** Get the const compute bound callback.*/
const ComputeBoundCallback* getComputeBoundCallback() const { return _computeBoundCallback.get(); }
/** If State is non-zero, this function releases any associated OpenGL objects for /** If State is non-zero, this function releases any associated OpenGL objects for
* the specified graphics context. Otherwise, releases OpenGL objexts * the specified graphics context. Otherwise, releases OpenGL objexts
@ -266,13 +301,11 @@ class OSG_EXPORT Node : public Object
virtual ~Node(); virtual ~Node();
/** Compute the bounding sphere around Node's geometry or children.
This method is automatically called by getBound() when the bounding
sphere has been marked dirty via dirtyBound().*/
virtual bool computeBound() const;
mutable BoundingSphere _bsphere; BoundingSphere _initialBound;
mutable bool _bsphere_computed; ref_ptr<ComputeBoundCallback> _computeBoundCallback;
mutable BoundingSphere _boundingSphere;
mutable bool _boundingSphereComputed;
std::string _name; std::string _name;

View File

@ -45,14 +45,13 @@ class OSG_EXPORT OccluderNode : public Group
/** Get the const ConvexPlanarOccluder* attached to a OccluderNode.*/ /** Get the const ConvexPlanarOccluder* attached to a OccluderNode.*/
const ConvexPlanarOccluder* getOccluder() const { return _occluder.get(); } const ConvexPlanarOccluder* getOccluder() const { return _occluder.get(); }
/** Overrides Group's computeBound.*/
virtual BoundingSphere computeBound() const;
protected : protected :
virtual ~OccluderNode() {} virtual ~OccluderNode() {}
/** Overrides Group's computeBound.*/
virtual bool computeBound() const;
ref_ptr<ConvexPlanarOccluder> _occluder; ref_ptr<ConvexPlanarOccluder> _occluder;
}; };

View File

@ -76,12 +76,12 @@ class OSG_EXPORT ProxyNode : public Group
/** Get the object-space radius of the volume enclosed by the ProxyNode.*/ /** Get the object-space radius of the volume enclosed by the ProxyNode.*/
inline float getRadius() const { return _radius; } inline float getRadius() const { return _radius; }
virtual BoundingSphere computeBound() const;
protected : protected :
virtual ~ProxyNode() {} virtual ~ProxyNode() {}
virtual bool computeBound() const;
void expandFileNameListTo(unsigned int pos); void expandFileNameListTo(unsigned int pos);
FileNameList _filenameList; FileNameList _filenameList;

View File

@ -177,14 +177,14 @@ class OSG_EXPORT ShapeDrawable : public Drawable
/** Accept a PrimitiveFunctor and call its methods to tell it about the internal primitives that this Drawable has.*/ /** Accept a PrimitiveFunctor and call its methods to tell it about the internal primitives that this Drawable has.*/
virtual void accept(PrimitiveFunctor& pf) const; virtual void accept(PrimitiveFunctor& pf) const;
virtual BoundingBox computeBound() const;
protected: protected:
ShapeDrawable& operator = (const ShapeDrawable&) { return *this;} ShapeDrawable& operator = (const ShapeDrawable&) { return *this;}
virtual ~ShapeDrawable(); virtual ~ShapeDrawable();
virtual bool computeBound() const;
Vec4 _color; Vec4 _color;
ref_ptr<TessellationHints> _tessellationHints; ref_ptr<TessellationHints> _tessellationHints;

View File

@ -77,12 +77,12 @@ class OSG_EXPORT Switch : public Group
const ValueList& getValueList() const { return _values; } const ValueList& getValueList() const { return _values; }
virtual BoundingSphere computeBound() const;
protected : protected :
virtual ~Switch() {} virtual ~Switch() {}
virtual bool computeBound() const;
// This is effectively a bit mask. // This is effectively a bit mask.
bool _newChildDefaultValue; bool _newChildDefaultValue;
ValueList _values; ValueList _values;

View File

@ -135,16 +135,17 @@ class OSG_EXPORT Transform : public Group
} }
} }
protected :
virtual ~Transform();
/** Overrides Group's computeBound. /** Overrides Group's computeBound.
* There is no need to override in subclasses from osg::Transform * There is no need to override in subclasses from osg::Transform
* since this computeBound() uses the underlying matrix (calling * since this computeBound() uses the underlying matrix (calling
* computeMatrix if required). * computeMatrix if required).
*/ */
virtual bool computeBound() const; virtual BoundingSphere computeBound() const;
protected :
virtual ~Transform();
ReferenceFrame _referenceFrame; ReferenceFrame _referenceFrame;

View File

@ -131,12 +131,12 @@ namespace osgParticle
/// Transform a vector from world to local coordinates, discarding translation (valid only during cull traversal). /// Transform a vector from world to local coordinates, discarding translation (valid only during cull traversal).
inline osg::Vec3 rotateWorldToLocal(const osg::Vec3& P); inline osg::Vec3 rotateWorldToLocal(const osg::Vec3& P);
virtual osg::BoundingSphere computeBound() const;
protected: protected:
virtual ~ParticleProcessor() {} virtual ~ParticleProcessor() {}
ParticleProcessor& operator=(const ParticleProcessor&) { return *this; } ParticleProcessor& operator=(const ParticleProcessor&) { return *this; }
inline bool computeBound() const;
virtual void process(double dt) = 0; virtual void process(double dt) = 0;
private: private:
@ -249,13 +249,6 @@ namespace osgParticle
return _resetTime; return _resetTime;
} }
inline bool ParticleProcessor::computeBound() const
{
_bsphere.init();
_bsphere_computed = true;
return true;
}
inline const osg::Matrix& ParticleProcessor::getLocalToWorldMatrix() inline const osg::Matrix& ParticleProcessor::getLocalToWorldMatrix()
{ {
if (_need_ltw_matrix) { if (_need_ltw_matrix) {

View File

@ -159,13 +159,14 @@ namespace osgParticle
virtual void drawImplementation(osg::State& state) const; virtual void drawImplementation(osg::State& state) const;
virtual osg::BoundingBox computeBound() const;
protected: protected:
virtual ~ParticleSystem(); virtual ~ParticleSystem();
ParticleSystem& operator=(const ParticleSystem&) { return *this; } ParticleSystem& operator=(const ParticleSystem&) { return *this; }
inline virtual bool computeBound() const;
inline void update_bounds(const osg::Vec3& p, float r); inline void update_bounds(const osg::Vec3& p, float r);
void single_pass_render(osg::State& state, const osg::Matrix& modelview) const; void single_pass_render(osg::State& state, const osg::Matrix& modelview) const;
@ -298,18 +299,6 @@ namespace osgParticle
return _last_frame; return _last_frame;
} }
inline bool ParticleSystem::computeBound() const
{
if (!_bounds_computed) {
_bbox = _def_bbox;
} else {
_bbox._min = _bmin;
_bbox._max = _bmax;
}
_bbox_computed = true;
return true;
}
inline void ParticleSystem::update_bounds(const osg::Vec3& p, float r) inline void ParticleSystem::update_bounds(const osg::Vec3& p, float r)
{ {
if (_reset_bounds_flag) { if (_reset_bounds_flag) {

View File

@ -75,11 +75,12 @@ namespace osgParticle
virtual void traverse(osg::NodeVisitor& nv); virtual void traverse(osg::NodeVisitor& nv);
virtual osg::BoundingSphere computeBound() const;
protected: protected:
virtual ~ParticleSystemUpdater() {} virtual ~ParticleSystemUpdater() {}
ParticleSystemUpdater &operator=(const ParticleSystemUpdater &) { return *this; } ParticleSystemUpdater &operator=(const ParticleSystemUpdater &) { return *this; }
inline virtual bool computeBound() const;
private: private:
typedef std::vector<osg::ref_ptr<ParticleSystem> > ParticleSystem_Vector; typedef std::vector<osg::ref_ptr<ParticleSystem> > ParticleSystem_Vector;
@ -90,13 +91,6 @@ namespace osgParticle
// INLINE FUNCTIONS // INLINE FUNCTIONS
inline bool ParticleSystemUpdater::computeBound() const
{
_bsphere.init();
_bsphere_computed = true;
return true;
}
inline bool ParticleSystemUpdater::addParticleSystem(ParticleSystem* ps) inline bool ParticleSystemUpdater::addParticleSystem(ParticleSystem* ps)
{ {
_psv.push_back(ps); _psv.push_back(ps);

View File

@ -100,12 +100,12 @@ class OSGSIM_EXPORT Impostor : public osg::LOD
/** Get a const list of ImpostorSprites attached to this const Impostor. */ /** Get a const list of ImpostorSprites attached to this const Impostor. */
inline const ImpostorSpriteList& getImpostorSpriteList(unsigned int contexID) const { return _impostorSpriteListBuffer[contexID]; } inline const ImpostorSpriteList& getImpostorSpriteList(unsigned int contexID) const { return _impostorSpriteListBuffer[contexID]; }
virtual osg::BoundingSphere computeBound() const;
protected : protected :
virtual ~Impostor() {} virtual ~Impostor() {}
virtual bool computeBound() const;
mutable osg::buffered_object<ImpostorSpriteList> _impostorSpriteListBuffer; mutable osg::buffered_object<ImpostorSpriteList> _impostorSpriteListBuffer;

View File

@ -148,6 +148,8 @@ class OSGSIM_EXPORT ImpostorSprite : public osg::Drawable
// for debugging purposes. // for debugging purposes.
osg::Vec4 _color; osg::Vec4 _color;
virtual osg::BoundingBox computeBound() const;
protected: protected:
ImpostorSprite(const ImpostorSprite&):Drawable() {} ImpostorSprite(const ImpostorSprite&):Drawable() {}
@ -155,8 +157,6 @@ class OSGSIM_EXPORT ImpostorSprite : public osg::Drawable
virtual ~ImpostorSprite(); virtual ~ImpostorSprite();
virtual bool computeBound() const;
Impostor* _parent; Impostor* _parent;
friend class osgSim::ImpostorSpriteManager; friend class osgSim::ImpostorSpriteManager;

View File

@ -82,6 +82,8 @@ class OSGSIM_EXPORT LightPointNode : public osg::Node
osgSim::LightPointSystem* getLightPointSystem() { return _lightSystem.get(); } osgSim::LightPointSystem* getLightPointSystem() { return _lightSystem.get(); }
virtual osg::BoundingSphere computeBound() const;
protected: protected:
~LightPointNode() {} ~LightPointNode() {}
@ -90,8 +92,6 @@ class OSGSIM_EXPORT LightPointNode : public osg::Node
// view frustum check. // view frustum check.
mutable osg::BoundingBox _bbox; mutable osg::BoundingBox _bbox;
virtual bool computeBound() const;
LightPointList _lightPointList; LightPointList _lightPointList;
float _minPixelSize; float _minPixelSize;

View File

@ -284,12 +284,12 @@ public:
return _textureGlyphQuadMap; return _textureGlyphQuadMap;
} }
virtual osg::BoundingBox computeBound() const;
protected: protected:
virtual ~Text(); virtual ~Text();
virtual bool computeBound() const;
Font* getActiveFont(); Font* getActiveFont();
const Font* getActiveFont() const; const Font* getActiveFont() const;

View File

@ -123,7 +123,7 @@ bool Billboard::removeDrawable( Drawable *gset )
// note ref_ptr<> automatically handles decrementing gset's reference count. // note ref_ptr<> automatically handles decrementing gset's reference count.
_drawables.erase(itr); _drawables.erase(itr);
_positionList.erase(pitr); _positionList.erase(pitr);
_bsphere_computed = false; dirtyBound();
return true; return true;
} }
} }
@ -265,41 +265,40 @@ bool Billboard::computeMatrix(Matrix& modelview, const Vec3& eye_local, const Ve
} }
bool Billboard::computeBound() const BoundingSphere Billboard::computeBound() const
{ {
int i; int i;
int ngsets = _drawables.size(); int ngsets = _drawables.size();
if( ngsets == 0 ) return false; if( ngsets == 0 ) return BoundingSphere();
_bsphere._center.set(0.0f,0.0f,0.0f); BoundingSphere bsphere;
bsphere._center.set(0.0f,0.0f,0.0f);
for( i = 0; i < ngsets; i++ ) for( i = 0; i < ngsets; i++ )
{ {
const Drawable *gset = _drawables[i].get(); const Drawable *gset = _drawables[i].get();
const BoundingBox& bbox = gset->getBound(); const BoundingBox& bbox = gset->getBound();
_bsphere._center += bbox.center(); bsphere._center += bbox.center();
_bsphere._center += _positionList[i]; bsphere._center += _positionList[i];
} }
_bsphere._center /= (float)(ngsets); bsphere._center /= (float)(ngsets);
float maxd = 0.0; float maxd = 0.0;
for( i = 0; i < ngsets; ++i ) for( i = 0; i < ngsets; ++i )
{ {
const Drawable *gset = _drawables[i].get(); const Drawable *gset = _drawables[i].get();
const BoundingBox& bbox = gset->getBound(); const BoundingBox& bbox = gset->getBound();
Vec3 local_center = _bsphere._center-_positionList[i]; Vec3 local_center = bsphere._center-_positionList[i];
for(unsigned int c=0;c<8;++c) for(unsigned int c=0;c<8;++c)
{ {
float d = (bbox.corner(c)-local_center).length2(); float d = (bbox.corner(c)-local_center).length2();
if( d > maxd ) maxd = d; if( d > maxd ) maxd = d;
} }
} }
_bsphere._radius = sqrtf(maxd); bsphere._radius = sqrtf(maxd);
_bsphere_computed=true; return bsphere;
return true;
} }

View File

@ -127,7 +127,7 @@ void ClipNode::setLocalStateSetModes(const StateAttribute::GLModeValue value)
setStateSetModes(*_stateset,value); setStateSetModes(*_stateset,value);
} }
bool ClipNode::computeBound() const BoundingSphere ClipNode::computeBound() const
{ {
return Group::computeBound(); return Group::computeBound();
} }

View File

@ -69,10 +69,10 @@ void DrawPixels::getSubImageDimensions(unsigned int& offsetX,unsigned int& offse
} }
bool DrawPixels::computeBound() const BoundingBox DrawPixels::computeBound() const
{ {
// really needs to be dependant of view poistion and projection... will implement simple version right now. // really needs to be dependant of view poistion and projection... will implement simple version right now.
_bbox.init(); BoundingBox bbox;
float diagonal = 0.0f; float diagonal = 0.0f;
if (_useSubImage) if (_useSubImage)
{ {
@ -83,10 +83,9 @@ bool DrawPixels::computeBound() const
diagonal = sqrtf(_image->s()*_image->s()+_image->t()*_image->t()); diagonal = sqrtf(_image->s()*_image->s()+_image->t()*_image->t());
} }
_bbox.expandBy(_position-osg::Vec3(diagonal,diagonal,diagonal)); bbox.expandBy(_position-osg::Vec3(diagonal,diagonal,diagonal));
_bbox.expandBy(_position+osg::Vec3(diagonal,diagonal,diagonal)); bbox.expandBy(_position+osg::Vec3(diagonal,diagonal,diagonal));
_bbox_computed = true; return bbox;
return true;
} }
void DrawPixels::drawImplementation(State&) const void DrawPixels::drawImplementation(State&) const

View File

@ -259,7 +259,7 @@ void Drawable::flushDeletedVertexBufferObjects(unsigned int contextID,double /*c
Drawable::Drawable() Drawable::Drawable()
{ {
_bbox_computed = false; _boundingBoxComputed = false;
// Note, if your are defining a subclass from drawable which is // Note, if your are defining a subclass from drawable which is
// dynamically updated then you should set both the following to // dynamically updated then you should set both the following to
@ -280,8 +280,9 @@ Drawable::Drawable(const Drawable& drawable,const CopyOp& copyop):
Object(drawable,copyop), Object(drawable,copyop),
_parents(), // leave empty as parentList is managed by Geode _parents(), // leave empty as parentList is managed by Geode
_stateset(copyop(drawable._stateset.get())), _stateset(copyop(drawable._stateset.get())),
_bbox(drawable._bbox), _initialBound(drawable._initialBound),
_bbox_computed(drawable._bbox_computed), _boundingBox(drawable._boundingBox),
_boundingBoxComputed(drawable._boundingBoxComputed),
_shape(copyop(drawable._shape.get())), _shape(copyop(drawable._shape.get())),
_supportsDisplayList(drawable._supportsDisplayList), _supportsDisplayList(drawable._supportsDisplayList),
_useDisplayList(drawable._useDisplayList), _useDisplayList(drawable._useDisplayList),
@ -444,9 +445,9 @@ osg::StateSet* Drawable::getOrCreateStateSet()
void Drawable::dirtyBound() void Drawable::dirtyBound()
{ {
if (_bbox_computed) if (_boundingBoxComputed)
{ {
_bbox_computed = false; _boundingBoxComputed = false;
// dirty parent bounding sphere's to ensure that all are valid. // dirty parent bounding sphere's to ensure that all are valid.
for(ParentList::iterator itr=_parents.begin(); for(ParentList::iterator itr=_parents.begin();
@ -724,23 +725,20 @@ struct ComputeBound : public PrimitiveFunctor
BoundingBox _bb; BoundingBox _bb;
}; };
bool Drawable::computeBound() const BoundingBox Drawable::computeBound() const
{ {
ComputeBound cb; ComputeBound cb;
Drawable* non_const_this = const_cast<Drawable*>(this); Drawable* non_const_this = const_cast<Drawable*>(this);
non_const_this->accept(cb); non_const_this->accept(cb);
_bbox = cb._bb; return cb._bb;
_bbox_computed = true;
return true;
} }
void Drawable::setBound(const BoundingBox& bb) const void Drawable::setBound(const BoundingBox& bb) const
{ {
_bbox = bb; _boundingBox = bb;
_bbox_computed = true; _boundingBoxComputed = true;
} }

View File

@ -178,9 +178,9 @@ bool Geode::setDrawable( unsigned int i, Drawable* newDrawable )
} }
bool Geode::computeBound() const BoundingSphere Geode::computeBound() const
{ {
_bsphere.init(); BoundingSphere bsphere;
_bbox.init(); _bbox.init();
@ -194,15 +194,9 @@ bool Geode::computeBound() const
if (_bbox.valid()) if (_bbox.valid())
{ {
_bsphere.expandBy(_bbox); bsphere.expandBy(_bbox);
_bsphere_computed=true;
return true;
}
else
{
_bsphere_computed=true;
return false;
} }
return bsphere;
} }
void Geode::compileDrawables(State& state) void Geode::compileDrawables(State& state)

View File

@ -337,15 +337,12 @@ bool Group::setChild( unsigned int i, Node* newNode )
} }
bool Group::computeBound() const BoundingSphere Group::computeBound() const
{ {
BoundingSphere bsphere;
_bsphere.init();
if (_children.empty()) if (_children.empty())
{ {
_bsphere_computed = true; return bsphere;
return false;
} }
// note, special handling of the case when a child is an Transform, // note, special handling of the case when a child is an Transform,
@ -368,12 +365,11 @@ bool Group::computeBound() const
if (!bb.valid()) if (!bb.valid())
{ {
_bsphere_computed = true; return bsphere;
return false;
} }
_bsphere._center = bb.center(); bsphere._center = bb.center();
_bsphere._radius = 0.0f; bsphere._radius = 0.0f;
for(itr=_children.begin(); for(itr=_children.begin();
itr!=_children.end(); itr!=_children.end();
++itr) ++itr)
@ -381,12 +377,11 @@ bool Group::computeBound() const
const osg::Transform* transform = (*itr)->asTransform(); const osg::Transform* transform = (*itr)->asTransform();
if (!transform || transform->getReferenceFrame()==osg::Transform::RELATIVE_RF) if (!transform || transform->getReferenceFrame()==osg::Transform::RELATIVE_RF)
{ {
_bsphere.expandRadiusBy((*itr)->getBound()); bsphere.expandRadiusBy((*itr)->getBound());
} }
} }
_bsphere_computed = true; return bsphere;
return true;
} }
void Group::releaseGLObjects(osg::State* state) const void Group::releaseGLObjects(osg::State* state) const

View File

@ -84,15 +84,11 @@ void LOD::traverse(NodeVisitor& nv)
} }
} }
bool LOD::computeBound() const BoundingSphere LOD::computeBound() const
{ {
if (_centerMode==USER_DEFINED_CENTER && _radius>=0.0f) if (_centerMode==USER_DEFINED_CENTER && _radius>=0.0f)
{ {
_bsphere._center = _userDefinedCenter; return BoundingSphere(_userDefinedCenter,_radius);
_bsphere._radius = _radius;
_bsphere_computed = true;
return true;
} }
else else
{ {

View File

@ -58,9 +58,9 @@ void LightSource::setLocalStateSetModes(StateAttribute::GLModeValue value)
setStateSetModes(*_stateset,value); setStateSetModes(*_stateset,value);
} }
bool LightSource::computeBound() const BoundingSphere LightSource::computeBound() const
{ {
Group::computeBound(); BoundingSphere bsphere(Group::computeBound());
if (_light.valid() && _referenceFrame==RELATIVE_RF) if (_light.valid() && _referenceFrame==RELATIVE_RF)
{ {
@ -68,11 +68,9 @@ bool LightSource::computeBound() const
if (pos[3]!=0.0f) if (pos[3]!=0.0f)
{ {
float div = 1.0f/pos[3]; float div = 1.0f/pos[3];
_bsphere.expandBy(Vec3(pos[0]*div,pos[1]*div,pos[2]*div)); bsphere.expandBy(Vec3(pos[0]*div,pos[1]*div,pos[2]*div));
} }
} }
_bsphere_computed = true; return bsphere;
return true;
} }

View File

@ -23,7 +23,7 @@ using namespace osg;
Node::Node() Node::Node()
{ {
_bsphere_computed = false; _boundingSphereComputed = false;
_nodeMask = 0xffffffff; _nodeMask = 0xffffffff;
_numChildrenRequiringUpdateTraversal = 0; _numChildrenRequiringUpdateTraversal = 0;
@ -38,8 +38,9 @@ Node::Node()
Node::Node(const Node& node,const CopyOp& copyop): Node::Node(const Node& node,const CopyOp& copyop):
Object(node,copyop), Object(node,copyop),
_bsphere(node._bsphere), _initialBound(node._initialBound),
_bsphere_computed(node._bsphere_computed), _boundingSphere(node._boundingSphere),
_boundingSphereComputed(node._boundingSphereComputed),
_name(node._name), _name(node._name),
_parents(), // leave empty as parentList is managed by Group. _parents(), // leave empty as parentList is managed by Group.
_updateCallback(node._updateCallback), _updateCallback(node._updateCallback),
@ -404,18 +405,17 @@ bool Node::containsOccluderNodes() const
return _numChildrenWithOccluderNodes>0 || dynamic_cast<const OccluderNode*>(this); return _numChildrenWithOccluderNodes>0 || dynamic_cast<const OccluderNode*>(this);
} }
bool Node::computeBound() const BoundingSphere Node::computeBound() const
{ {
_bsphere.init(); return BoundingSphere();
return false;
} }
void Node::dirtyBound() void Node::dirtyBound()
{ {
if (_bsphere_computed) if (_boundingSphereComputed)
{ {
_bsphere_computed = false; _boundingSphereComputed = false;
// dirty parent bounding sphere's to ensure that all are valid. // dirty parent bounding sphere's to ensure that all are valid.
for(ParentList::iterator itr=_parents.begin(); for(ParentList::iterator itr=_parents.begin();

View File

@ -24,9 +24,9 @@ OccluderNode::OccluderNode(const OccluderNode& node,const CopyOp& copyop):
{ {
} }
bool OccluderNode::computeBound() const BoundingSphere OccluderNode::computeBound() const
{ {
bool result = Group::computeBound(); BoundingSphere bsphere(Group::computeBound());
if (getOccluder()) if (getOccluder())
{ {
@ -40,10 +40,8 @@ bool OccluderNode::computeBound() const
} }
if (bb.valid()) if (bb.valid())
{ {
_bsphere.expandBy(bb); bsphere.expandBy(bb);
_bsphere_computed=true;
result = true;
} }
} }
return result; return bsphere;
} }

View File

@ -103,15 +103,11 @@ bool ProxyNode::removeChild( Node *child )
return Group::removeChild(child); return Group::removeChild(child);
} }
bool ProxyNode::computeBound() const BoundingSphere ProxyNode::computeBound() const
{ {
if (_centerMode==USER_DEFINED_CENTER && _radius>=0.0f) if (_centerMode==USER_DEFINED_CENTER && _radius>=0.0f)
{ {
_bsphere._center = _userDefinedCenter; return BoundingSphere(_userDefinedCenter,_radius);
_bsphere._radius = _radius;
_bsphere_computed = true;
return true;
} }
else else
{ {

View File

@ -1787,20 +1787,14 @@ void ShapeDrawable::accept(PrimitiveFunctor& pf) const
} }
bool ShapeDrawable::computeBound() const BoundingBox ShapeDrawable::computeBound() const
{ {
_bbox.init(); BoundingBox bbox;
if (_shape.valid()) if (_shape.valid())
{ {
ComputeBoundShapeVisitor cbsv(_bbox); ComputeBoundShapeVisitor cbsv(bbox);
_shape->accept(cbsv); _shape->accept(cbsv);
_bbox_computed = true; }
return bbox;
return true;
}
return false;
} }

View File

@ -175,13 +175,12 @@ bool Switch::setSingleChildOn(unsigned int pos)
return true; return true;
} }
bool Switch::computeBound() const BoundingSphere Switch::computeBound() const
{ {
_bsphere.init(); BoundingSphere bsphere;
if (_children.empty()) if (_children.empty())
{ {
_bsphere_computed = true; return bsphere;
return false;
} }
// note, special handling of the case when a child is an Transform, // note, special handling of the case when a child is an Transform,
@ -205,12 +204,11 @@ bool Switch::computeBound() const
if (!bb.valid()) if (!bb.valid())
{ {
_bsphere_computed = true; return bsphere;
return false;
} }
_bsphere._center = bb.center(); bsphere._center = bb.center();
_bsphere._radius = 0.0f; bsphere._radius = 0.0f;
for(itr=_children.begin(); for(itr=_children.begin();
itr!=_children.end(); itr!=_children.end();
++itr) ++itr)
@ -219,80 +217,9 @@ bool Switch::computeBound() const
if (!transform || transform->getReferenceFrame()==osg::Transform::RELATIVE_RF) if (!transform || transform->getReferenceFrame()==osg::Transform::RELATIVE_RF)
{ {
if( getChildValue((*itr).get()) == true ) if( getChildValue((*itr).get()) == true )
_bsphere.expandRadiusBy((*itr)->getBound()); bsphere.expandRadiusBy((*itr)->getBound());
} }
} }
return bsphere;
}
_bsphere_computed = true;
return true;
}
#ifdef USE_DEPRECATED_API
void Switch::setValue(int value)
{
switch(value)
{
case(MULTIPLE_CHILDREN_ON):
// do nothing...
break;
case(ALL_CHILDREN_OFF):
{
_newChildDefaultValue = false;
for(ValueList::iterator itr=_values.begin();
itr!=_values.end();
++itr)
{
*itr = false;
}
break;
}
case(ALL_CHILDREN_ON):
{
_newChildDefaultValue = true;
for(ValueList::iterator itr=_values.begin();
itr!=_values.end();
++itr)
{
*itr = true;
}
break;
}
default:
{
for(ValueList::iterator itr=_values.begin();
itr!=_values.end();
++itr)
{
*itr = false;
}
setValue(value,true);
break;
}
}
}
int Switch::getValue() const
{
if (_values.empty()) return ALL_CHILDREN_OFF;
unsigned int noChildrenSwitchedOn=0;
int firstChildSelected=ALL_CHILDREN_OFF;
for(unsigned int i=0; i<_values.size();++i)
{
if (_values[i])
{
++noChildrenSwitchedOn;
if (firstChildSelected==ALL_CHILDREN_OFF) firstChildSelected=i;
}
}
if (noChildrenSwitchedOn>1)
{
if (noChildrenSwitchedOn==_values.size()) return ALL_CHILDREN_ON;
else return MULTIPLE_CHILDREN_ON;
}
return firstChildSelected;
}
#endif

View File

@ -121,9 +121,10 @@ void Transform::setReferenceFrame(ReferenceFrame rf)
setCullingActive(_referenceFrame==RELATIVE_RF); setCullingActive(_referenceFrame==RELATIVE_RF);
} }
bool Transform::computeBound() const BoundingSphere Transform::computeBound() const
{ {
if (!Group::computeBound()) return false; BoundingSphere bsphere = Group::computeBound();
if (!bsphere.valid()) return bsphere;
// note, NULL pointer for NodeVisitor, so compute's need // note, NULL pointer for NodeVisitor, so compute's need
// to handle this case gracefully, normally this should not be a problem. // to handle this case gracefully, normally this should not be a problem.
@ -131,33 +132,34 @@ bool Transform::computeBound() const
computeLocalToWorldMatrix(l2w,NULL); computeLocalToWorldMatrix(l2w,NULL);
Vec3 xdash = _bsphere._center; Vec3 xdash = bsphere._center;
xdash.x() += _bsphere._radius; xdash.x() += bsphere._radius;
xdash = xdash*l2w; xdash = xdash*l2w;
Vec3 ydash = _bsphere._center; Vec3 ydash = bsphere._center;
ydash.y() += _bsphere._radius; ydash.y() += bsphere._radius;
ydash = ydash*l2w; ydash = ydash*l2w;
Vec3 zdash = _bsphere._center; Vec3 zdash = bsphere._center;
zdash.z() += _bsphere._radius; zdash.z() += bsphere._radius;
zdash = zdash*l2w; zdash = zdash*l2w;
_bsphere._center = _bsphere._center*l2w;
xdash -= _bsphere._center; bsphere._center = bsphere._center*l2w;
xdash -= bsphere._center;
float len_xdash = xdash.length(); float len_xdash = xdash.length();
ydash -= _bsphere._center; ydash -= bsphere._center;
float len_ydash = ydash.length(); float len_ydash = ydash.length();
zdash -= _bsphere._center; zdash -= bsphere._center;
float len_zdash = zdash.length(); float len_zdash = zdash.length();
_bsphere._radius = len_xdash; bsphere._radius = len_xdash;
if (_bsphere._radius<len_ydash) _bsphere._radius = len_ydash; if (bsphere._radius<len_ydash) bsphere._radius = len_ydash;
if (_bsphere._radius<len_zdash) _bsphere._radius = len_zdash; if (bsphere._radius<len_zdash) bsphere._radius = len_zdash;
return true; return bsphere;
} }

View File

@ -121,3 +121,9 @@ void osgParticle::ParticleProcessor::traverse(osg::NodeVisitor& nv)
// call the inherited method // call the inherited method
Node::traverse(nv); Node::traverse(nv);
} }
osg::BoundingSphere osgParticle::ParticleProcessor::computeBound() const
{
return osg::BoundingSphere();
}

View File

@ -197,3 +197,15 @@ void osgParticle::ParticleSystem::single_pass_render(osg::State& /*state*/, con
i0->endRender(); i0->endRender();
} }
osg::BoundingBox osgParticle::ParticleSystem::computeBound() const
{
if (!_bounds_computed)
{
return _def_bbox;
} else
{
return osg::BoundingBox(_bmin,_bmax);
}
}

View File

@ -48,3 +48,9 @@ void osgParticle::ParticleSystemUpdater::traverse(osg::NodeVisitor& nv)
} }
Node::traverse(nv); Node::traverse(nv);
} }
osg::BoundingSphere osgParticle::ParticleSystemUpdater::computeBound() const
{
return osg::BoundingSphere();
}

View File

@ -165,15 +165,15 @@ class Logos: public osg::Drawable
return (n != 0); return (n != 0);
} }
virtual osg::BoundingBox computeBound() const
{
return osg::BoundingBox( -1, -1, -1, 1, 1, 1);
}
protected: protected:
Logos& operator = (const Logos&) { return *this;} Logos& operator = (const Logos&) { return *this;}
virtual ~Logos() {} virtual ~Logos() {}
virtual bool computeBound() const
{
_bbox.set( -1, -1, -1, 1, 1, 1);
return true;
}
private : private :
std::vector <osg::Image *> logos[last_position]; std::vector <osg::Image *> logos[last_position];
osg::Viewport *viewport; osg::Viewport *viewport;

View File

@ -101,14 +101,11 @@ void TXPNode::traverse(osg::NodeVisitor& nv)
Group::traverse(nv); Group::traverse(nv);
} }
bool TXPNode::computeBound() const osg::BoundingSphere TXPNode::computeBound() const
{ {
if (getNumChildren() == 0) if (getNumChildren() == 0)
{ {
_bsphere.init(); return osg::BoundingSphere( _extents );
_bsphere.expandBy(_extents);
_bsphere_computed = true;
return true;
} }
return Group::computeBound(); return Group::computeBound();
} }

View File

@ -69,11 +69,12 @@ public:
void setArchive(TXPArchive* archive) { _archive = archive; } void setArchive(TXPArchive* archive) { _archive = archive; }
virtual osg::BoundingSphere computeBound() const;
protected: protected:
virtual ~TXPNode(); virtual ~TXPNode();
virtual bool computeBound() const;
void updateEye(osg::NodeVisitor& nv); void updateEye(osg::NodeVisitor& nv);
void updateSceneGraph(); void updateSceneGraph();

View File

@ -74,7 +74,7 @@ void Impostor::addImpostorSprite(unsigned int contextID, ImpostorSprite* is)
} }
} }
bool Impostor::computeBound() const osg::BoundingSphere Impostor::computeBound() const
{ {
return LOD::computeBound(); return LOD::computeBound();
} }

View File

@ -100,22 +100,20 @@ void ImpostorSprite::drawImplementation(osg::State&) const
} }
bool ImpostorSprite::computeBound() const osg::BoundingBox ImpostorSprite::computeBound() const
{ {
_bbox.init(); osg::BoundingBox bbox;
_bbox.expandBy(_coords[0]); bbox.expandBy(_coords[0]);
_bbox.expandBy(_coords[1]); bbox.expandBy(_coords[1]);
_bbox.expandBy(_coords[2]); bbox.expandBy(_coords[2]);
_bbox.expandBy(_coords[3]); bbox.expandBy(_coords[3]);
_bbox_computed=true; if (!bbox.valid())
if (!_bbox.valid())
{ {
osg::notify(osg::WARN) << "******* ImpostorSprite::computeBound() problem"<<std::endl; osg::notify(osg::WARN) << "******* ImpostorSprite::computeBound() problem"<<std::endl;
} }
return true; return bbox;
} }
void ImpostorSprite::setTexture(osg::Texture2D* tex,int s,int t) void ImpostorSprite::setTexture(osg::Texture2D* tex,int s,int t)

View File

@ -169,9 +169,9 @@ void LightPointDrawable::drawImplementation(osg::State& state) const
} }
bool LightPointDrawable::computeBound() const osg::BoundingBox LightPointDrawable::computeBound() const
{ {
_bbox.init(); osg::BoundingBox bbox;
SizedLightPointList::const_iterator sitr; SizedLightPointList::const_iterator sitr;
for(sitr=_sizedOpaqueLightPointList.begin(); for(sitr=_sizedOpaqueLightPointList.begin();
@ -183,7 +183,7 @@ bool LightPointDrawable::computeBound() const
litr!=lpl.end(); litr!=lpl.end();
++litr) ++litr)
{ {
_bbox.expandBy(litr->second); bbox.expandBy(litr->second);
} }
} }
for(sitr=_sizedAdditiveLightPointList.begin(); for(sitr=_sizedAdditiveLightPointList.begin();
@ -195,7 +195,7 @@ bool LightPointDrawable::computeBound() const
litr!=lpl.end(); litr!=lpl.end();
++litr) ++litr)
{ {
_bbox.expandBy(litr->second); bbox.expandBy(litr->second);
} }
} }
for(sitr=_sizedBlendedLightPointList.begin(); for(sitr=_sizedBlendedLightPointList.begin();
@ -207,9 +207,9 @@ bool LightPointDrawable::computeBound() const
litr!=lpl.end(); litr!=lpl.end();
++litr) ++litr)
{ {
_bbox.expandBy(litr->second); bbox.expandBy(litr->second);
} }
} }
return true; return bbox;
} }

View File

@ -93,9 +93,9 @@ class OSGSIM_EXPORT LightPointDrawable : public osg::Drawable
double getReferenceTime() const { return _referenceTime; } double getReferenceTime() const { return _referenceTime; }
double getReferenceTimeInterval() const { return _referenceTimeInterval; } double getReferenceTimeInterval() const { return _referenceTimeInterval; }
protected: virtual osg::BoundingBox computeBound() const;
virtual bool computeBound() const; protected:
virtual ~LightPointDrawable() {} virtual ~LightPointDrawable() {}

View File

@ -80,15 +80,15 @@ void LightPointNode::removeLightPoint(unsigned int pos)
dirtyBound(); dirtyBound();
} }
bool LightPointNode::computeBound() const osg::BoundingSphere LightPointNode::computeBound() const
{ {
_bsphere.init(); osg::BoundingSphere bsphere;
bsphere.init();
_bbox.init(); _bbox.init();
if (_lightPointList.empty()) if (_lightPointList.empty())
{ {
_bsphere_computed=true; return bsphere;
return false;
} }
@ -101,21 +101,19 @@ bool LightPointNode::computeBound() const
} }
_bsphere.set(_bbox.center(),0.0f); bsphere.set(_bbox.center(),0.0f);
for(itr=_lightPointList.begin(); for(itr=_lightPointList.begin();
itr!=_lightPointList.end(); itr!=_lightPointList.end();
++itr) ++itr)
{ {
osg::Vec3 dv(itr->_position-_bsphere.center()); osg::Vec3 dv(itr->_position-bsphere.center());
float radius = dv.length()+itr->_radius; float radius = dv.length()+itr->_radius;
if (_bsphere.radius()<radius) _bsphere.radius()=radius; if (bsphere.radius()<radius) bsphere.radius()=radius;
} }
_bsphere.radius()+=1.0f; bsphere.radius()+=1.0f;
return bsphere;
_bsphere_computed=true;
return true;
} }

View File

@ -35,9 +35,9 @@ public:
void drawImplementation(osg::State& state) const; void drawImplementation(osg::State& state) const;
protected: virtual osg::BoundingBox computeBound() const;
virtual bool computeBound() const; protected:
private: private:
@ -49,10 +49,11 @@ void SphereSegment::Surface::drawImplementation(osg::State& state) const
_ss->Surface_drawImplementation(state); _ss->Surface_drawImplementation(state);
} }
bool SphereSegment::Surface::computeBound() const osg:: BoundingBox SphereSegment::Surface::computeBound() const
{ {
_bbox_computed = _ss->Surface_computeBound(_bbox); osg:: BoundingBox bbox;
return _bbox_computed; _ss->Surface_computeBound(bbox);
return bbox;
} }
@ -93,7 +94,7 @@ protected:
} }
virtual bool computeBound() const; virtual osg::BoundingBox computeBound() const;
private: private:
@ -105,10 +106,11 @@ void SphereSegment::EdgeLine::drawImplementation(osg::State& state) const
_ss->EdgeLine_drawImplementation(state); _ss->EdgeLine_drawImplementation(state);
} }
bool SphereSegment::EdgeLine::computeBound() const osg::BoundingBox SphereSegment::EdgeLine::computeBound() const
{ {
_bbox_computed = _ss->EdgeLine_computeBound(_bbox); osg::BoundingBox bbox;
return _bbox_computed; _ss->EdgeLine_computeBound(bbox);
return bbox;
} }
@ -141,7 +143,7 @@ public:
protected: protected:
virtual bool computeBound() const; virtual osg::BoundingBox computeBound() const;
private: private:
SphereSegment* _ss; SphereSegment* _ss;
@ -155,10 +157,11 @@ void SphereSegment::Side::drawImplementation(osg::State& state) const
_ss->Side_drawImplementation(state, _planeOrientation, _BoundaryAngle); _ss->Side_drawImplementation(state, _planeOrientation, _BoundaryAngle);
} }
bool SphereSegment::Side::computeBound() const osg::BoundingBox SphereSegment::Side::computeBound() const
{ {
_bbox_computed = _ss->Side_computeBound(_bbox, _planeOrientation, _BoundaryAngle); osg::BoundingBox bbox;
return _bbox_computed; _ss->Side_computeBound(bbox, _planeOrientation, _BoundaryAngle);
return bbox;
} }
@ -199,7 +202,7 @@ protected:
//getOrCreateStateSet()->setAttributeAndModes(new osg::LineWidth(2.0),osg::StateAttribute::OFF); //getOrCreateStateSet()->setAttributeAndModes(new osg::LineWidth(2.0),osg::StateAttribute::OFF);
} }
virtual bool computeBound() const; virtual osg::BoundingBox computeBound() const;
private: private:
SphereSegment* _ss; SphereSegment* _ss;
@ -211,10 +214,11 @@ void SphereSegment::Spoke::drawImplementation(osg::State& state) const
_ss->Spoke_drawImplementation(state, _azAngle, _elevAngle); _ss->Spoke_drawImplementation(state, _azAngle, _elevAngle);
} }
bool SphereSegment::Spoke::computeBound() const osg::BoundingBox SphereSegment::Spoke::computeBound() const
{ {
_bbox_computed = _ss->Spoke_computeBound(_bbox, _azAngle, _elevAngle); osg::BoundingBox bbox;
return _bbox_computed; _ss->Spoke_computeBound(bbox, _azAngle, _elevAngle);
return bbox;
} }
SphereSegment::SphereSegment(const osg::Vec3& centre, float radius, const osg::Vec3& vec, float azRange, SphereSegment::SphereSegment(const osg::Vec3& centre, float radius, const osg::Vec3& vec, float azRange,

View File

@ -222,9 +222,9 @@ void Text::setDrawMode(unsigned int mode)
} }
bool Text::computeBound() const osg::BoundingBox Text::computeBound() const
{ {
_bbox.init(); osg::BoundingBox bbox;
if (_textBB.valid()) if (_textBB.valid())
{ {
@ -238,16 +238,15 @@ bool Text::computeBound() const
else else
{ {
osg::Matrix& matrix = _autoTransformCache[i]._matrix; osg::Matrix& matrix = _autoTransformCache[i]._matrix;
_bbox.expandBy(osg::Vec3(_textBB.xMin(),_textBB.yMin(),_textBB.zMin())*matrix); bbox.expandBy(osg::Vec3(_textBB.xMin(),_textBB.yMin(),_textBB.zMin())*matrix);
_bbox.expandBy(osg::Vec3(_textBB.xMax(),_textBB.yMin(),_textBB.zMin())*matrix); bbox.expandBy(osg::Vec3(_textBB.xMax(),_textBB.yMin(),_textBB.zMin())*matrix);
_bbox.expandBy(osg::Vec3(_textBB.xMax(),_textBB.yMax(),_textBB.zMin())*matrix); bbox.expandBy(osg::Vec3(_textBB.xMax(),_textBB.yMax(),_textBB.zMin())*matrix);
_bbox.expandBy(osg::Vec3(_textBB.xMin(),_textBB.yMax(),_textBB.zMin())*matrix); bbox.expandBy(osg::Vec3(_textBB.xMin(),_textBB.yMax(),_textBB.zMin())*matrix);
} }
} }
} }
_bbox_computed = true; return bbox;
return true;
} }
Font* Text::getActiveFont() Font* Text::getActiveFont()