From bf4d63f6eaa8e61e7fae62a481a2a6c1c1b83248 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 12 May 2005 14:03:22 +0000 Subject: [PATCH] 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. --- applications/osgconv/GeoSet.cpp | 23 +++--- applications/osgconv/GeoSet.h | 4 +- examples/osgteapot/osgteapot.cpp | 24 +++--- include/osg/Billboard | 4 +- include/osg/BoundingSphere | 6 ++ include/osg/ClipNode | 4 +- include/osg/DrawPixels | 5 +- include/osg/Drawable | 50 ++++++++++--- include/osg/Geode | 6 +- include/osg/Group | 2 +- include/osg/LOD | 4 +- include/osg/LightSource | 4 +- include/osg/Node | 61 ++++++++++++---- include/osg/OccluderNode | 5 +- include/osg/ProxyNode | 4 +- include/osg/ShapeDrawable | 4 +- include/osg/Switch | 4 +- include/osg/Transform | 11 +-- include/osgParticle/ParticleProcessor | 11 +-- include/osgParticle/ParticleSystem | 15 +--- include/osgParticle/ParticleSystemUpdater | 10 +-- include/osgSim/Impostor | 4 +- include/osgSim/ImpostorSprite | 4 +- include/osgSim/LightPointNode | 4 +- include/osgText/Text | 4 +- src/osg/Billboard.cpp | 23 +++--- src/osg/ClipNode.cpp | 2 +- src/osg/DrawPixels.cpp | 11 ++- src/osg/Drawable.cpp | 22 +++--- src/osg/Geode.cpp | 16 ++-- src/osg/Group.cpp | 21 ++---- src/osg/LOD.cpp | 8 +- src/osg/LightSource.cpp | 10 +-- src/osg/Node.cpp | 16 ++-- src/osg/OccluderNode.cpp | 10 +-- src/osg/ProxyNode.cpp | 8 +- src/osg/ShapeDrawable.cpp | 14 +--- src/osg/Switch.cpp | 89 ++--------------------- src/osg/Transform.cpp | 34 +++++---- src/osgParticle/ParticleProcessor.cpp | 6 ++ src/osgParticle/ParticleSystem.cpp | 12 +++ src/osgParticle/ParticleSystemUpdater.cpp | 6 ++ src/osgPlugins/logo/ReaderWriterLOGO.cpp | 10 +-- src/osgPlugins/txp/TXPNode.cpp | 7 +- src/osgPlugins/txp/TXPNode.h | 3 +- src/osgSim/Impostor.cpp | 2 +- src/osgSim/ImpostorSprite.cpp | 18 ++--- src/osgSim/LightPointDrawable.cpp | 12 +-- src/osgSim/LightPointDrawable.h | 4 +- src/osgSim/LightPointNode.cpp | 20 +++-- src/osgSim/SphereSegment.cpp | 38 +++++----- src/osgText/Text.cpp | 15 ++-- 52 files changed, 337 insertions(+), 377 deletions(-) diff --git a/applications/osgconv/GeoSet.cpp b/applications/osgconv/GeoSet.cpp index 6eeb7c3cd..a3acae69b 100644 --- a/applications/osgconv/GeoSet.cpp +++ b/applications/osgconv/GeoSet.cpp @@ -418,11 +418,11 @@ void GeoSet::computeNumVerts() const // 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 ) { @@ -430,7 +430,7 @@ bool GeoSet::computeBound() const } if( _numcoords == 0 ) - return false; + return bbox; Vec3 center(0.0f,0.0f,0.0f); @@ -442,7 +442,7 @@ bool GeoSet::computeBound() const for( i = 0; i < int(_cindex._size); i++ ) { center += _coords[_cindex[i]]; - _bbox.expandBy(_coords[_cindex[i]]); + bbox.expandBy(_coords[_cindex[i]]); } } else @@ -450,7 +450,7 @@ bool GeoSet::computeBound() const for( i = 0; i < _numcoords; 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; if( stride == -1 ) // INTERNAL ERROR!! - return false; + return bbox; int offset = _iaformat == IA_V2F ? 0 : @@ -518,7 +518,7 @@ bool GeoSet::computeBound() const float z = ncomp >= 3 ? fptr[2] : 0.0f; Vec3 vv(x,y,z); center += vv; - _bbox.expandBy(vv); + bbox.expandBy(vv); fptr += stride; } @@ -526,9 +526,7 @@ bool GeoSet::computeBound() const center /= (float)_numcoords; - _bbox_computed=true; - - return true; + return bbox; } bool GeoSet::checkConsistency() const @@ -653,7 +651,6 @@ void GeoSet::setNormals( Vec3 *cp, IndexPointer& ip ) { _normals = cp; _nindex = ip; - _bbox_computed = false; if( _normal_binding == BIND_OFF ) setNormalBinding( BIND_DEFAULT ); } @@ -692,7 +689,6 @@ void GeoSet::setColors( Vec4 *cp, IndexPointer& ip ) { _colors = cp; _colindex = ip; - _bbox_computed = false; if( _color_binding == BIND_OFF ) setColorBinding( BIND_DEFAULT ); } @@ -733,7 +729,6 @@ void GeoSet::setTextureCoords( Vec2 *cp, IndexPointer& ip ) { _tcoords = cp; _tindex = ip; - _bbox_computed = false; if( _texture_binding == BIND_OFF ) setTextureBinding( BIND_DEFAULT ); } diff --git a/applications/osgconv/GeoSet.h b/applications/osgconv/GeoSet.h index ef73508df..f85cd44df 100644 --- a/applications/osgconv/GeoSet.h +++ b/applications/osgconv/GeoSet.h @@ -360,14 +360,14 @@ class GeoSet : public Drawable /** convinience function for converting GeoSet's to equivilant Geometry nodes.*/ Geometry* convertToGeometry(); + virtual osg::BoundingBox computeBound() const; + protected: GeoSet& operator = (const GeoSet&) { return *this;} virtual ~GeoSet(); - virtual bool computeBound() const; - ref_ptr _adf; int _numprims; diff --git a/examples/osgteapot/osgteapot.cpp b/examples/osgteapot/osgteapot.cpp index 6faa1e154..77e5d1726 100644 --- a/examples/osgteapot/osgteapot.cpp +++ b/examples/osgteapot/osgteapot.cpp @@ -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 // 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 // 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(q[j][k][0],q[j][k][1],q[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])); if (i < 6) { - _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(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])); } @@ -279,9 +275,13 @@ class Teapot : public osg::Drawable } } - _bbox_computed = true; - return true; + return bbox; } + + protected: + + virtual ~Teapot() {} + }; diff --git a/include/osg/Billboard b/include/osg/Billboard index bea3509e1..20d1a345e 100644 --- a/include/osg/Billboard +++ b/include/osg/Billboard @@ -97,12 +97,12 @@ class OSG_EXPORT Billboard : public Geode bool computeMatrix(Matrix& modelview, const Vec3& eye_local, const Vec3& pos_local) const; + virtual BoundingSphere computeBound() const; + protected: virtual ~Billboard(); - virtual bool computeBound() const; - enum AxisAligned { AXIAL_ROT_X_AXIS=AXIAL_ROT+1, diff --git a/include/osg/BoundingSphere b/include/osg/BoundingSphere index 9e501ed57..d0846a33b 100644 --- a/include/osg/BoundingSphere +++ b/include/osg/BoundingSphere @@ -40,6 +40,12 @@ class OSG_EXPORT BoundingSphere /** Creates a bounding sphere initialized to the given extents. */ 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. */ inline void init() { diff --git a/include/osg/ClipNode b/include/osg/ClipNode index bd8d0337d..79f005556 100644 --- a/include/osg/ClipNode +++ b/include/osg/ClipNode @@ -75,12 +75,12 @@ class OSG_EXPORT ClipNode : public Group /** Set up the local StateSet. */ void setLocalStateSetModes(StateAttribute::GLModeValue=StateAttribute::ON); + virtual BoundingSphere computeBound() const; + protected: virtual ~ClipNode(); - virtual bool computeBound() const; - StateAttribute::GLModeValue _value; ClipPlaneList _planes; }; diff --git a/include/osg/DrawPixels b/include/osg/DrawPixels index 77439eb5f..c3259ca7d 100644 --- a/include/osg/DrawPixels +++ b/include/osg/DrawPixels @@ -59,15 +59,14 @@ class OSG_EXPORT DrawPixels : public Drawable virtual void drawImplementation(State& state) const; - + virtual BoundingBox computeBound() const; + protected: DrawPixels& operator = (const DrawPixels&) { return *this;} virtual ~DrawPixels(); - virtual bool computeBound() const; - Vec3 _position; ref_ptr _image; diff --git a/include/osg/Drawable b/include/osg/Drawable index dcad58516..bc3bcbbda 100644 --- a/include/osg/Drawable +++ b/include/osg/Drawable @@ -149,6 +149,12 @@ class OSG_EXPORT Drawable : public Object 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 * to getBound(). Should be called in the internal geometry of the Drawable * is modified.*/ @@ -160,12 +166,39 @@ class OSG_EXPORT Drawable : public Object */ inline const BoundingBox& getBound() const { - if( !_bbox_computed) - computeBound(); - return _bbox; + if(!_boundingBoxComputed) + { + _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 * speed up collision detection or as a guide for procedural * geometry generation. @@ -694,9 +727,6 @@ class OSG_EXPORT Drawable : public Object virtual ~Drawable(); - /** Compute the bounding box of the drawable. Method must be - implemented by subclasses.*/ - virtual bool computeBound() const; /** set the bounding box .*/ void setBound(const BoundingBox& bb) const; @@ -711,10 +741,12 @@ class OSG_EXPORT Drawable : public Object ref_ptr _stateset; - mutable BoundingBox _bbox; - mutable bool _bbox_computed; + BoundingBox _initialBound; + ref_ptr _computeBoundCallback; + mutable BoundingBox _boundingBox; + mutable bool _boundingBoxComputed; - ref_ptr _shape; + ref_ptr _shape; bool _supportsDisplayList; bool _useDisplayList; diff --git a/include/osg/Geode b/include/osg/Geode index 2eb66f067..cc8765de1 100644 --- a/include/osg/Geode +++ b/include/osg/Geode @@ -128,20 +128,22 @@ class OSG_EXPORT Geode : public Node * bounding boxes of the geode's drawables.*/ inline const BoundingBox& getBoundingBox() const { - if(!_bsphere_computed) computeBound(); + if(!_boundingSphereComputed) getBound(); return _bbox; } + virtual BoundingSphere computeBound() const; + /** If State is non-zero, this function releases any associated OpenGL objects for * the specified graphics context. Otherwise, releases OpenGL objexts * for all graphics contexts. */ virtual void releaseGLObjects(osg::State* = 0) const; + protected: virtual ~Geode(); - virtual bool computeBound() const; mutable osg::BoundingBox _bbox; DrawableList _drawables; diff --git a/include/osg/Group b/include/osg/Group index 285191b1e..3afb9022a 100644 --- a/include/osg/Group +++ b/include/osg/Group @@ -130,7 +130,7 @@ class OSG_EXPORT Group : public Node virtual ~Group(); - virtual bool computeBound() const; + virtual BoundingSphere computeBound() const; virtual void childRemoved(unsigned int /*pos*/, unsigned int /*numChildrenToRemove*/) {} virtual void childInserted(unsigned int /*pos*/) {} diff --git a/include/osg/LOD b/include/osg/LOD index 9290325fb..3aa5ec4b3 100644 --- a/include/osg/LOD +++ b/include/osg/LOD @@ -119,11 +119,11 @@ class OSG_EXPORT LOD : public Group /** return the list of MinMax ranges for each child.*/ inline const RangeList& getRangeList() const { return _rangeList; } + virtual BoundingSphere computeBound() const; + protected : virtual ~LOD() {} - virtual bool computeBound() const; - virtual void childRemoved(unsigned int pos, unsigned int numChildrenToRemove); virtual void childInserted(unsigned int pos); diff --git a/include/osg/LightSource b/include/osg/LightSource index 6a15b7223..37469c886 100644 --- a/include/osg/LightSource +++ b/include/osg/LightSource @@ -72,12 +72,12 @@ class OSG_EXPORT LightSource : public Group /** Set up the local StateSet. */ void setLocalStateSetModes(StateAttribute::GLModeValue value = StateAttribute::ON); + virtual BoundingSphere computeBound() const; + protected: virtual ~LightSource(); - virtual bool computeBound() const; - StateAttribute::GLModeValue _value; ref_ptr _light; diff --git a/include/osg/Node b/include/osg/Node index c7df1892d..5015a413c 100644 --- a/include/osg/Node +++ b/include/osg/Node @@ -231,22 +231,57 @@ class OSG_EXPORT Node : public Object /** Return the node's StateSet. returns NULL if a stateset is not attached.*/ 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(); } - /** get the bounding sphere of node. - Using lazy evaluation computes the bounding sphere if it is 'dirty'.*/ - inline const BoundingSphere& getBound() const - { - if(!_bsphere_computed) computeBound(); - return _bsphere; - } + /** Set the intial bounding volume to use when computing the overall bounding volume.*/ + void setInitialBound(const osg::BoundingSphere& bsphere) { _initialBound = bsphere; dirtyBound(); } + /** 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. Forcing it to be computed on the next call to getBound().*/ 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 * the specified graphics context. Otherwise, releases OpenGL objexts @@ -266,13 +301,11 @@ class OSG_EXPORT Node : public Object 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; - mutable bool _bsphere_computed; + BoundingSphere _initialBound; + ref_ptr _computeBoundCallback; + mutable BoundingSphere _boundingSphere; + mutable bool _boundingSphereComputed; std::string _name; diff --git a/include/osg/OccluderNode b/include/osg/OccluderNode index a5559a96a..d436640c9 100644 --- a/include/osg/OccluderNode +++ b/include/osg/OccluderNode @@ -45,14 +45,13 @@ class OSG_EXPORT OccluderNode : public Group /** Get the const ConvexPlanarOccluder* attached to a OccluderNode.*/ const ConvexPlanarOccluder* getOccluder() const { return _occluder.get(); } + /** Overrides Group's computeBound.*/ + virtual BoundingSphere computeBound() const; protected : virtual ~OccluderNode() {} - /** Overrides Group's computeBound.*/ - virtual bool computeBound() const; - ref_ptr _occluder; }; diff --git a/include/osg/ProxyNode b/include/osg/ProxyNode index c3808ad96..20f42f032 100644 --- a/include/osg/ProxyNode +++ b/include/osg/ProxyNode @@ -76,12 +76,12 @@ class OSG_EXPORT ProxyNode : public Group /** Get the object-space radius of the volume enclosed by the ProxyNode.*/ inline float getRadius() const { return _radius; } + virtual BoundingSphere computeBound() const; + protected : virtual ~ProxyNode() {} - virtual bool computeBound() const; - void expandFileNameListTo(unsigned int pos); FileNameList _filenameList; diff --git a/include/osg/ShapeDrawable b/include/osg/ShapeDrawable index 8f21e5038..c77f096f2 100644 --- a/include/osg/ShapeDrawable +++ b/include/osg/ShapeDrawable @@ -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.*/ virtual void accept(PrimitiveFunctor& pf) const; + virtual BoundingBox computeBound() const; + protected: ShapeDrawable& operator = (const ShapeDrawable&) { return *this;} virtual ~ShapeDrawable(); - virtual bool computeBound() const; - Vec4 _color; ref_ptr _tessellationHints; diff --git a/include/osg/Switch b/include/osg/Switch index 86769ff80..2e5e09f4a 100644 --- a/include/osg/Switch +++ b/include/osg/Switch @@ -77,12 +77,12 @@ class OSG_EXPORT Switch : public Group const ValueList& getValueList() const { return _values; } + virtual BoundingSphere computeBound() const; + protected : virtual ~Switch() {} - virtual bool computeBound() const; - // This is effectively a bit mask. bool _newChildDefaultValue; ValueList _values; diff --git a/include/osg/Transform b/include/osg/Transform index 1f8c8984f..e6b4723aa 100644 --- a/include/osg/Transform +++ b/include/osg/Transform @@ -135,16 +135,17 @@ class OSG_EXPORT Transform : public Group } } - protected : - - virtual ~Transform(); - /** Overrides Group's computeBound. * There is no need to override in subclasses from osg::Transform * since this computeBound() uses the underlying matrix (calling * computeMatrix if required). */ - virtual bool computeBound() const; + virtual BoundingSphere computeBound() const; + + protected : + + virtual ~Transform(); + ReferenceFrame _referenceFrame; diff --git a/include/osgParticle/ParticleProcessor b/include/osgParticle/ParticleProcessor index 5113d56f4..806299535 100644 --- a/include/osgParticle/ParticleProcessor +++ b/include/osgParticle/ParticleProcessor @@ -131,12 +131,12 @@ namespace osgParticle /// Transform a vector from world to local coordinates, discarding translation (valid only during cull traversal). inline osg::Vec3 rotateWorldToLocal(const osg::Vec3& P); + virtual osg::BoundingSphere computeBound() const; + protected: virtual ~ParticleProcessor() {} ParticleProcessor& operator=(const ParticleProcessor&) { return *this; } - inline bool computeBound() const; - virtual void process(double dt) = 0; private: @@ -249,13 +249,6 @@ namespace osgParticle return _resetTime; } - inline bool ParticleProcessor::computeBound() const - { - _bsphere.init(); - _bsphere_computed = true; - return true; - } - inline const osg::Matrix& ParticleProcessor::getLocalToWorldMatrix() { if (_need_ltw_matrix) { diff --git a/include/osgParticle/ParticleSystem b/include/osgParticle/ParticleSystem index cf887a7ee..c31dace6c 100644 --- a/include/osgParticle/ParticleSystem +++ b/include/osgParticle/ParticleSystem @@ -159,13 +159,14 @@ namespace osgParticle virtual void drawImplementation(osg::State& state) const; + virtual osg::BoundingBox computeBound() const; + protected: virtual ~ParticleSystem(); ParticleSystem& operator=(const ParticleSystem&) { return *this; } - inline virtual bool computeBound() const; inline void update_bounds(const osg::Vec3& p, float r); void single_pass_render(osg::State& state, const osg::Matrix& modelview) const; @@ -298,18 +299,6 @@ namespace osgParticle 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) { if (_reset_bounds_flag) { diff --git a/include/osgParticle/ParticleSystemUpdater b/include/osgParticle/ParticleSystemUpdater index 74f552a0b..c248e8074 100644 --- a/include/osgParticle/ParticleSystemUpdater +++ b/include/osgParticle/ParticleSystemUpdater @@ -75,11 +75,12 @@ namespace osgParticle virtual void traverse(osg::NodeVisitor& nv); + virtual osg::BoundingSphere computeBound() const; + protected: virtual ~ParticleSystemUpdater() {} ParticleSystemUpdater &operator=(const ParticleSystemUpdater &) { return *this; } - inline virtual bool computeBound() const; private: typedef std::vector > ParticleSystem_Vector; @@ -90,13 +91,6 @@ namespace osgParticle // INLINE FUNCTIONS - inline bool ParticleSystemUpdater::computeBound() const - { - _bsphere.init(); - _bsphere_computed = true; - return true; - } - inline bool ParticleSystemUpdater::addParticleSystem(ParticleSystem* ps) { _psv.push_back(ps); diff --git a/include/osgSim/Impostor b/include/osgSim/Impostor index 30596d1ab..a6306eeb8 100644 --- a/include/osgSim/Impostor +++ b/include/osgSim/Impostor @@ -100,12 +100,12 @@ class OSGSIM_EXPORT Impostor : public osg::LOD /** Get a const list of ImpostorSprites attached to this const Impostor. */ inline const ImpostorSpriteList& getImpostorSpriteList(unsigned int contexID) const { return _impostorSpriteListBuffer[contexID]; } + virtual osg::BoundingSphere computeBound() const; + protected : virtual ~Impostor() {} - virtual bool computeBound() const; - mutable osg::buffered_object _impostorSpriteListBuffer; diff --git a/include/osgSim/ImpostorSprite b/include/osgSim/ImpostorSprite index 077e42298..9cf02990b 100644 --- a/include/osgSim/ImpostorSprite +++ b/include/osgSim/ImpostorSprite @@ -148,6 +148,8 @@ class OSGSIM_EXPORT ImpostorSprite : public osg::Drawable // for debugging purposes. osg::Vec4 _color; + virtual osg::BoundingBox computeBound() const; + protected: ImpostorSprite(const ImpostorSprite&):Drawable() {} @@ -155,8 +157,6 @@ class OSGSIM_EXPORT ImpostorSprite : public osg::Drawable virtual ~ImpostorSprite(); - virtual bool computeBound() const; - Impostor* _parent; friend class osgSim::ImpostorSpriteManager; diff --git a/include/osgSim/LightPointNode b/include/osgSim/LightPointNode index 3481af8ca..33d158a35 100644 --- a/include/osgSim/LightPointNode +++ b/include/osgSim/LightPointNode @@ -82,6 +82,8 @@ class OSGSIM_EXPORT LightPointNode : public osg::Node osgSim::LightPointSystem* getLightPointSystem() { return _lightSystem.get(); } + virtual osg::BoundingSphere computeBound() const; + protected: ~LightPointNode() {} @@ -90,8 +92,6 @@ class OSGSIM_EXPORT LightPointNode : public osg::Node // view frustum check. mutable osg::BoundingBox _bbox; - virtual bool computeBound() const; - LightPointList _lightPointList; float _minPixelSize; diff --git a/include/osgText/Text b/include/osgText/Text index 48e4f256d..4c2a1b67f 100644 --- a/include/osgText/Text +++ b/include/osgText/Text @@ -284,12 +284,12 @@ public: return _textureGlyphQuadMap; } + virtual osg::BoundingBox computeBound() const; + protected: virtual ~Text(); - virtual bool computeBound() const; - Font* getActiveFont(); const Font* getActiveFont() const; diff --git a/src/osg/Billboard.cpp b/src/osg/Billboard.cpp index 2b8edd016..a78a37429 100644 --- a/src/osg/Billboard.cpp +++ b/src/osg/Billboard.cpp @@ -123,7 +123,7 @@ bool Billboard::removeDrawable( Drawable *gset ) // note ref_ptr<> automatically handles decrementing gset's reference count. _drawables.erase(itr); _positionList.erase(pitr); - _bsphere_computed = false; + dirtyBound(); 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 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++ ) { const Drawable *gset = _drawables[i].get(); const BoundingBox& bbox = gset->getBound(); - _bsphere._center += bbox.center(); - _bsphere._center += _positionList[i]; + bsphere._center += bbox.center(); + bsphere._center += _positionList[i]; } - _bsphere._center /= (float)(ngsets); + bsphere._center /= (float)(ngsets); float maxd = 0.0; for( i = 0; i < ngsets; ++i ) { const Drawable *gset = _drawables[i].get(); 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) { float d = (bbox.corner(c)-local_center).length2(); if( d > maxd ) maxd = d; } } - _bsphere._radius = sqrtf(maxd); + bsphere._radius = sqrtf(maxd); - _bsphere_computed=true; - - return true; + return bsphere; } diff --git a/src/osg/ClipNode.cpp b/src/osg/ClipNode.cpp index b3a20fd06..111c63e75 100644 --- a/src/osg/ClipNode.cpp +++ b/src/osg/ClipNode.cpp @@ -127,7 +127,7 @@ void ClipNode::setLocalStateSetModes(const StateAttribute::GLModeValue value) setStateSetModes(*_stateset,value); } -bool ClipNode::computeBound() const +BoundingSphere ClipNode::computeBound() const { return Group::computeBound(); } diff --git a/src/osg/DrawPixels.cpp b/src/osg/DrawPixels.cpp index 696c2e4c1..94410e55c 100644 --- a/src/osg/DrawPixels.cpp +++ b/src/osg/DrawPixels.cpp @@ -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. - _bbox.init(); + BoundingBox bbox; float diagonal = 0.0f; if (_useSubImage) { @@ -83,10 +83,9 @@ bool DrawPixels::computeBound() const 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_computed = true; - return true; + bbox.expandBy(_position-osg::Vec3(diagonal,diagonal,diagonal)); + bbox.expandBy(_position+osg::Vec3(diagonal,diagonal,diagonal)); + return bbox; } void DrawPixels::drawImplementation(State&) const diff --git a/src/osg/Drawable.cpp b/src/osg/Drawable.cpp index 9deb7eaf7..e925f9fea 100644 --- a/src/osg/Drawable.cpp +++ b/src/osg/Drawable.cpp @@ -259,7 +259,7 @@ void Drawable::flushDeletedVertexBufferObjects(unsigned int contextID,double /*c Drawable::Drawable() { - _bbox_computed = false; + _boundingBoxComputed = false; // Note, if your are defining a subclass from drawable which is // 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), _parents(), // leave empty as parentList is managed by Geode _stateset(copyop(drawable._stateset.get())), - _bbox(drawable._bbox), - _bbox_computed(drawable._bbox_computed), + _initialBound(drawable._initialBound), + _boundingBox(drawable._boundingBox), + _boundingBoxComputed(drawable._boundingBoxComputed), _shape(copyop(drawable._shape.get())), _supportsDisplayList(drawable._supportsDisplayList), _useDisplayList(drawable._useDisplayList), @@ -444,9 +445,9 @@ osg::StateSet* Drawable::getOrCreateStateSet() void Drawable::dirtyBound() { - if (_bbox_computed) + if (_boundingBoxComputed) { - _bbox_computed = false; + _boundingBoxComputed = false; // dirty parent bounding sphere's to ensure that all are valid. for(ParentList::iterator itr=_parents.begin(); @@ -724,23 +725,20 @@ struct ComputeBound : public PrimitiveFunctor BoundingBox _bb; }; -bool Drawable::computeBound() const +BoundingBox Drawable::computeBound() const { ComputeBound cb; Drawable* non_const_this = const_cast(this); non_const_this->accept(cb); - _bbox = cb._bb; - _bbox_computed = true; - - return true; + return cb._bb; } void Drawable::setBound(const BoundingBox& bb) const { - _bbox = bb; - _bbox_computed = true; + _boundingBox = bb; + _boundingBoxComputed = true; } diff --git a/src/osg/Geode.cpp b/src/osg/Geode.cpp index 75f866549..137d4fa72 100644 --- a/src/osg/Geode.cpp +++ b/src/osg/Geode.cpp @@ -178,11 +178,11 @@ bool Geode::setDrawable( unsigned int i, Drawable* newDrawable ) } -bool Geode::computeBound() const +BoundingSphere Geode::computeBound() const { - _bsphere.init(); + BoundingSphere bsphere; - _bbox.init(); + _bbox.init(); DrawableList::const_iterator itr; for(itr=_drawables.begin(); @@ -194,15 +194,9 @@ bool Geode::computeBound() const if (_bbox.valid()) { - _bsphere.expandBy(_bbox); - _bsphere_computed=true; - return true; - } - else - { - _bsphere_computed=true; - return false; + bsphere.expandBy(_bbox); } + return bsphere; } void Geode::compileDrawables(State& state) diff --git a/src/osg/Group.cpp b/src/osg/Group.cpp index c605fdddc..6ccc22d50 100644 --- a/src/osg/Group.cpp +++ b/src/osg/Group.cpp @@ -337,15 +337,12 @@ bool Group::setChild( unsigned int i, Node* newNode ) } -bool Group::computeBound() const +BoundingSphere Group::computeBound() const { - - - _bsphere.init(); + BoundingSphere bsphere; if (_children.empty()) { - _bsphere_computed = true; - return false; + return bsphere; } // note, special handling of the case when a child is an Transform, @@ -368,12 +365,11 @@ bool Group::computeBound() const if (!bb.valid()) { - _bsphere_computed = true; - return false; + return bsphere; } - _bsphere._center = bb.center(); - _bsphere._radius = 0.0f; + bsphere._center = bb.center(); + bsphere._radius = 0.0f; for(itr=_children.begin(); itr!=_children.end(); ++itr) @@ -381,12 +377,11 @@ bool Group::computeBound() const const osg::Transform* transform = (*itr)->asTransform(); if (!transform || transform->getReferenceFrame()==osg::Transform::RELATIVE_RF) { - _bsphere.expandRadiusBy((*itr)->getBound()); + bsphere.expandRadiusBy((*itr)->getBound()); } } - _bsphere_computed = true; - return true; + return bsphere; } void Group::releaseGLObjects(osg::State* state) const diff --git a/src/osg/LOD.cpp b/src/osg/LOD.cpp index b1fcc1b8b..d88ddcbeb 100644 --- a/src/osg/LOD.cpp +++ b/src/osg/LOD.cpp @@ -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) { - _bsphere._center = _userDefinedCenter; - _bsphere._radius = _radius; - _bsphere_computed = true; - - return true; + return BoundingSphere(_userDefinedCenter,_radius); } else { diff --git a/src/osg/LightSource.cpp b/src/osg/LightSource.cpp index 39f2c8af8..5901ef1fb 100644 --- a/src/osg/LightSource.cpp +++ b/src/osg/LightSource.cpp @@ -58,9 +58,9 @@ void LightSource::setLocalStateSetModes(StateAttribute::GLModeValue value) setStateSetModes(*_stateset,value); } -bool LightSource::computeBound() const +BoundingSphere LightSource::computeBound() const { - Group::computeBound(); + BoundingSphere bsphere(Group::computeBound()); if (_light.valid() && _referenceFrame==RELATIVE_RF) { @@ -68,11 +68,9 @@ bool LightSource::computeBound() const if (pos[3]!=0.0f) { 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 true; + return bsphere; } diff --git a/src/osg/Node.cpp b/src/osg/Node.cpp index a31ce83a9..c53753f9b 100644 --- a/src/osg/Node.cpp +++ b/src/osg/Node.cpp @@ -23,7 +23,7 @@ using namespace osg; Node::Node() { - _bsphere_computed = false; + _boundingSphereComputed = false; _nodeMask = 0xffffffff; _numChildrenRequiringUpdateTraversal = 0; @@ -38,8 +38,9 @@ Node::Node() Node::Node(const Node& node,const CopyOp& copyop): Object(node,copyop), - _bsphere(node._bsphere), - _bsphere_computed(node._bsphere_computed), + _initialBound(node._initialBound), + _boundingSphere(node._boundingSphere), + _boundingSphereComputed(node._boundingSphereComputed), _name(node._name), _parents(), // leave empty as parentList is managed by Group. _updateCallback(node._updateCallback), @@ -404,18 +405,17 @@ bool Node::containsOccluderNodes() const return _numChildrenWithOccluderNodes>0 || dynamic_cast(this); } -bool Node::computeBound() const +BoundingSphere Node::computeBound() const { - _bsphere.init(); - return false; + return BoundingSphere(); } void Node::dirtyBound() { - if (_bsphere_computed) + if (_boundingSphereComputed) { - _bsphere_computed = false; + _boundingSphereComputed = false; // dirty parent bounding sphere's to ensure that all are valid. for(ParentList::iterator itr=_parents.begin(); diff --git a/src/osg/OccluderNode.cpp b/src/osg/OccluderNode.cpp index a6363d01c..4b7987330 100644 --- a/src/osg/OccluderNode.cpp +++ b/src/osg/OccluderNode.cpp @@ -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()) { @@ -40,10 +40,8 @@ bool OccluderNode::computeBound() const } if (bb.valid()) { - _bsphere.expandBy(bb); - _bsphere_computed=true; - result = true; + bsphere.expandBy(bb); } } - return result; + return bsphere; } diff --git a/src/osg/ProxyNode.cpp b/src/osg/ProxyNode.cpp index 0a73ec43f..8e4951881 100644 --- a/src/osg/ProxyNode.cpp +++ b/src/osg/ProxyNode.cpp @@ -103,15 +103,11 @@ bool ProxyNode::removeChild( Node *child ) return Group::removeChild(child); } -bool ProxyNode::computeBound() const +BoundingSphere ProxyNode::computeBound() const { if (_centerMode==USER_DEFINED_CENTER && _radius>=0.0f) { - _bsphere._center = _userDefinedCenter; - _bsphere._radius = _radius; - _bsphere_computed = true; - - return true; + return BoundingSphere(_userDefinedCenter,_radius); } else { diff --git a/src/osg/ShapeDrawable.cpp b/src/osg/ShapeDrawable.cpp index 432f854d2..836d82baf 100644 --- a/src/osg/ShapeDrawable.cpp +++ b/src/osg/ShapeDrawable.cpp @@ -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()) { - ComputeBoundShapeVisitor cbsv(_bbox); + ComputeBoundShapeVisitor cbsv(bbox); _shape->accept(cbsv); - _bbox_computed = true; - - return true; } - - return false; + return bbox; } diff --git a/src/osg/Switch.cpp b/src/osg/Switch.cpp index cff0d2fbe..4afdfcd66 100644 --- a/src/osg/Switch.cpp +++ b/src/osg/Switch.cpp @@ -175,13 +175,12 @@ bool Switch::setSingleChildOn(unsigned int pos) return true; } -bool Switch::computeBound() const +BoundingSphere Switch::computeBound() const { - _bsphere.init(); + BoundingSphere bsphere; if (_children.empty()) { - _bsphere_computed = true; - return false; + return bsphere; } // note, special handling of the case when a child is an Transform, @@ -205,12 +204,11 @@ bool Switch::computeBound() const if (!bb.valid()) { - _bsphere_computed = true; - return false; + return bsphere; } - _bsphere._center = bb.center(); - _bsphere._radius = 0.0f; + bsphere._center = bb.center(); + bsphere._radius = 0.0f; for(itr=_children.begin(); itr!=_children.end(); ++itr) @@ -219,80 +217,9 @@ bool Switch::computeBound() const if (!transform || transform->getReferenceFrame()==osg::Transform::RELATIVE_RF) { if( getChildValue((*itr).get()) == true ) - _bsphere.expandRadiusBy((*itr)->getBound()); + bsphere.expandRadiusBy((*itr)->getBound()); } } - - _bsphere_computed = true; - return true; + return bsphere; } -#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 diff --git a/src/osg/Transform.cpp b/src/osg/Transform.cpp index d9ab2706a..4e7f9b1ac 100644 --- a/src/osg/Transform.cpp +++ b/src/osg/Transform.cpp @@ -121,9 +121,10 @@ void Transform::setReferenceFrame(ReferenceFrame 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 // to handle this case gracefully, normally this should not be a problem. @@ -131,33 +132,34 @@ bool Transform::computeBound() const computeLocalToWorldMatrix(l2w,NULL); - Vec3 xdash = _bsphere._center; - xdash.x() += _bsphere._radius; + Vec3 xdash = bsphere._center; + xdash.x() += bsphere._radius; xdash = xdash*l2w; - Vec3 ydash = _bsphere._center; - ydash.y() += _bsphere._radius; + Vec3 ydash = bsphere._center; + ydash.y() += bsphere._radius; ydash = ydash*l2w; - Vec3 zdash = _bsphere._center; - zdash.z() += _bsphere._radius; + Vec3 zdash = bsphere._center; + zdash.z() += bsphere._radius; zdash = zdash*l2w; - _bsphere._center = _bsphere._center*l2w; - xdash -= _bsphere._center; + bsphere._center = bsphere._center*l2w; + + xdash -= bsphere._center; float len_xdash = xdash.length(); - ydash -= _bsphere._center; + ydash -= bsphere._center; float len_ydash = ydash.length(); - zdash -= _bsphere._center; + zdash -= bsphere._center; float len_zdash = zdash.length(); - _bsphere._radius = len_xdash; - if (_bsphere._radiusendRender(); } + +osg::BoundingBox osgParticle::ParticleSystem::computeBound() const +{ + if (!_bounds_computed) + { + return _def_bbox; + } else + { + return osg::BoundingBox(_bmin,_bmax); + } +} + diff --git a/src/osgParticle/ParticleSystemUpdater.cpp b/src/osgParticle/ParticleSystemUpdater.cpp index 802d82d63..d37638008 100644 --- a/src/osgParticle/ParticleSystemUpdater.cpp +++ b/src/osgParticle/ParticleSystemUpdater.cpp @@ -48,3 +48,9 @@ void osgParticle::ParticleSystemUpdater::traverse(osg::NodeVisitor& nv) } Node::traverse(nv); } + +osg::BoundingSphere osgParticle::ParticleSystemUpdater::computeBound() const +{ + return osg::BoundingSphere(); +} + diff --git a/src/osgPlugins/logo/ReaderWriterLOGO.cpp b/src/osgPlugins/logo/ReaderWriterLOGO.cpp index be5fd8aba..161ba2722 100644 --- a/src/osgPlugins/logo/ReaderWriterLOGO.cpp +++ b/src/osgPlugins/logo/ReaderWriterLOGO.cpp @@ -165,15 +165,15 @@ class Logos: public osg::Drawable return (n != 0); } + virtual osg::BoundingBox computeBound() const + { + return osg::BoundingBox( -1, -1, -1, 1, 1, 1); + } + protected: Logos& operator = (const Logos&) { return *this;} virtual ~Logos() {} - virtual bool computeBound() const - { - _bbox.set( -1, -1, -1, 1, 1, 1); - return true; - } private : std::vector logos[last_position]; osg::Viewport *viewport; diff --git a/src/osgPlugins/txp/TXPNode.cpp b/src/osgPlugins/txp/TXPNode.cpp index cee6d17b2..ff78d4b42 100644 --- a/src/osgPlugins/txp/TXPNode.cpp +++ b/src/osgPlugins/txp/TXPNode.cpp @@ -101,14 +101,11 @@ void TXPNode::traverse(osg::NodeVisitor& nv) Group::traverse(nv); } -bool TXPNode::computeBound() const +osg::BoundingSphere TXPNode::computeBound() const { if (getNumChildren() == 0) { - _bsphere.init(); - _bsphere.expandBy(_extents); - _bsphere_computed = true; - return true; + return osg::BoundingSphere( _extents ); } return Group::computeBound(); } diff --git a/src/osgPlugins/txp/TXPNode.h b/src/osgPlugins/txp/TXPNode.h index 711d79bb5..642765e76 100644 --- a/src/osgPlugins/txp/TXPNode.h +++ b/src/osgPlugins/txp/TXPNode.h @@ -69,11 +69,12 @@ public: void setArchive(TXPArchive* archive) { _archive = archive; } + virtual osg::BoundingSphere computeBound() const; + protected: virtual ~TXPNode(); - virtual bool computeBound() const; void updateEye(osg::NodeVisitor& nv); void updateSceneGraph(); diff --git a/src/osgSim/Impostor.cpp b/src/osgSim/Impostor.cpp index 01fafaee6..3ef5a2989 100644 --- a/src/osgSim/Impostor.cpp +++ b/src/osgSim/Impostor.cpp @@ -74,7 +74,7 @@ void Impostor::addImpostorSprite(unsigned int contextID, ImpostorSprite* is) } } -bool Impostor::computeBound() const +osg::BoundingSphere Impostor::computeBound() const { return LOD::computeBound(); } diff --git a/src/osgSim/ImpostorSprite.cpp b/src/osgSim/ImpostorSprite.cpp index 93fb8827e..fed7c2cde 100644 --- a/src/osgSim/ImpostorSprite.cpp +++ b/src/osgSim/ImpostorSprite.cpp @@ -100,22 +100,20 @@ void ImpostorSprite::drawImplementation(osg::State&) const } -bool ImpostorSprite::computeBound() const +osg::BoundingBox ImpostorSprite::computeBound() const { - _bbox.init(); - _bbox.expandBy(_coords[0]); - _bbox.expandBy(_coords[1]); - _bbox.expandBy(_coords[2]); - _bbox.expandBy(_coords[3]); + osg::BoundingBox bbox; + bbox.expandBy(_coords[0]); + bbox.expandBy(_coords[1]); + bbox.expandBy(_coords[2]); + bbox.expandBy(_coords[3]); - _bbox_computed=true; - - if (!_bbox.valid()) + if (!bbox.valid()) { osg::notify(osg::WARN) << "******* ImpostorSprite::computeBound() problem"<second); + bbox.expandBy(litr->second); } } for(sitr=_sizedAdditiveLightPointList.begin(); @@ -195,7 +195,7 @@ bool LightPointDrawable::computeBound() const litr!=lpl.end(); ++litr) { - _bbox.expandBy(litr->second); + bbox.expandBy(litr->second); } } for(sitr=_sizedBlendedLightPointList.begin(); @@ -207,9 +207,9 @@ bool LightPointDrawable::computeBound() const litr!=lpl.end(); ++litr) { - _bbox.expandBy(litr->second); + bbox.expandBy(litr->second); } } - return true; + return bbox; } diff --git a/src/osgSim/LightPointDrawable.h b/src/osgSim/LightPointDrawable.h index 4299a9289..70c1e101f 100644 --- a/src/osgSim/LightPointDrawable.h +++ b/src/osgSim/LightPointDrawable.h @@ -93,10 +93,10 @@ class OSGSIM_EXPORT LightPointDrawable : public osg::Drawable double getReferenceTime() const { return _referenceTime; } double getReferenceTimeInterval() const { return _referenceTimeInterval; } + virtual osg::BoundingBox computeBound() const; + protected: - virtual bool computeBound() const; - virtual ~LightPointDrawable() {} osg::Endian _endian; diff --git a/src/osgSim/LightPointNode.cpp b/src/osgSim/LightPointNode.cpp index c36a67990..713313b94 100644 --- a/src/osgSim/LightPointNode.cpp +++ b/src/osgSim/LightPointNode.cpp @@ -80,15 +80,15 @@ void LightPointNode::removeLightPoint(unsigned int pos) dirtyBound(); } -bool LightPointNode::computeBound() const +osg::BoundingSphere LightPointNode::computeBound() const { - _bsphere.init(); + osg::BoundingSphere bsphere; + bsphere.init(); _bbox.init(); if (_lightPointList.empty()) { - _bsphere_computed=true; - return false; + return bsphere; } @@ -101,21 +101,19 @@ bool LightPointNode::computeBound() const } - _bsphere.set(_bbox.center(),0.0f); + bsphere.set(_bbox.center(),0.0f); for(itr=_lightPointList.begin(); itr!=_lightPointList.end(); ++itr) { - osg::Vec3 dv(itr->_position-_bsphere.center()); + osg::Vec3 dv(itr->_position-bsphere.center()); float radius = dv.length()+itr->_radius; - if (_bsphere.radius()Surface_drawImplementation(state); } -bool SphereSegment::Surface::computeBound() const +osg:: BoundingBox SphereSegment::Surface::computeBound() const { - _bbox_computed = _ss->Surface_computeBound(_bbox); - return _bbox_computed; + osg:: BoundingBox bbox; + _ss->Surface_computeBound(bbox); + return bbox; } @@ -93,7 +94,7 @@ protected: } - virtual bool computeBound() const; + virtual osg::BoundingBox computeBound() const; private: @@ -105,10 +106,11 @@ void SphereSegment::EdgeLine::drawImplementation(osg::State& state) const _ss->EdgeLine_drawImplementation(state); } -bool SphereSegment::EdgeLine::computeBound() const +osg::BoundingBox SphereSegment::EdgeLine::computeBound() const { - _bbox_computed = _ss->EdgeLine_computeBound(_bbox); - return _bbox_computed; + osg::BoundingBox bbox; + _ss->EdgeLine_computeBound(bbox); + return bbox; } @@ -141,7 +143,7 @@ public: protected: - virtual bool computeBound() const; + virtual osg::BoundingBox computeBound() const; private: SphereSegment* _ss; @@ -155,10 +157,11 @@ void SphereSegment::Side::drawImplementation(osg::State& state) const _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); - return _bbox_computed; + osg::BoundingBox bbox; + _ss->Side_computeBound(bbox, _planeOrientation, _BoundaryAngle); + return bbox; } @@ -199,7 +202,7 @@ protected: //getOrCreateStateSet()->setAttributeAndModes(new osg::LineWidth(2.0),osg::StateAttribute::OFF); } - virtual bool computeBound() const; + virtual osg::BoundingBox computeBound() const; private: SphereSegment* _ss; @@ -211,10 +214,11 @@ void SphereSegment::Spoke::drawImplementation(osg::State& state) const _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); - return _bbox_computed; + osg::BoundingBox bbox; + _ss->Spoke_computeBound(bbox, _azAngle, _elevAngle); + return bbox; } SphereSegment::SphereSegment(const osg::Vec3& centre, float radius, const osg::Vec3& vec, float azRange, diff --git a/src/osgText/Text.cpp b/src/osgText/Text.cpp index 39e32de4b..68e0f03b5 100644 --- a/src/osgText/Text.cpp +++ b/src/osgText/Text.cpp @@ -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()) { @@ -238,16 +238,15 @@ bool Text::computeBound() const else { osg::Matrix& matrix = _autoTransformCache[i]._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.yMax(),_textBB.zMin())*matrix); - _bbox.expandBy(osg::Vec3(_textBB.xMin(),_textBB.yMax(),_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.yMax(),_textBB.zMin())*matrix); + bbox.expandBy(osg::Vec3(_textBB.xMin(),_textBB.yMax(),_textBB.zMin())*matrix); } } } - _bbox_computed = true; - return true; + return bbox; } Font* Text::getActiveFont()