2001-10-22 05:27:40 +08:00
|
|
|
#include <osg/LOD>
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
using namespace osg;
|
|
|
|
|
2002-01-29 22:04:06 +08:00
|
|
|
LOD::LOD(const LOD& lod,const CopyOp& copyop):
|
|
|
|
Group(lod,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
|
|
|
_rangeList(lod._rangeList),
|
|
|
|
_rangeList2(lod._rangeList2),
|
|
|
|
_center(lod._center)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
void LOD::traverse(NodeVisitor& nv)
|
|
|
|
{
|
2001-09-20 05:08:56 +08:00
|
|
|
switch(nv.getTraversalMode())
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2001-09-20 05:08:56 +08:00
|
|
|
case(NodeVisitor::TRAVERSE_ALL_CHILDREN):
|
|
|
|
std::for_each(_children.begin(),_children.end(),NodeAcceptOp(nv));
|
|
|
|
break;
|
|
|
|
case(NodeVisitor::TRAVERSE_ACTIVE_CHILDREN):
|
|
|
|
if (_children.size()!=0) _children.front()->accept(nv);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
|
|
|
|
void LOD::setRange(const unsigned int index, const float range)
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
|
|
|
if (index<_rangeList.size()) _rangeList[index] = range;
|
|
|
|
else while (index>=_rangeList.size()) _rangeList.push_back(range);
|
|
|
|
|
|
|
|
if (index<_rangeList2.size()) _rangeList2[index] = range*range;
|
|
|
|
else while (index>=_rangeList2.size()) _rangeList2.push_back(range*range);
|
|
|
|
}
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2002-02-07 09:07:11 +08:00
|
|
|
const int LOD::evaluateLODChild(const Vec3& eye_local, const float bias) const
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2001-09-20 05:08:56 +08:00
|
|
|
// For cache coherency, use _rangeList2 exclusively
|
2002-01-05 04:43:20 +08:00
|
|
|
if (_rangeList2.empty()) return -1;
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
// Test distance-squared against the stored array of squared ranges
|
2001-01-11 00:32:10 +08:00
|
|
|
float LODRange = (eye_local-_center).length2()*bias;
|
|
|
|
if (LODRange<_rangeList2[0]) return -1;
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2002-01-05 04:43:20 +08:00
|
|
|
unsigned int end_marker = _rangeList2.size()-1;
|
|
|
|
if (end_marker>_children.size()) end_marker=_children.size();
|
|
|
|
for(unsigned int i=0;i<end_marker;++i)
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2002-01-05 04:43:20 +08:00
|
|
|
if (LODRange<_rangeList2[i+1])
|
2001-09-20 05:08:56 +08:00
|
|
|
{
|
2001-01-11 00:32:10 +08:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|