2001-10-22 05:27:40 +08:00
|
|
|
#include <osg/LOD>
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
using namespace osg;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
const int LOD::evaluate(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;
|
|
|
|
}
|
|
|
|
|