OpenMW
Public Member Functions | Private Member Functions | Private Attributes
Terrain::QuadTreeNode Class Reference

A node in the quad tree for our terrain. Depending on LOD, a node can either choose to render itself in one batch (merging its children), or delegate the render process to its children, rendering each child in at least one batch. More...

#include <quadtreenode.hpp>

List of all members.

Public Member Functions

 QuadTreeNode (World *terrain, ChildDirection dir, float size, const Ogre::Vector2 &center, QuadTreeNode *parent)
 ~QuadTreeNode ()
void setVisible (bool visible)
void applyMaterials ()
 Rebuild all materials.
void initNeighbours ()
 Initialize neighbours - do this after the quadtree is built.
void initAabb ()
void createChild (ChildDirection id, float size, const Ogre::Vector2 &center)
void markAsDummy ()
bool isDummy ()
QuadTreeNodegetParent ()
Ogre::SceneNode * getSceneNode ()
int getSize ()
Ogre::Vector2 getCenter ()
bool hasChildren ()
QuadTreeNodegetChild (ChildDirection dir)
QuadTreeNodegetNeighbour (Direction dir)
 Get neighbour node in this direction.
ChildDirection getDirection ()
 Returns our direction relative to the parent node, or Root if we are the root node.
void setBoundingBox (const Ogre::AxisAlignedBox &box)
const Ogre::AxisAlignedBox & getBoundingBox ()
 Get bounding box in local coordinates.
WorldgetTerrain ()
void update (const Ogre::Vector3 &cameraPos, Loading::Listener *loadingListener)
 Adjust LODs for the given camera position, possibly splitting up chunks or merging them.
void updateIndexBuffers ()
void destroyChunks (bool children)
 Destroy chunks rendered by this node *and* its children (if param is true)
size_t getNativeLodLevel ()
size_t getActualLodLevel ()
 Get the effective current LOD level used by the chunk rendering this node.
bool hasChunk ()
 Is this node currently configured to render itself?
void prepareForCompositeMap (Ogre::TRect< float > area)

Private Member Functions

void ensureLayerInfo ()
void ensureCompositeMap ()

Private Attributes

MaterialGeneratormMaterialGenerator
bool mIsActive
bool mIsDummy
float mSize
size_t mLodLevel
Ogre::AxisAlignedBox mBounds
Ogre::AxisAlignedBox mWorldBounds
ChildDirection mDirection
Ogre::Vector2 mCenter
Ogre::SceneNode * mSceneNode
QuadTreeNodemParent
QuadTreeNodemChildren [4]
QuadTreeNodemNeighbours [4]
ChunkmChunk
WorldmTerrain
Ogre::TexturePtr mCompositeMap

Detailed Description

A node in the quad tree for our terrain. Depending on LOD, a node can either choose to render itself in one batch (merging its children), or delegate the render process to its children, rendering each child in at least one batch.


Constructor & Destructor Documentation

QuadTreeNode::QuadTreeNode ( World terrain,
ChildDirection  dir,
float  size,
const Ogre::Vector2 &  center,
QuadTreeNode parent 
)
Parameters:
terrain
dirrelative to parent, or Root if we are the root node
sizesize (in *cell* units!)
centercenter (in *cell* units!)
parentparent node

Member Function Documentation

Rebuild all materials.

void QuadTreeNode::createChild ( ChildDirection  id,
float  size,
const Ogre::Vector2 &  center 
)
Note:
takes ownership of child
void QuadTreeNode::destroyChunks ( bool  children)

Destroy chunks rendered by this node *and* its children (if param is true)

void QuadTreeNode::ensureLayerInfo ( ) [private]

Get the effective current LOD level used by the chunk rendering this node.

const Ogre::AxisAlignedBox & QuadTreeNode::getBoundingBox ( void  )

Get bounding box in local coordinates.

Ogre::Vector2 Terrain::QuadTreeNode::getCenter ( ) [inline]

Returns our direction relative to the parent node, or Root if we are the root node.

Get the effective LOD level if this node was rendered in one chunk with ESM::Land::LAND_SIZE^2 vertices

Get neighbour node in this direction.

Ogre::SceneNode* Terrain::QuadTreeNode::getSceneNode ( ) [inline]

Is this node currently configured to render itself?

Initialize bounding boxes of non-leafs by merging children bounding boxes. Do this after the quadtree is built - note that leaf bounding boxes need to be set first via setBoundingBox!

Initialize neighbours - do this after the quadtree is built.

bool Terrain::QuadTreeNode::isDummy ( ) [inline]

Mark this node as a dummy node. This can happen if the terrain size isn't a power of two. For the QuadTree to work, we need to round the size up to a power of two, which means we'll end up with empty nodes that don't actually render anything.

void QuadTreeNode::prepareForCompositeMap ( Ogre::TRect< float >  area)

Add a textured quad to a specific 2d area in the composite map scenemanager. Only nodes with size <= 1 can be rendered with alpha blending, so larger nodes will simply call this method on their children.

Parameters:
areaarea in image space to put the quad
quadscollect quads here so they can be deleted later
void QuadTreeNode::setBoundingBox ( const Ogre::AxisAlignedBox &  box)

Set bounding box in local coordinates. Should be done at load time for leaf nodes. Other nodes can merge AABB of child nodes.

void QuadTreeNode::setVisible ( bool  visible)
void QuadTreeNode::update ( const Ogre::Vector3 &  cameraPos,
Loading::Listener loadingListener 
)

Adjust LODs for the given camera position, possibly splitting up chunks or merging them.

Todo:
implement error metrics or some other means of not using arbitrary values (general quality needs to be user configurable as well)

Adjust index buffers of chunks to stitch together chunks of different LOD, so that cracks are avoided. Call after QuadTreeNode::update!


Member Data Documentation

Ogre::AxisAlignedBox Terrain::QuadTreeNode::mBounds [private]
Ogre::Vector2 Terrain::QuadTreeNode::mCenter [private]
Ogre::TexturePtr Terrain::QuadTreeNode::mCompositeMap [private]

Is this node (or any of its child nodes) currently configured to render itself? (only relevant when distant land is disabled, otherwise whole terrain is always rendered)

Ogre::SceneNode* Terrain::QuadTreeNode::mSceneNode [private]
Ogre::AxisAlignedBox Terrain::QuadTreeNode::mWorldBounds [private]

The documentation for this class was generated from the following files: