OpenMW
|
00001 #ifndef COMPONENTS_TERRAIN_QUADTREENODE_H 00002 #define COMPONENTS_TERRAIN_QUADTREENODE_H 00003 00004 #include <OgreAxisAlignedBox.h> 00005 #include <OgreVector2.h> 00006 #include <OgreTexture.h> 00007 00008 #include <components/loadinglistener/loadinglistener.hpp> 00009 00010 namespace Ogre 00011 { 00012 class Rectangle2D; 00013 } 00014 00015 namespace Terrain 00016 { 00017 class World; 00018 class Chunk; 00019 class MaterialGenerator; 00020 00021 enum Direction 00022 { 00023 North = 0, 00024 East = 1, 00025 South = 2, 00026 West = 3 00027 }; 00028 00029 enum ChildDirection 00030 { 00031 NW = 0, 00032 NE = 1, 00033 SW = 2, 00034 SE = 3, 00035 Root 00036 }; 00037 00043 class QuadTreeNode 00044 { 00045 public: 00051 QuadTreeNode (World* terrain, ChildDirection dir, float size, const Ogre::Vector2& center, QuadTreeNode* parent); 00052 ~QuadTreeNode(); 00053 00054 void setVisible(bool visible); 00055 00057 void applyMaterials(); 00058 00060 void initNeighbours(); 00064 void initAabb(); 00065 00067 void createChild (ChildDirection id, float size, const Ogre::Vector2& center); 00068 00072 void markAsDummy() { mIsDummy = true; } 00073 bool isDummy() { return mIsDummy; } 00074 00075 QuadTreeNode* getParent() { return mParent; } 00076 00077 Ogre::SceneNode* getSceneNode() { return mSceneNode; } 00078 00079 int getSize() { return mSize; } 00080 Ogre::Vector2 getCenter() { return mCenter; } 00081 00082 bool hasChildren() { return mChildren[0] != 0; } 00083 QuadTreeNode* getChild(ChildDirection dir) { return mChildren[dir]; } 00084 00086 QuadTreeNode* getNeighbour (Direction dir); 00087 00089 ChildDirection getDirection() { return mDirection; } 00090 00093 void setBoundingBox (const Ogre::AxisAlignedBox& box); 00094 00096 const Ogre::AxisAlignedBox& getBoundingBox(); 00097 00098 World* getTerrain() { return mTerrain; } 00099 00101 void update (const Ogre::Vector3& cameraPos, Loading::Listener* loadingListener); 00102 00105 void updateIndexBuffers(); 00106 00108 void destroyChunks(bool children); 00109 00112 size_t getNativeLodLevel() { return mLodLevel; } 00113 00115 size_t getActualLodLevel(); 00116 00118 bool hasChunk(); 00119 00125 void prepareForCompositeMap(Ogre::TRect<float> area); 00126 00127 private: 00128 // Stored here for convenience in case we need layer list again 00129 MaterialGenerator* mMaterialGenerator; 00130 00133 bool mIsActive; 00134 00135 bool mIsDummy; 00136 float mSize; 00137 size_t mLodLevel; // LOD if we were to render this node in one chunk 00138 Ogre::AxisAlignedBox mBounds; 00139 Ogre::AxisAlignedBox mWorldBounds; 00140 ChildDirection mDirection; 00141 Ogre::Vector2 mCenter; 00142 00143 Ogre::SceneNode* mSceneNode; 00144 00145 QuadTreeNode* mParent; 00146 QuadTreeNode* mChildren[4]; 00147 QuadTreeNode* mNeighbours[4]; 00148 00149 Chunk* mChunk; 00150 00151 World* mTerrain; 00152 00153 Ogre::TexturePtr mCompositeMap; 00154 00155 void ensureLayerInfo(); 00156 void ensureCompositeMap(); 00157 }; 00158 00159 } 00160 00161 #endif