Use the quad tree's minSize in the LodCallback

This commit is contained in:
scrawl 2017-03-12 22:39:53 +01:00
parent c22fde2bcd
commit a041546b54

View file

@ -72,14 +72,22 @@ namespace Terrain
class DefaultLodCallback : public LodCallback class DefaultLodCallback : public LodCallback
{ {
public: public:
DefaultLodCallback(float minSize)
: mMinSize(minSize)
{
}
virtual bool isSufficientDetail(QuadTreeNode* node, const osg::Vec3f& eyePoint) virtual bool isSufficientDetail(QuadTreeNode* node, const osg::Vec3f& eyePoint)
{ {
float dist = distance(node->getBoundingBox(), eyePoint); float dist = distance(node->getBoundingBox(), eyePoint);
int nativeLodLevel = Log2(static_cast<unsigned int>(node->getSize()*4)); int nativeLodLevel = Log2(static_cast<unsigned int>(node->getSize()/mMinSize));
int lodLevel = Log2(static_cast<unsigned int>(dist/2048.0)); int lodLevel = Log2(static_cast<unsigned int>(dist/(8192*mMinSize)));
return nativeLodLevel <= lodLevel; return nativeLodLevel <= lodLevel;
} }
private:
float mMinSize;
}; };
class RootNode : public QuadTreeNode class RootNode : public QuadTreeNode
@ -135,7 +143,7 @@ public:
mRootNode = new RootNode(size, osg::Vec2f(centerX, centerY)); mRootNode = new RootNode(size, osg::Vec2f(centerX, centerY));
mRootNode->setViewDataMap(mViewDataMap); mRootNode->setViewDataMap(mViewDataMap);
mRootNode->setLodCallback(new DefaultLodCallback); mRootNode->setLodCallback(new DefaultLodCallback(mMinSize));
addChildren(mRootNode); addChildren(mRootNode);
mRootNode->initNeighbours(); mRootNode->initNeighbours();
@ -177,7 +185,7 @@ public:
} }
osg::ref_ptr<QuadTreeNode> node = new QuadTreeNode(parent, direction, size, center); osg::ref_ptr<QuadTreeNode> node = new QuadTreeNode(parent, direction, size, center);
node->setLodCallback(new DefaultLodCallback); node->setLodCallback(parent->getLodCallback());
node->setViewDataMap(mViewDataMap); node->setViewDataMap(mViewDataMap);
parent->addChild(node); parent->addChild(node);