From: frohlich Date: Thu, 11 Jun 2009 08:42:44 +0000 (+0000) Subject: Also handle PagedLOD nodes frame count in the update visitor. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=a34eceb327964b685ece06efeb50386cd7198eb0;p=simgear.git Also handle PagedLOD nodes frame count in the update visitor. Modified Files: simgear/scene/util/SGUpdateVisitor.hxx --- diff --git a/simgear/scene/util/SGUpdateVisitor.hxx b/simgear/scene/util/SGUpdateVisitor.hxx index 3787b43e..0f640b66 100644 --- a/simgear/scene/util/SGUpdateVisitor.hxx +++ b/simgear/scene/util/SGUpdateVisitor.hxx @@ -23,6 +23,7 @@ #define SG_SCENE_UPDATEVISITOR_HXX #include +#include #include #include "simgear/math/SGMath.hxx" @@ -139,7 +140,17 @@ public: return; osgUtil::UpdateVisitor::apply(node); } - + // To avoid expiry of LOD nodes that are in range and that are updated, + // mark them with the last traversal number, even if they are culled away + // by the cull frustum. + virtual void apply(osg::PagedLOD& pagedLOD) + { + if (!needToEnterNode(pagedLOD)) + return; + if (getFrameStamp()) + pagedLOD.setFrameNumberOfLastTraversal(getFrameStamp()->getFrameNumber()); + osgUtil::UpdateVisitor::apply(pagedLOD); + } // To be able to traverse correctly only the active children, we need to // track the model view matrices during update. virtual void apply(osg::Transform& transform) @@ -164,6 +175,8 @@ public: apply(static_cast(camera)); } } + // Function to make the LOD traversal only enter that children that + // are visible on the screen. virtual float getDistanceToViewPoint(const osg::Vec3& pos, bool) const { return (_currentEyePos - _matrix.preMult(osg::Vec3d(pos))).length(); } @@ -176,8 +189,11 @@ protected: } bool isSphereInRange(const osg::BoundingSphere& sphere) const { - float maxDist = mVisibility + 2*sphere._radius; - return getDistanceToViewPoint(sphere._center, false) < maxDist; + if (!sphere.valid()) + return false; + float maxDist = mVisibility + sphere._radius; + osg::Vec3d center = _matrix.preMult(osg::Vec3d(sphere._center)); + return (_currentEyePos - center).length2() <= maxDist*maxDist; } private: