OgreTerrainQuadTreeNode.h
Go to the documentation of this file.

    00001 /*
    00002 -----------------------------------------------------------------------------
    00003 This source file is part of OGRE
    00004 (Object-oriented Graphics Rendering Engine)
    00005 For the latest info, see http://www.ogre3d.org/
    00006
    00007 Copyright (c) 2000-2012 Torus Knot Software Ltd
    00008
    00009 Permission is hereby granted, free of charge, to any person obtaining a copy
    00010 of this software and associated documentation files (the "Software"), to deal
    00011 in the Software without restriction, including without limitation the rights
    00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    00013 copies of the Software, and to permit persons to whom the Software is
    00014 furnished to do so, subject to the following conditions:
    00015
    00016 The above copyright notice and this permission notice shall be included in
    00017 all copies or substantial portions of the Software.
    00018
    00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    00025 THE SOFTWARE.
    00026 -----------------------------------------------------------------------------
    00027 */
    00028
    00029 #ifndef __Ogre_TerrainQuadTreeNode_H__
    00030 #define __Ogre_TerrainQuadTreeNode_H__
    00031
    00032 #include "OgreTerrainPrerequisites.h"
    00033 #include "OgreCommon.h"
    00034 #include "OgreHardwareIndexBuffer.h"
    00035 #include "OgreMovableObject.h"
    00036 #include "OgreRenderable.h"
    00037
    00038
    00039
    00040 namespace Ogre
    00041 {
    00042     class HardwareVertexBufferSharedPtr;
    00043
    00085     class _OgreTerrainExport TerrainQuadTreeNode : public TerrainAlloc
    00086     {
    00087     public:
    00097         TerrainQuadTreeNode(Terrain* terrain, TerrainQuadTreeNode* parent,
    00098             uint16 xoff, uint16 yoff, uint16 size, uint16 lod, uint16 depth, uint16 quadrant);
    00099         virtual ~TerrainQuadTreeNode();
    00100
    00102         uint16 getXOffset() const { return mOffsetX; }
    00104         uint16 getYOffset() const { return mOffsetY; }
    00106         bool isLeaf() const;
    00108         uint16 getBaseLod() const { return mBaseLod; }
    00110         uint16 getLodCount() const;
    00112         TerrainQuadTreeNode* getChild(unsigned short child) const;
    00114         TerrainQuadTreeNode* getParent() const;
    00116         Terrain* getTerrain() const;
    00117
    00119         void prepare();
    00121         void prepare(StreamSerialiser& stream);
    00123         void load();
    00125         void unload();
    00127         void unprepare();
    00129         void save(StreamSerialiser& stream);
    00130
    00131         struct _OgreTerrainExport LodLevel : public TerrainAlloc
    00132         {
    00134             uint16 batchSize;
    00136             IndexData* gpuIndexData;
    00138             Real maxHeightDelta;
    00140             Real calcMaxHeightDelta;
    00142             Real lastTransitionDist;
    00144             Real lastCFactor;
    00145
    00146             LodLevel() : gpuIndexData(0), maxHeightDelta(0), calcMaxHeightDelta(0),
    00147                 lastTransitionDist(0), lastCFactor(0) {}
    00148         };
    00149         typedef vector<LodLevel*>::type LodLevelList;
    00150
    00156         const LodLevel* getLodLevel(uint16 lod);
    00157
    00162         void preDeltaCalculation(const Rect& rect);
    00163
    00165         void notifyDelta(uint16 x, uint16 y, uint16 lod, Real delta);
    00166
    00169         void postDeltaCalculation(const Rect& rect);
    00170
    00174         void finaliseDeltaValues(const Rect& rect);
    00175
    00182         void assignVertexData(uint16 treeDepthStart, uint16 treeDepthEnd, uint16 resolution, uint sz);
    00183
    00188         void useAncestorVertexData(TerrainQuadTreeNode* owner, uint16 treeDepthEnd, uint16 resolution);
    00189
    00192         void updateVertexData(bool positions, bool deltas, const Rect& rect, bool cpuData);
    00193
    00194
    00195
    00202         void mergeIntoBounds(long x, long y, const Vector3& pos);
    00206         void resetBounds(const Rect& rect);
    00207
    00212         bool rectIntersectsNode(const Rect& rect);
    00217         bool rectContainsNode(const Rect& rect);
    00222         bool pointIntersectsNode(long x, long y);
    00223
    00225         const AxisAlignedBox& getAABB() const;
    00227         Real getBoundingRadius() const;
    00229         const Vector3& getLocalCentre() const { return mLocalCentre; }
    00231         Real getMinHeight() const;
    00233         Real getMaxHeight() const;
    00234
    00240         bool calculateCurrentLod(const Camera* cam, Real cFactor);
    00241
    00243         int getCurrentLod() const { return mCurrentLod; }
    00245         bool isRenderedAtCurrentLod() const;
    00247         bool isSelfOrChildRenderedAtCurrentLod() const;
    00249         void setCurrentLod(int lod);
    00251         float getLodTransition() const { return mLodTransition; }
    00253         void setLodTransition(float t);
    00254
    00256         static unsigned short POSITION_BUFFER;
    00258         static unsigned short DELTA_BUFFER;
    00259
    00261         Renderable *_getRenderable();
    00262     protected:
    00263         Terrain* mTerrain;
    00264         TerrainQuadTreeNode* mParent;
    00265         TerrainQuadTreeNode* mChildren[4];
    00266         LodLevelList mLodLevels;
    00267
    00268         uint16 mOffsetX, mOffsetY;
    00269         uint16 mBoundaryX, mBoundaryY;
    00271         uint16 mSize;
    00272         uint16 mBaseLod;
    00273         uint16 mDepth;
    00274         uint16 mQuadrant;
    00275         Vector3 mLocalCentre; // relative to terrain centre
    00276         AxisAlignedBox mAABB; //relative to mLocalCentre
    00277         Real mBoundingRadius; //relative to mLocalCentre
    00278         int mCurrentLod; // -1 = none (do not render)
    00279         unsigned short mMaterialLodIndex;
    00280         float mLodTransition; // 0-1 transition to lower LOD
    00282         TerrainQuadTreeNode* mChildWithMaxHeightDelta;
    00283         bool mSelfOrChildRendered;
    00284
    00285         struct VertexDataRecord : public TerrainAlloc
    00286         {
    00287             VertexData* cpuVertexData;
    00288             VertexData* gpuVertexData;
    00290             uint16 resolution;
    00292             uint16 size;
    00294             uint16 treeLevels;
    00296             uint16 numSkirtRowsCols;
    00298             uint16 skirtRowColSkip;
    00300             bool gpuVertexDataDirty;
    00301
    00302             VertexDataRecord(uint16 res, uint16 sz, uint16 lvls)
    00303                 : cpuVertexData(0), gpuVertexData(0), resolution(res), size(sz),
    00304                 treeLevels(lvls), gpuVertexDataDirty(false) {}
    00305         };
    00306
    00307         TerrainQuadTreeNode* mNodeWithVertexData;
    00308         VertexDataRecord* mVertexDataRecord;
    00309
    00329         class _OgreTerrainExport Movable : public MovableObject
    00330         {
    00331         protected:
    00332             TerrainQuadTreeNode* mParent;
    00333         public:
    00334             Movable(TerrainQuadTreeNode* parent);
    00335             ~Movable();
    00336
    00337             // necessary overrides
    00338             const String& getMovableType(void) const;
    00339             const AxisAlignedBox& getBoundingBox(void) const;
    00340             Real getBoundingRadius(void) const;
    00341             void _updateRenderQueue(RenderQueue* queue);
    00342             void visitRenderables(Renderable::Visitor* visitor,  bool debugRenderables = false);
    00343             bool isVisible(void) const;
    00344             uint32 getVisibilityFlags(void) const;
    00345             uint32 getQueryFlags(void) const;
    00346             bool getCastShadows(void) const;
    00347
    00348         };
    00349         Movable* mMovable;
    00350         friend class Movable;
    00351         SceneNode* mLocalNode;
    00352
    00354         class _OgreTerrainExport Rend : public Renderable, public TerrainAlloc
    00355         {
    00356         protected:
    00357             TerrainQuadTreeNode* mParent;
    00358         public:
    00359             Rend(TerrainQuadTreeNode* parent);
    00360             ~Rend();
    00361
    00362             const MaterialPtr& getMaterial(void) const;
    00363             Technique* getTechnique(void) const;
    00364             void getRenderOperation(RenderOperation& op);
    00365             void getWorldTransforms(Matrix4* xform) const;
    00366             Real getSquaredViewDepth(const Camera* cam) const;
    00367             const LightList& getLights(void) const;
    00368             bool getCastsShadows(void) const;
    00369
    00370         };
    00371         Rend* mRend;
    00372         friend class Rend;
    00373
    00374         // actual implementation of MovableObject methods
    00375         void updateRenderQueue(RenderQueue* queue);
    00376         void visitRenderables(Renderable::Visitor* visitor,  bool debugRenderables = false);
    00377         // actual implementations of Renderable methods
    00378         const MaterialPtr& getMaterial(void) const;
    00379         Technique* getTechnique(void) const;
    00380         void getRenderOperation(RenderOperation& op);
    00381         void getWorldTransforms(Matrix4* xform) const;
    00382         Real getSquaredViewDepth(const Camera* cam) const;
    00383         const LightList& getLights(void) const;
    00384         bool getCastsShadows(void) const;
    00385
    00386
    00387         const VertexDataRecord* getVertexDataRecord() const;
    00388         void createCpuVertexData();
    00389         /* Update the vertex buffers - the rect in question is relative to the whole terrain,
    00390             not the local vertex data (which may use a subset)
    00391         */
    00392         void updateVertexBuffer(HardwareVertexBufferSharedPtr& posbuf, HardwareVertexBufferSharedPtr& deltabuf, const Rect& rect);
    00393         void destroyCpuVertexData();
    00394
    00395         void createGpuVertexData();
    00396         void destroyGpuVertexData();
    00397         void updateGpuVertexData();
    00398         void createGpuIndexData();
    00399         void destroyGpuIndexData();
    00400
    00401         void populateIndexData(uint16 batchSize, IndexData* destData);
    00402         void writePosVertex(bool compress, uint16 x, uint16 y, float height, const Vector3& pos, float uvScale, float** ppPos);
    00403         void writeDeltaVertex(bool compress, uint16 x, uint16 y, float delta, float deltaThresh, float** ppDelta);
    00404
    00405         uint16 calcSkirtVertexIndex(uint16 mainIndex, bool isCol);
    00406
    00407     };
    00408
    00411 }
    00412
    00413 #endif

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun Sep 2 2012 07:27:24