Files
OpenSceneGraph/src/osg/LOD.cpp
2001-10-21 21:27:40 +00:00

52 lines
1.3 KiB
C++

#include <osg/LOD>
#include <algorithm>
using namespace osg;
void LOD::traverse(NodeVisitor& nv)
{
switch(nv.getTraversalMode())
{
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;
}
}
void LOD::setRange(const unsigned int index, const float range)
{
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);
}
const int LOD::evaluate(const Vec3& eye_local, const float bias) const
{
// For cache coherency, use _rangeList2 exclusively
if (_rangeList2.size()==0) return -1;
// Test distance-squared against the stored array of squared ranges
float LODRange = (eye_local-_center).length2()*bias;
if (LODRange<_rangeList2[0]) return -1;
for(unsigned int i=0;i<_rangeList2.size()-1;++i)
{
if (_rangeList2[i]<=LODRange && LODRange<_rangeList2[i+1])
{
return i;
}
}
return -1;
}