1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-10 06:39:49 +00:00
OpenMW/components/terrain/quadtreenode.hpp
scrawl 8c151364df Add special handling for CullVisitor to QuadTreeWorld.
- Cull only against bounding box, not bounding sphere, as this appears to perform better.
- Also traverse into non visible nodes to compute their LOD, this is to avoid nodes having to be loaded in when the player turns the view around, and will avoid unnecessary refs/unrefs of rendering data in the View. This should probably be turned off at some point for static cameras, such as the local maps.
2017-03-14 19:27:56 +01:00

99 lines
2.5 KiB
C++

#ifndef OPENMW_COMPONENTS_TERRAIN_QUADTREENODE_H
#define OPENMW_COMPONENTS_TERRAIN_QUADTREENODE_H
#include <osg/Group>
#include "defs.hpp"
namespace Terrain
{
enum ChildDirection
{
NW = 0,
NE = 1,
SW = 2,
SE = 3,
Root
};
class QuadTreeNode;
class LodCallback : public osg::Referenced
{
public:
virtual ~LodCallback() {}
virtual bool isSufficientDetail(QuadTreeNode *node, osg::NodeVisitor &nv) = 0;
};
class ViewDataMap;
class ViewData;
class QuadTreeNode : public osg::Group
{
public:
QuadTreeNode(QuadTreeNode* parent, ChildDirection dir, float size, const osg::Vec2f& center);
virtual ~QuadTreeNode();
QuadTreeNode* getParent();
QuadTreeNode* getChild(unsigned int i);
using osg::Group::getNumChildren;
/// Returns our direction relative to the parent node, or Root if we are the root node.
ChildDirection getDirection() { return mDirection; }
/// Get neighbour node in this direction
QuadTreeNode* getNeighbour (Direction dir);
/// Initialize neighbours - do this after the quadtree is built
void initNeighbours();
void setBoundingBox(const osg::BoundingBox& boundingBox);
const osg::BoundingBox& getBoundingBox() const;
bool hasValidBounds() const { return mValidBounds; }
virtual osg::BoundingSphere computeBound() const;
/// size in cell coordinates
float getSize() const;
/// center in cell coordinates
const osg::Vec2f& getCenter() const;
virtual void traverse(osg::NodeVisitor& nv);
/// Set the Lod callback to use for determining when to stop traversing further down the quad tree.
void setLodCallback(LodCallback* lodCallback);
LodCallback* getLodCallback();
/// Set the view data map that the finally used nodes for a given camera/intersection are pushed onto.
void setViewDataMap(ViewDataMap* map);
ViewDataMap* getViewDataMap();
/// Create or retrieve a view for the given traversal.
ViewData* getView(osg::NodeVisitor& nv);
private:
QuadTreeNode* mParent;
QuadTreeNode* mNeighbours[4];
ChildDirection mDirection;
osg::BoundingBox mBoundingBox;
bool mValidBounds;
float mSize;
osg::Vec2f mCenter;
osg::ref_ptr<LodCallback> mLodCallback;
osg::ref_ptr<ViewDataMap> mViewDataMap;
};
}
#endif