osgEarth 2.1.1
Public Member Functions

osgEarth::Drivers::LODFactorCallback Struct Reference

List of all members.

Public Member Functions

void operator() (osg::Node *node, osg::NodeVisitor *nv)

Detailed Description

Definition at line 29 of file LODFactorCallback.


Member Function Documentation

void osgEarth::Drivers::LODFactorCallback::operator() ( osg::Node *  node,
osg::NodeVisitor *  nv 
)

Definition at line 39 of file LODFactorCallback.cpp.

        {
            // test the type since this is not always a PagedLOD.
            osg::PagedLOD* lod = static_cast<osg::PagedLOD*>(node);
            osgUtil::CullVisitor* cv = static_cast<osgUtil::CullVisitor*>(nv);
            osg::LOD::RangeMode rangeMode = lod->getRangeMode();
            float requiredRange = 0.0f;
            float rangeFactor = 1.0f;
            const osg::LOD::RangeList& rangeList = lod->getRangeList();
            if (rangeMode == osg::LOD::DISTANCE_FROM_EYE_POINT)
            {
                requiredRange = cv->getDistanceToViewPoint(lod->getCenter(), true);
            }
            else if (cv->getLODScale() > 0.0f)
            {
                requiredRange = cv->clampedPixelSize(lod->getBound()) / cv->getLODScale();
            }
            else
            {
                // The comment in osg/PagedLOD.cpp says that this algorithm
                // finds the highest res tile, but it actually finds the
                // lowest res tile!
                for (osg::LOD::RangeList::const_iterator itr = rangeList.begin(), end = rangeList.end();
                    itr != end;
                    ++itr)
                {
                    requiredRange = osg::maximum(requiredRange, itr->first);
                }
            }
            // We're counting on only finding one valid LOD, unlike the
            // general OSG behavior.
            if (!rangeList.empty() && rangeList[0].first <= requiredRange
                && requiredRange < rangeList[0].second)
            {
                rangeFactor = 1.0f - (requiredRange - rangeList[0].first) / rangeList[0].first;
                rangeFactor = osg::clampTo(rangeFactor, 0.0f, 1.0f);
            }
            osg::ref_ptr<osg::Uniform> ufact
                = new osg::Uniform("osgearth_LODRangeFactor", rangeFactor);
            osg::ref_ptr<osg::StateSet> ss = new osg::StateSet;
            ss->addUniform(ufact.get());

            cv->pushStateSet(ss.get());
            traverse(node, nv);
            cv->popStateSet();
        }
    }

The documentation for this struct was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines