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-2013 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 load(uint16 depthStart, uint16 depthEnd);
126  void loadSelf();
128  void unload();
130  void unload(uint16 depthStart, uint16 depthEnd);
132  void unprepare();
134  void save(StreamSerialiser& stream);
135 
137  {
150 
151  LodLevel() : gpuIndexData(0), maxHeightDelta(0), calcMaxHeightDelta(0),
152  lastTransitionDist(0), lastCFactor(0) {}
153  };
155 
161  const LodLevel* getLodLevel(uint16 lod);
162 
167  void preDeltaCalculation(const Rect& rect);
168 
170  void notifyDelta(uint16 x, uint16 y, uint16 lod, Real delta);
171 
174  void postDeltaCalculation(const Rect& rect);
175 
179  void finaliseDeltaValues(const Rect& rect);
180 
187  void assignVertexData(uint16 treeDepthStart, uint16 treeDepthEnd, uint16 resolution, uint sz);
188 
193  void useAncestorVertexData(TerrainQuadTreeNode* owner, uint16 treeDepthEnd, uint16 resolution);
194 
197  void updateVertexData(bool positions, bool deltas, const Rect& rect, bool cpuData);
198 
199 
200 
207  void mergeIntoBounds(long x, long y, const Vector3& pos);
211  void resetBounds(const Rect& rect);
212 
217  bool rectIntersectsNode(const Rect& rect);
222  bool rectContainsNode(const Rect& rect);
227  bool pointIntersectsNode(long x, long y);
228 
230  const AxisAlignedBox& getAABB() const;
232  Real getBoundingRadius() const;
234  const Vector3& getLocalCentre() const { return mLocalCentre; }
236  Real getMinHeight() const;
238  Real getMaxHeight() const;
239 
245  bool calculateCurrentLod(const Camera* cam, Real cFactor);
246 
248  int getCurrentLod() const { return mCurrentLod; }
250  bool isRenderedAtCurrentLod() const;
252  bool isSelfOrChildRenderedAtCurrentLod() const;
254  void setCurrentLod(int lod);
256  float getLodTransition() const { return mLodTransition; }
258  void setLodTransition(float t);
259 
261  static unsigned short POSITION_BUFFER;
263  static unsigned short DELTA_BUFFER;
264 
266  Renderable *_getRenderable();
267  protected:
270  TerrainQuadTreeNode* mChildren[4];
272 
273  uint16 mOffsetX, mOffsetY;
274  uint16 mBoundaryX, mBoundaryY;
284  unsigned short mMaterialLodIndex;
286  TerrainQuadTreeNode* mChildWithMaxHeightDelta;
289 
291  {
306 
308  : cpuVertexData(0), gpuVertexData(0), resolution(res), size(sz),
309  treeLevels(lvls), gpuVertexDataDirty(false) {}
310  };
311 
314 
335  {
336  protected:
338  public:
339  Movable(TerrainQuadTreeNode* parent);
340  virtual ~Movable();
341 
342  // necessary overrides
343  const String& getMovableType(void) const;
344  const AxisAlignedBox& getBoundingBox(void) const;
345  Real getBoundingRadius(void) const;
346  void _updateRenderQueue(RenderQueue* queue);
347  void visitRenderables(Renderable::Visitor* visitor, bool debugRenderables = false);
348  bool isVisible(void) const;
349  uint32 getVisibilityFlags(void) const;
350  uint32 getQueryFlags(void) const;
351  bool getCastShadows(void) const;
352 
353  };
355  friend class Movable;
357 
360  {
361  protected:
363  public:
364  Rend(TerrainQuadTreeNode* parent);
365  virtual ~Rend();
366 
367  const MaterialPtr& getMaterial(void) const;
368  Technique* getTechnique(void) const;
369  void getRenderOperation(RenderOperation& op);
370  void getWorldTransforms(Matrix4* xform) const;
371  Real getSquaredViewDepth(const Camera* cam) const;
372  const LightList& getLights(void) const;
373  bool getCastsShadows(void) const;
374 
375  };
377  friend class Rend;
378 
379  // actual implementation of MovableObject methods
380  void updateRenderQueue(RenderQueue* queue);
381  void visitRenderables(Renderable::Visitor* visitor, bool debugRenderables = false);
382  // actual implementations of Renderable methods
383  const MaterialPtr& getMaterial(void) const;
384  Technique* getTechnique(void) const;
385  void getRenderOperation(RenderOperation& op);
386  void getWorldTransforms(Matrix4* xform) const;
387  Real getSquaredViewDepth(const Camera* cam) const;
388  const LightList& getLights(void) const;
389  bool getCastsShadows(void) const;
390 
391 
392  const VertexDataRecord* getVertexDataRecord() const;
393  void createCpuVertexData();
394  /* Update the vertex buffers - the rect in question is relative to the whole terrain,
395  not the local vertex data (which may use a subset)
396  */
397  void updateVertexBuffer(HardwareVertexBufferSharedPtr& posbuf, HardwareVertexBufferSharedPtr& deltabuf, const Rect& rect);
398  void destroyCpuVertexData();
399 
400  void createGpuVertexData();
401  void destroyGpuVertexData();
402  void updateGpuVertexData();
403  void createGpuIndexData();
404  void destroyGpuIndexData();
405 
406  void populateIndexData(uint16 batchSize, IndexData* destData);
407  void writePosVertex(bool compress, uint16 x, uint16 y, float height, const Vector3& pos, float uvScale, float** ppPos);
408  void writeDeltaVertex(bool compress, uint16 x, uint16 y, float delta, float deltaThresh, float** ppDelta);
409 
410  uint16 calcSkirtVertexIndex(uint16 mainIndex, bool isCol);
411 
412  };
413 
416 }
417 
418 #endif

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Wed Oct 23 2013 06:57:26