2001-01-11 00:32:10 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <math.h>
|
2001-10-22 05:27:40 +08:00
|
|
|
#include <osg/Geode>
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
#define square(x) ((x)*(x))
|
|
|
|
|
|
|
|
using namespace osg;
|
|
|
|
|
|
|
|
Geode::Geode()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-01-29 22:04:06 +08:00
|
|
|
Geode::Geode(const Geode& geode,const CopyOp& copyop):
|
|
|
|
Node(geode,copyop)
|
Added support for shallow and deep copy of nodes, drawables and state, via a
copy constructor which takes an optional Cloner object, and the old
osg::Object::clone() has changed so that it now requires a Cloner as paramter.
This is passed on to the copy constructor to help control the shallow vs
deep copying. The old functionality of clone() which was clone of type has
been renamed to cloneType().
Updated all of the OSG to work with these new conventions, implemention all
the required copy constructors etc. A couple of areas will do shallow
copies by design, a couple of other still need to be updated to do either
shallow or deep.
Neither of the shallow or deep copy operations have been tested yet, only
the old functionality of the OSG has been checked so far, such running the
viewer on various demo datasets.
Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which
was not checking that Group didn't have have any attached StateSet's, Callbacks
or UserData. These checks have now been added, which fixes a bug which was
revealled by the new osgscribe demo, this related to removal of group acting
as state decorator.
method
2002-01-29 05:17:01 +08:00
|
|
|
{
|
|
|
|
for(DrawableList::const_iterator itr=geode._drawables.begin();
|
|
|
|
itr!=geode._drawables.end();
|
|
|
|
++itr)
|
|
|
|
{
|
2002-01-29 22:04:06 +08:00
|
|
|
Drawable* drawable = copyop(itr->get());
|
2002-01-29 20:52:04 +08:00
|
|
|
if (drawable) addDrawable(drawable);
|
Added support for shallow and deep copy of nodes, drawables and state, via a
copy constructor which takes an optional Cloner object, and the old
osg::Object::clone() has changed so that it now requires a Cloner as paramter.
This is passed on to the copy constructor to help control the shallow vs
deep copying. The old functionality of clone() which was clone of type has
been renamed to cloneType().
Updated all of the OSG to work with these new conventions, implemention all
the required copy constructors etc. A couple of areas will do shallow
copies by design, a couple of other still need to be updated to do either
shallow or deep.
Neither of the shallow or deep copy operations have been tested yet, only
the old functionality of the OSG has been checked so far, such running the
viewer on various demo datasets.
Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which
was not checking that Group didn't have have any attached StateSet's, Callbacks
or UserData. These checks have now been added, which fixes a bug which was
revealled by the new osgscribe demo, this related to removal of group acting
as state decorator.
method
2002-01-29 05:17:01 +08:00
|
|
|
}
|
|
|
|
}
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
Geode::~Geode()
|
|
|
|
{
|
2002-02-09 06:55:21 +08:00
|
|
|
// remove reference to this from children's parent lists.
|
|
|
|
for(DrawableList::iterator itr=_drawables.begin();
|
|
|
|
itr!=_drawables.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
(*itr)->removeParent(this);
|
|
|
|
}
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
|
2002-02-09 06:55:21 +08:00
|
|
|
const bool Geode::addDrawable( Drawable *drawable )
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2002-02-09 06:55:21 +08:00
|
|
|
if (drawable && !containsDrawable(drawable))
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2002-02-09 06:55:21 +08:00
|
|
|
// note ref_ptr<> automatically handles incrementing drawable's reference count.
|
|
|
|
_drawables.push_back(drawable);
|
|
|
|
|
|
|
|
// register as parent of drawable.
|
|
|
|
drawable->addParent(this);
|
|
|
|
|
|
|
|
dirtyBound();
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2002-02-09 06:55:21 +08:00
|
|
|
const bool Geode::removeDrawable( Drawable *drawable )
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2002-02-09 06:55:21 +08:00
|
|
|
DrawableList::iterator itr = findDrawable(drawable);
|
2001-09-20 05:08:56 +08:00
|
|
|
if (itr!=_drawables.end())
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2002-02-09 06:55:21 +08:00
|
|
|
// remove this Geode from the child parent list.
|
|
|
|
drawable->removeParent(this);
|
|
|
|
|
|
|
|
// note ref_ptr<> automatically handles decrementing drawable's reference count.
|
|
|
|
_drawables.erase(itr);
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
dirtyBound();
|
2002-02-09 06:55:21 +08:00
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2002-02-09 06:55:21 +08:00
|
|
|
const bool Geode::replaceDrawable( Drawable *origDrawable, Drawable *newDrawable )
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2002-02-09 06:55:21 +08:00
|
|
|
if (newDrawable==NULL || origDrawable==newDrawable) return false;
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2002-02-09 06:55:21 +08:00
|
|
|
DrawableList::iterator itr = findDrawable(origDrawable);
|
2001-09-20 05:08:56 +08:00
|
|
|
if (itr!=_drawables.end())
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2002-02-09 06:55:21 +08:00
|
|
|
|
|
|
|
// remove from origDrawable's parent list.
|
|
|
|
origDrawable->removeParent(this);
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
// note ref_ptr<> automatically handles decrementing origGset's reference count,
|
|
|
|
// and inccrementing newGset's reference count.
|
2002-02-09 06:55:21 +08:00
|
|
|
*itr = newDrawable;
|
|
|
|
|
|
|
|
// register as parent of child.
|
|
|
|
newDrawable->addParent(this);
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
dirtyBound();
|
2002-02-09 06:55:21 +08:00
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else return false;
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
const bool Geode::computeBound() const
|
|
|
|
{
|
2001-01-11 00:32:10 +08:00
|
|
|
BoundingBox bb;
|
2001-09-20 05:08:56 +08:00
|
|
|
|
|
|
|
DrawableList::const_iterator itr;
|
|
|
|
for(itr=_drawables.begin();
|
|
|
|
itr!=_drawables.end();
|
2001-01-11 00:32:10 +08:00
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
bb.expandBy((*itr)->getBound());
|
|
|
|
}
|
2001-09-20 05:08:56 +08:00
|
|
|
|
|
|
|
if (bb.isValid())
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2001-09-20 05:08:56 +08:00
|
|
|
|
|
|
|
_bsphere._center = bb.center();
|
|
|
|
_bsphere._radius = 0.0f;
|
|
|
|
|
|
|
|
for(itr=_drawables.begin();
|
|
|
|
itr!=_drawables.end();
|
|
|
|
++itr)
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2001-09-20 05:08:56 +08:00
|
|
|
const BoundingBox& bbox = (*itr)->getBound();
|
|
|
|
for(unsigned int c=0;c<8;++c)
|
|
|
|
{
|
|
|
|
_bsphere.expandRadiusBy(bbox.corner(c));
|
|
|
|
}
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
_bsphere_computed=true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_bsphere.init();
|
|
|
|
_bsphere_computed=true;
|
|
|
|
return false;
|
|
|
|
}
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
void Geode::compileDrawables(State& state)
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2001-09-20 05:08:56 +08:00
|
|
|
for(DrawableList::iterator itr = _drawables.begin();
|
|
|
|
itr!=_drawables.end();
|
2001-01-11 00:32:10 +08:00
|
|
|
++itr)
|
|
|
|
{
|
2001-09-20 05:08:56 +08:00
|
|
|
(*itr)->compile(state);
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
}
|