OGRE  1.7
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OgreTerrainQuadTreeNode.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2011 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 
29 #ifndef __Ogre_TerrainQuadTreeNode_H__
30 #define __Ogre_TerrainQuadTreeNode_H__
31 
33 #include "OgreCommon.h"
35 #include "OgreMovableObject.h"
36 #include "OgreRenderable.h"
37 
38 
39 
40 namespace Ogre
41 {
42  class HardwareVertexBufferSharedPtr;
43 
86  {
87  public:
98  uint16 xoff, uint16 yoff, uint16 size, uint16 lod, uint16 depth, uint16 quadrant);
99  virtual ~TerrainQuadTreeNode();
100 
102  uint16 getXOffset() const { return mOffsetX; }
104  uint16 getYOffset() const { return mOffsetY; }
106  bool isLeaf() const;
108  uint16 getBaseLod() const { return mBaseLod; }
110  uint16 getLodCount() const;
112  TerrainQuadTreeNode* getChild(unsigned short child) const;
114  TerrainQuadTreeNode* getParent() const;
116  Terrain* getTerrain() const;
117 
119  void prepare();
121  void prepare(StreamSerialiser& stream);
123  void load();
125  void unload();
127  void unprepare();
129  void save(StreamSerialiser& stream);
130 
132  {
145 
146  LodLevel() : gpuIndexData(0), maxHeightDelta(0), calcMaxHeightDelta(0),
147  lastTransitionDist(0), lastCFactor(0) {}
148  };
150 
156  const LodLevel* getLodLevel(uint16 lod);
157 
162  void preDeltaCalculation(const Rect& rect);
163 
165  void notifyDelta(uint16 x, uint16 y, uint16 lod, Real delta);
166 
169  void postDeltaCalculation(const Rect& rect);
170 
174  void finaliseDeltaValues(const Rect& rect);
175 
182  void assignVertexData(uint16 treeDepthStart, uint16 treeDepthEnd, uint16 resolution, uint sz);
183 
188  void useAncestorVertexData(TerrainQuadTreeNode* owner, uint16 treeDepthEnd, uint16 resolution);
189 
192  void updateVertexData(bool positions, bool deltas, const Rect& rect, bool cpuData);
193 
194 
195 
202  void mergeIntoBounds(long x, long y, const Vector3& pos);
206  void resetBounds(const Rect& rect);
207 
212  bool rectIntersectsNode(const Rect& rect);
217  bool rectContainsNode(const Rect& rect);
222  bool pointIntersectsNode(long x, long y);
223 
225  const AxisAlignedBox& getAABB() const;
227  Real getBoundingRadius() const;
229  const Vector3& getLocalCentre() const { return mLocalCentre; }
231  Real getMinHeight() const;
233  Real getMaxHeight() const;
234 
240  bool calculateCurrentLod(const Camera* cam, Real cFactor);
241 
243  int getCurrentLod() const { return mCurrentLod; }
245  bool isRenderedAtCurrentLod() const;
247  bool isSelfOrChildRenderedAtCurrentLod() const;
249  void setCurrentLod(int lod);
251  float getLodTransition() const { return mLodTransition; }
253  void setLodTransition(float t);
254 
256  static unsigned short POSITION_BUFFER;
258  static unsigned short DELTA_BUFFER;
259 
260 
261  protected:
264  TerrainQuadTreeNode* mChildren[4];
266 
267  uint16 mOffsetX, mOffsetY;
268  uint16 mBoundaryX, mBoundaryY;
274  Vector3 mLocalCentre; // relative to terrain centre
275  AxisAlignedBox mAABB; //relative to mLocalCentre
276  Real mBoundingRadius; //relative to mLocalCentre
277  int mCurrentLod; // -1 = none (do not render)
278  unsigned short mMaterialLodIndex;
279  float mLodTransition; // 0-1 transition to lower LOD
283 
285  {
300 
302  : cpuVertexData(0), gpuVertexData(0), resolution(res), size(sz),
303  treeLevels(lvls), gpuVertexDataDirty(false) {}
304  };
305 
308 
329  {
330  protected:
332  public:
333  Movable(TerrainQuadTreeNode* parent);
334  ~Movable();
335 
336  // necessary overrides
337  const String& getMovableType(void) const;
338  const AxisAlignedBox& getBoundingBox(void) const;
339  Real getBoundingRadius(void) const;
340  void _updateRenderQueue(RenderQueue* queue);
341  void visitRenderables(Renderable::Visitor* visitor, bool debugRenderables = false);
342  bool isVisible(void) const;
343  uint32 getVisibilityFlags(void) const;
344  uint32 getQueryFlags(void) const;
345  bool getCastShadows(void) const;
346 
347  };
349  friend class Movable;
351 
354  {
355  protected:
357  public:
358  Rend(TerrainQuadTreeNode* parent);
359  ~Rend();
360 
361  const MaterialPtr& getMaterial(void) const;
362  Technique* getTechnique(void) const;
363  void getRenderOperation(RenderOperation& op);
364  void getWorldTransforms(Matrix4* xform) const;
365  Real getSquaredViewDepth(const Camera* cam) const;
366  const LightList& getLights(void) const;
367  bool getCastsShadows(void) const;
368 
369  };
371  friend class Rend;
372 
373  // actual implementation of MovableObject methods
374  void updateRenderQueue(RenderQueue* queue);
375  void visitRenderables(Renderable::Visitor* visitor, bool debugRenderables = false);
376  // actual implementations of Renderable methods
377  const MaterialPtr& getMaterial(void) const;
378  Technique* getTechnique(void) const;
379  void getRenderOperation(RenderOperation& op);
380  void getWorldTransforms(Matrix4* xform) const;
381  Real getSquaredViewDepth(const Camera* cam) const;
382  const LightList& getLights(void) const;
383  bool getCastsShadows(void) const;
384 
385 
386  const VertexDataRecord* getVertexDataRecord() const;
387  void createCpuVertexData();
388  /* Update the vertex buffers - the rect in question is relative to the whole terrain,
389  not the local vertex data (which may use a subset)
390  */
391  void updateVertexBuffer(HardwareVertexBufferSharedPtr& posbuf, HardwareVertexBufferSharedPtr& deltabuf, const Rect& rect);
392  void destroyCpuVertexData();
393 
394  void createGpuVertexData();
395  void destroyGpuVertexData();
396  void updateGpuVertexData();
397  void createGpuIndexData();
398  void destroyGpuIndexData();
399 
400  void populateIndexData(uint16 batchSize, IndexData* destData);
401 
402  uint16 calcSkirtVertexIndex(uint16 mainIndex, bool isCol);
403 
404  };
405 
408 }
409 
410 #endif
A viewpoint from which the scene will be rendered.
Definition: OgreCamera.h:85
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:78
uint16 batchSize
Number of vertices rendered down one side (not including skirts)
float Real
Software floating point type.
unsigned int uint32
Definition: OgrePlatform.h:246
uint16 getXOffset() const
Get the horizontal offset into the main terrain data of this node.
The main containing class for a chunk of terrain.
Definition: OgreTerrain.h:261
IndexData * gpuIndexData
Index data on the gpu.
uint16 skirtRowColSkip
The number of rows / cols to skip in between skirts.
Real calcMaxHeightDelta
Temp calc area for max height delta.
uint16 treeLevels
Number of quadtree levels (including this one) this data applies to.
Shared pointer implementation used to share index buffers.
A 3D box aligned with the x/y/z axes.
vector< LodLevel * >::type LodLevelList
Class representing an approach to rendering this particular Material.
Definition: OgreTechnique.h:53
Abstract class defining a movable object in a scene.
Class representing a node in the scene graph.
Definition: OgreSceneNode.h:57
Abstract class defining the interface all renderable objects must implement.
uint16 resolution
resolution of the data compared to the base terrain data (NOT number of vertices!) ...
Real maxHeightDelta
Maximum delta height between this and the next lower lod.
uint16 getBaseLod() const
Get the base LOD level this node starts at (the highest LOD it handles)
static unsigned short DELTA_BUFFER
Buffer binding used for holding delta values.
int getCurrentLod() const
Get the current LOD index (only valid after calculateCurrentLod)
float getLodTransition() const
Get the transition state between the current LOD and the next lower one (only valid after calculateCu...
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Summary class collecting together index data source information.
VertexDataRecord(uint16 res, uint16 sz, uint16 lvls)
TerrainQuadTreeNode * mChildWithMaxHeightDelta
The child with the largest height delta.
Visitor object that can be used to iterate over a collection of Renderable instances abstractly...
static unsigned short POSITION_BUFFER
Buffer binding used for holding positions.
uint16 getYOffset() const
Get the vertical offset into the main terrain data of this node.
Utility class providing helper methods for reading / writing structured data held in a DataStream...
Standard 3-dimensional vector.
Definition: OgreVector3.h:51
uint16 size
size of the data along one edge
Real lastCFactor
The cFactor value used to calculate transitionDist.
uint16 numSkirtRowsCols
Number of rows and columns of skirts.
Summary class collecting together vertex source information.
'New' rendering operation using vertex buffers.
Real lastTransitionDist
The most recently calculated transition distance.
Class to manage the scene object rendering queue.
const Vector3 & getLocalCentre() const
Get the local centre of this node, relative to parent terrain centre.
MovableObject implementation to provide the hook to the scene.
bool gpuVertexDataDirty
Is the GPU vertex data out of date?
_StringBase String
TerrainQuadTreeNode * mNodeWithVertexData
unsigned short uint16
Definition: OgrePlatform.h:247
Specialisation of SharedPtr to allow SharedPtr to be assigned to MaterialPtr.
Definition: OgreMaterial.h:677
A node in a quad tree used to store a patch of terrain.
unsigned int uint
uint16 mSize
the number of vertices at the original terrain resolution this node encompasses