OgreTerrainQuadTreeNode.h
Go to the documentation of this file.
/*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/
Copyright (c) 2000-2013 Torus Knot Software Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/
#ifndef __Ogre_TerrainQuadTreeNode_H__
#define __Ogre_TerrainQuadTreeNode_H__
#include "OgreTerrainPrerequisites.h"
#include "OgreCommon.h"
#include "OgreHardwareIndexBuffer.h"
#include "OgreMovableObject.h"
#include "OgreRenderable.h"
namespace Ogre
{
class HardwareVertexBufferSharedPtr;
class _OgreTerrainExport TerrainQuadTreeNode : public TerrainAlloc
{
public:
TerrainQuadTreeNode(Terrain* terrain, TerrainQuadTreeNode* parent,
uint16 xoff, uint16 yoff, uint16 size, uint16 lod, uint16 depth, uint16 quadrant);
virtual ~TerrainQuadTreeNode();
uint16 getXOffset() const { return mOffsetX; }
uint16 getYOffset() const { return mOffsetY; }
bool isLeaf() const;
uint16 getBaseLod() const { return mBaseLod; }
uint16 getLodCount() const;
TerrainQuadTreeNode* getChild(unsigned short child) const;
TerrainQuadTreeNode* getParent() const;
Terrain* getTerrain() const;
void prepare();
void prepare(StreamSerialiser& stream);
void load();
void load(uint16 depthStart, uint16 depthEnd);
void loadSelf();
void unload();
void unload(uint16 depthStart, uint16 depthEnd);
void unprepare();
void save(StreamSerialiser& stream);
struct _OgreTerrainExport LodLevel : public TerrainAlloc
{
uint16 batchSize;
IndexData* gpuIndexData;
Real maxHeightDelta;
Real calcMaxHeightDelta;
Real lastTransitionDist;
Real lastCFactor;
LodLevel() : batchSize(0), gpuIndexData(0), maxHeightDelta(0), calcMaxHeightDelta(0),
lastTransitionDist(0), lastCFactor(0) {}
};
typedef vector<LodLevel*>::type LodLevelList;
const LodLevel* getLodLevel(uint16 lod);
void preDeltaCalculation(const Rect& rect);
void notifyDelta(uint16 x, uint16 y, uint16 lod, Real delta);
void postDeltaCalculation(const Rect& rect);
void finaliseDeltaValues(const Rect& rect);
void assignVertexData(uint16 treeDepthStart, uint16 treeDepthEnd, uint16 resolution, uint sz);
void useAncestorVertexData(TerrainQuadTreeNode* owner, uint16 treeDepthEnd, uint16 resolution);
void updateVertexData(bool positions, bool deltas, const Rect& rect, bool cpuData);
void mergeIntoBounds(long x, long y, const Vector3& pos);
void resetBounds(const Rect& rect);
bool rectIntersectsNode(const Rect& rect);
bool rectContainsNode(const Rect& rect);
bool pointIntersectsNode(long x, long y);
const AxisAlignedBox& getAABB() const;
Real getBoundingRadius() const;
const Vector3& getLocalCentre() const { return mLocalCentre; }
Real getMinHeight() const;
Real getMaxHeight() const;
bool calculateCurrentLod(const Camera* cam, Real cFactor);
int getCurrentLod() const { return mCurrentLod; }
bool isRenderedAtCurrentLod() const;
bool isSelfOrChildRenderedAtCurrentLod() const;
void setCurrentLod(int lod);
float getLodTransition() const { return mLodTransition; }
void setLodTransition(float t);
static unsigned short POSITION_BUFFER;
static unsigned short DELTA_BUFFER;
Renderable *_getRenderable();
protected:
Terrain* mTerrain;
TerrainQuadTreeNode* mParent;
TerrainQuadTreeNode* mChildren[4];
LodLevelList mLodLevels;
uint16 mOffsetX, mOffsetY;
uint16 mBoundaryX, mBoundaryY;
uint16 mSize;
uint16 mBaseLod;
uint16 mDepth;
uint16 mQuadrant;
Vector3 mLocalCentre;
AxisAlignedBox mAABB;
Real mBoundingRadius;
int mCurrentLod;
unsigned short mMaterialLodIndex;
float mLodTransition;
TerrainQuadTreeNode* mChildWithMaxHeightDelta;
bool mSelfOrChildRendered;
struct VertexDataRecord : public TerrainAlloc
{
VertexData* cpuVertexData;
VertexData* gpuVertexData;
uint16 resolution;
uint16 size;
uint16 treeLevels;
uint16 numSkirtRowsCols;
uint16 skirtRowColSkip;
bool gpuVertexDataDirty;
VertexDataRecord(uint16 res, uint16 sz, uint16 lvls)
: cpuVertexData(0), gpuVertexData(0), resolution(res), size(sz),
treeLevels(lvls), numSkirtRowsCols(0),
skirtRowColSkip(0), gpuVertexDataDirty(false) {}
};
TerrainQuadTreeNode* mNodeWithVertexData;
VertexDataRecord* mVertexDataRecord;
class _OgreTerrainExport Movable : public MovableObject
{
protected:
TerrainQuadTreeNode* mParent;
public:
Movable(TerrainQuadTreeNode* parent);
virtual ~Movable();
// necessary overrides
const String& getMovableType(void) const;
const AxisAlignedBox& getBoundingBox(void) const;
Real getBoundingRadius(void) const;
void _updateRenderQueue(RenderQueue* queue);
void visitRenderables(Renderable::Visitor* visitor, bool debugRenderables = false);
bool isVisible(void) const;
uint32 getVisibilityFlags(void) const;
uint32 getQueryFlags(void) const;
bool getCastShadows(void) const;
};
Movable* mMovable;
friend class Movable;
SceneNode* mLocalNode;
class _OgreTerrainExport Rend : public Renderable, public TerrainAlloc
{
protected:
TerrainQuadTreeNode* mParent;
public:
Rend(TerrainQuadTreeNode* parent);
virtual ~Rend();
const MaterialPtr& getMaterial(void) const;
Technique* getTechnique(void) const;
void getRenderOperation(RenderOperation& op);
void getWorldTransforms(Matrix4* xform) const;
Real getSquaredViewDepth(const Camera* cam) const;
const LightList& getLights(void) const;
bool getCastsShadows(void) const;
};
Rend* mRend;
friend class Rend;
// actual implementation of MovableObject methods
void updateRenderQueue(RenderQueue* queue);
void visitRenderables(Renderable::Visitor* visitor, bool debugRenderables = false);
// actual implementations of Renderable methods
const MaterialPtr& getMaterial(void) const;
Technique* getTechnique(void) const;
void getRenderOperation(RenderOperation& op);
void getWorldTransforms(Matrix4* xform) const;
Real getSquaredViewDepth(const Camera* cam) const;
const LightList& getLights(void) const;
bool getCastsShadows(void) const;
const VertexDataRecord* getVertexDataRecord() const;
void createCpuVertexData();
/* Update the vertex buffers - the rect in question is relative to the whole terrain,
not the local vertex data (which may use a subset)
*/
void updateVertexBuffer(HardwareVertexBufferSharedPtr& posbuf, HardwareVertexBufferSharedPtr& deltabuf, const Rect& rect);
void destroyCpuVertexData();
void createGpuVertexData();
void destroyGpuVertexData();
void updateGpuVertexData();
void createGpuIndexData();
void destroyGpuIndexData();
void populateIndexData(uint16 batchSize, IndexData* destData);
void writePosVertex(bool compress, uint16 x, uint16 y, float height, const Vector3& pos, float uvScale, float** ppPos);
void writeDeltaVertex(bool compress, uint16 x, uint16 y, float delta, float deltaThresh, float** ppDelta);
uint16 calcSkirtVertexIndex(uint16 mainIndex, bool isCol);
};
}
#endif
Ogre::TerrainQuadTreeNode::mTerrain
Terrain * mTerrain
Definition: OgreTerrainQuadTreeNode.h:268
Ogre::TerrainQuadTreeNode::mAABB
AxisAlignedBox mAABB
Relative to terrain centre.
Definition: OgreTerrainQuadTreeNode.h:281
Ogre::Renderable
Abstract class defining the interface all renderable objects must implement.
Definition: OgreRenderable.h:63
Ogre::TerrainQuadTreeNode::POSITION_BUFFER
static unsigned short POSITION_BUFFER
Buffer binding used for holding positions.
Definition: OgreTerrainQuadTreeNode.h:261
Ogre::TerrainQuadTreeNode::VertexDataRecord::VertexDataRecord
VertexDataRecord(uint16 res, uint16 sz, uint16 lvls)
Definition: OgreTerrainQuadTreeNode.h:307
Ogre::TerrainQuadTreeNode::VertexDataRecord::gpuVertexDataDirty
bool gpuVertexDataDirty
Is the GPU vertex data out of date?
Definition: OgreTerrainQuadTreeNode.h:305
Ogre::TerrainQuadTreeNode::getYOffset
uint16 getYOffset() const
Get the vertical offset into the main terrain data of this node.
Definition: OgreTerrainQuadTreeNode.h:104
Ogre::TerrainQuadTreeNode::mSize
uint16 mSize
The number of vertices at the original terrain resolution this node encompasses.
Definition: OgreTerrainQuadTreeNode.h:276
Ogre::MovableObject
Abstract class defining a movable object in a scene.
Definition: OgreMovableObject.h:60
Ogre::uint
unsigned int uint
Definition: OgrePrerequisites.h:114
OgreRenderable.h
Ogre::TerrainQuadTreeNode::LodLevel::batchSize
uint16 batchSize
Number of vertices rendered down one side (not including skirts)
Definition: OgreTerrainQuadTreeNode.h:139
OgreMovableObject.h
Ogre::TerrainQuadTreeNode::getLocalCentre
const Vector3 & getLocalCentre() const
Get the local centre of this node, relative to parent terrain centre.
Definition: OgreTerrainQuadTreeNode.h:234
Ogre::VertexData
Summary class collecting together vertex source information.
Definition: OgreVertexIndexData.h:49
Ogre::TerrainQuadTreeNode::LodLevel::calcMaxHeightDelta
Real calcMaxHeightDelta
Temp calc area for max height delta.
Definition: OgreTerrainQuadTreeNode.h:145
Ogre::TerrainQuadTreeNode::VertexDataRecord::resolution
uint16 resolution
Resolution of the data compared to the base terrain data (NOT number of vertices!) ...
Definition: OgreTerrainQuadTreeNode.h:295
Ogre::TerrainQuadTreeNode::LodLevel
Definition: OgreTerrainQuadTreeNode.h:136
Ogre::Real
float Real
Software floating point type.
Definition: OgrePrerequisites.h:70
Ogre::RenderQueue
Class to manage the scene object rendering queue.
Definition: OgreRenderQueue.h:92
Ogre::TerrainQuadTreeNode::VertexDataRecord::cpuVertexData
VertexData * cpuVertexData
Definition: OgreTerrainQuadTreeNode.h:292
Ogre::IndexData
Summary class collecting together index data source information.
Definition: OgreVertexIndexData.h:242
Ogre::TRect< long >
OgreHardwareIndexBuffer.h
Ogre::SceneNode
Class representing a node in the scene graph.
Definition: OgreSceneNode.h:58
Ogre::TerrainQuadTreeNode::mSelfOrChildRendered
bool mSelfOrChildRendered
Definition: OgreTerrainQuadTreeNode.h:288
Ogre::TerrainQuadTreeNode::mLocalCentre
Vector3 mLocalCentre
Definition: OgreTerrainQuadTreeNode.h:280
Ogre::TerrainQuadTreeNode::LodLevel::maxHeightDelta
Real maxHeightDelta
Maximum delta height between this and the next lower lod.
Definition: OgreTerrainQuadTreeNode.h:143
Ogre::TerrainQuadTreeNode::LodLevel::lastCFactor
Real lastCFactor
The cFactor value used to calculate transitionDist.
Definition: OgreTerrainQuadTreeNode.h:149
Ogre::TerrainQuadTreeNode::VertexDataRecord::numSkirtRowsCols
uint16 numSkirtRowsCols
Number of rows and columns of skirts.
Definition: OgreTerrainQuadTreeNode.h:301
Ogre::TerrainQuadTreeNode::mCurrentLod
int mCurrentLod
Relative to mLocalCentre.
Definition: OgreTerrainQuadTreeNode.h:283
Ogre::TerrainQuadTreeNode::LodLevel::lastTransitionDist
Real lastTransitionDist
The most recently calculated transition distance.
Definition: OgreTerrainQuadTreeNode.h:147
Ogre::TerrainQuadTreeNode::getXOffset
uint16 getXOffset() const
Get the horizontal offset into the main terrain data of this node.
Definition: OgreTerrainQuadTreeNode.h:102
Ogre::TerrainQuadTreeNode::Rend::mParent
TerrainQuadTreeNode * mParent
Definition: OgreTerrainQuadTreeNode.h:363
Ogre::TerrainQuadTreeNode::getBaseLod
uint16 getBaseLod() const
Get the base LOD level this node starts at (the highest LOD it handles)
Definition: OgreTerrainQuadTreeNode.h:108
OgreCommon.h
Ogre::TerrainQuadTreeNode::mBoundaryY
uint16 mBoundaryY
Definition: OgreTerrainQuadTreeNode.h:274
Ogre::Matrix4
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:78
Ogre::Terrain
The main containing class for a chunk of terrain.
Definition: OgreTerrain.h:262
Ogre::Vector3
Standard 3-dimensional vector.
Definition: OgreVector3.h:51
Ogre::TerrainQuadTreeNode::mLocalNode
SceneNode * mLocalNode
Definition: OgreTerrainQuadTreeNode.h:357
Ogre::HardwareVertexBufferSharedPtr
Shared pointer implementation used to share vertex buffers.
Definition: OgreHardwareVertexBuffer.h:86
Ogre::TerrainQuadTreeNode::getLodTransition
float getLodTransition() const
Get the transition state between the current LOD and the next lower one (only valid after calculateCu...
Definition: OgreTerrainQuadTreeNode.h:256
Ogre::TerrainQuadTreeNode::mLodLevels
LodLevelList mLodLevels
Definition: OgreTerrainQuadTreeNode.h:271
Ogre::HashedVector
A hashed vector.
Definition: OgreCommon.h:332
Ogre::Renderable::Visitor
Visitor object that can be used to iterate over a collection of Renderable instances abstractly...
Definition: OgreRenderable.h:377
Ogre::TerrainQuadTreeNode::mDepth
uint16 mDepth
Definition: OgreTerrainQuadTreeNode.h:278
Ogre::TerrainQuadTreeNode::VertexDataRecord::gpuVertexData
VertexData * gpuVertexData
Definition: OgreTerrainQuadTreeNode.h:293
Ogre::TerrainQuadTreeNode::mMaterialLodIndex
unsigned short mMaterialLodIndex
-1 = none (do not render)
Definition: OgreTerrainQuadTreeNode.h:284
Ogre::TerrainQuadTreeNode::VertexDataRecord::skirtRowColSkip
uint16 skirtRowColSkip
The number of rows / cols to skip in between skirts.
Definition: OgreTerrainQuadTreeNode.h:303
_OgreTerrainExport
#define _OgreTerrainExport
Definition: OgreTerrainPrerequisites.h:58
Ogre::String
_StringBase String
Definition: OgrePrerequisites.h:439
Ogre::TerrainQuadTreeNode::mLodTransition
float mLodTransition
Definition: OgreTerrainQuadTreeNode.h:285
Ogre::StreamSerialiser
Utility class providing helper methods for reading / writing structured data held in a DataStream...
Definition: OgreStreamSerialiser.h:66
Ogre::TerrainQuadTreeNode::mParent
TerrainQuadTreeNode * mParent
Definition: OgreTerrainQuadTreeNode.h:269
Ogre::TerrainQuadTreeNode::Movable
MovableObject implementation to provide the hook to the scene.
Definition: OgreTerrainQuadTreeNode.h:335
Ogre::Camera
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:86
Ogre::TerrainQuadTreeNode
A node in a quad tree used to store a patch of terrain.
Definition: OgreTerrainQuadTreeNode.h:85
Ogre::uint32
unsigned int uint32
Definition: OgrePlatform.h:359
Ogre::TerrainQuadTreeNode::DELTA_BUFFER
static unsigned short DELTA_BUFFER
Buffer binding used for holding delta values.
Definition: OgreTerrainQuadTreeNode.h:263
Ogre::TerrainQuadTreeNode::VertexDataRecord
Definition: OgreTerrainQuadTreeNode.h:290
Ogre
Definition: OgreAndroidLogListener.h:34
Ogre::TerrainQuadTreeNode::mVertexDataRecord
VertexDataRecord * mVertexDataRecord
Definition: OgreTerrainQuadTreeNode.h:314
Ogre::TerrainQuadTreeNode::VertexDataRecord::treeLevels
uint16 treeLevels
Number of quadtree levels (including this one) this data applies to.
Definition: OgreTerrainQuadTreeNode.h:299
Ogre::TerrainQuadTreeNode::LodLevel::LodLevel
LodLevel()
Definition: OgreTerrainQuadTreeNode.h:151
Ogre::SharedPtr< Material >
Ogre::TerrainQuadTreeNode::mQuadrant
uint16 mQuadrant
Definition: OgreTerrainQuadTreeNode.h:279
Ogre::vector
Definition: OgrePrerequisites.h:491
Ogre::TerrainQuadTreeNode::LodLevelList
vector< LodLevel * >::type LodLevelList
Definition: OgreTerrainQuadTreeNode.h:154
Ogre::TerrainQuadTreeNode::Rend
Hook to the render queue.
Definition: OgreTerrainQuadTreeNode.h:360
Ogre::TerrainQuadTreeNode::Movable::mParent
TerrainQuadTreeNode * mParent
Definition: OgreTerrainQuadTreeNode.h:338
Ogre::RenderOperation
&#39;New&#39; rendering operation using vertex buffers.
Definition: OgreRenderOperation.h:45
Ogre::Technique
Class representing an approach to rendering this particular Material.
Definition: OgreTechnique.h:53
OgreTerrainPrerequisites.h
Ogre::TerrainQuadTreeNode::mBoundingRadius
Real mBoundingRadius
Relative to mLocalCentre.
Definition: OgreTerrainQuadTreeNode.h:282
Ogre::TerrainQuadTreeNode::mMovable
Movable * mMovable
Definition: OgreTerrainQuadTreeNode.h:355
Ogre::AxisAlignedBox
A 3D box aligned with the x/y/z axes.
Definition: OgreAxisAlignedBox.h:54
Ogre::TerrainQuadTreeNode::mBaseLod
uint16 mBaseLod
Definition: OgreTerrainQuadTreeNode.h:277
Ogre::TerrainQuadTreeNode::VertexDataRecord::size
uint16 size
Size of the data along one edge.
Definition: OgreTerrainQuadTreeNode.h:297
Ogre::TerrainQuadTreeNode::LodLevel::gpuIndexData
IndexData * gpuIndexData
Index data on the gpu.
Definition: OgreTerrainQuadTreeNode.h:141
Ogre::TerrainQuadTreeNode::mOffsetY
uint16 mOffsetY
Definition: OgreTerrainQuadTreeNode.h:273
Ogre::uint16
unsigned short uint16
Definition: OgrePlatform.h:360
Ogre::AllocatedObject
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Definition: OgreMemoryAllocatedObject.h:58
Ogre::TerrainQuadTreeNode::getCurrentLod
int getCurrentLod() const
Get the current LOD index (only valid after calculateCurrentLod)
Definition: OgreTerrainQuadTreeNode.h:248
Ogre::TerrainQuadTreeNode::mRend
Rend * mRend
Definition: OgreTerrainQuadTreeNode.h:377
Ogre::TerrainQuadTreeNode::mNodeWithVertexData
TerrainQuadTreeNode * mNodeWithVertexData
Definition: OgreTerrainQuadTreeNode.h:313

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.