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:
@@ -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,
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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> _image;
|
||||
|
||||
|
||||
@@ -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> _stateset;
|
||||
|
||||
mutable BoundingBox _bbox;
|
||||
mutable bool _bbox_computed;
|
||||
BoundingBox _initialBound;
|
||||
ref_ptr<ComputeBoundCallback> _computeBoundCallback;
|
||||
mutable BoundingBox _boundingBox;
|
||||
mutable bool _boundingBoxComputed;
|
||||
|
||||
ref_ptr<Shape> _shape;
|
||||
ref_ptr<Shape> _shape;
|
||||
|
||||
bool _supportsDisplayList;
|
||||
bool _useDisplayList;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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*/) {}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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> _light;
|
||||
|
||||
|
||||
@@ -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> _computeBoundCallback;
|
||||
mutable BoundingSphere _boundingSphere;
|
||||
mutable bool _boundingSphereComputed;
|
||||
|
||||
std::string _name;
|
||||
|
||||
|
||||
@@ -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<ConvexPlanarOccluder> _occluder;
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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> _tessellationHints;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user