OpenSceneGraph/include/osg/Geode

110 lines
3.9 KiB
Plaintext
Raw Normal View History

2002-07-17 04:07:32 +08:00
//C++ header - Open Scene Graph - Copyright (C) 1998-2002 Robert Osfield
//Distributed under the terms of the GNU Library General Public License (LGPL)
//as published by the Free Software Foundation.
2001-01-11 00:32:10 +08:00
#ifndef OSG_GEODE
#define OSG_GEODE 1
#include <osg/Node>
#include <osg/NodeVisitor>
#include <osg/Drawable>
2001-01-11 00:32:10 +08:00
namespace osg {
/** Leaf Node for grouping Drawables.*/
2001-01-11 00:32:10 +08:00
class SG_EXPORT Geode : public Node
{
public:
typedef std::vector< ref_ptr<Drawable> > DrawableList;
2001-01-11 00:32:10 +08:00
Geode();
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
Geode(const Geode&,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
META_Node(osg, Geode);
2001-01-11 00:32:10 +08:00
/** Add Drawable to Geode.
2001-01-11 00:32:10 +08:00
* If gset is not NULL and is not contained in Geode then increment its
* reference count, add it to the drawables list and dirty the bounding
2001-01-11 00:32:10 +08:00
* sphere to force it to recompute on next getBound() and return true for success.
* Otherwise return false.
*/
virtual bool addDrawable( Drawable *drawable );
2001-01-11 00:32:10 +08:00
/** Remove Drawable from Geode.
* Equivalent to setDrawabke(getDrawableIndex(orignChild),node),
* see docs for setNode for futher details on implementation.*/
virtual bool removeDrawable( Drawable *drawable );
2001-01-11 00:32:10 +08:00
/** Remove drawable(s) from the specified position in Geode's drawable list.*/
virtual bool removeDrawable(unsigned int i,unsigned int numDrawablesToRemove=1);
/** Replace specified Drawable with another Drawable.
* Equivalent to setDrawable(getDrawableIndex(orignChild),node),
* see docs for setDrawable for futher details on implementation.*/
virtual bool replaceDrawable( Drawable *origDraw, Drawable *newDraw );
/** set drawable at position i.
* return true if set correctly, false on failure (if node==NULL || i is out of range).
2001-01-11 00:32:10 +08:00
* Decrement the reference count origGSet and increments the
* reference count of newGset, and dirty the bounding sphere
* to force it to recompute on next getBound() and returns true.
* If origDrawable is not found then return false and do not
2001-01-11 00:32:10 +08:00
* add newGset. If newGset is NULL then return false and do
* not remove origGset.
*/
virtual bool setDrawable( unsigned int i, Drawable* drawable );
2001-01-11 00:32:10 +08:00
/** return the number of drawable's.*/
inline unsigned int getNumDrawables() const { return _drawables.size(); }
/** return drawable at position i.*/
inline Drawable* getDrawable( unsigned int i ) { return _drawables[i].get(); }
2001-01-11 00:32:10 +08:00
/** return drawable at position i.*/
inline const Drawable* getDrawable( unsigned int i ) const { return _drawables[i].get(); }
2001-01-11 00:32:10 +08:00
/** return true if drawable is contained within Geode.*/
inline bool containsDrawable(const Drawable* gset) const
2001-01-11 00:32:10 +08:00
{
for (DrawableList::const_iterator itr=_drawables.begin();
itr!=_drawables.end();
2001-01-11 00:32:10 +08:00
++itr)
{
if (itr->get()==gset) return true;
}
return false;
}
/** Get the index number of drawable, return a value between
* 0 and _drawables.size()-1 if found, if not found then
* return _drawables.size().*/
inline unsigned int getDrawableIndex( const Drawable* node ) const
{
for (unsigned int drawableNum=0;drawableNum<_drawables.size();++drawableNum)
{
if (_drawables[drawableNum]==node) return drawableNum;
}
return _drawables.size(); // node not found.
}
/** compile OpenGL Display List for each drawable.*/
void compileDrawables(State& state);
2001-01-11 00:32:10 +08:00
protected:
virtual ~Geode();
virtual bool computeBound() const;
2001-01-11 00:32:10 +08:00
DrawableList _drawables;
2001-01-11 00:32:10 +08:00
};
}
2001-01-11 00:32:10 +08:00
#endif