Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifndef __SP_SCENE_TERRAIN_H__
00009 #define __SP_SCENE_TERRAIN_H__
00010
00011
00012 #include "Base/spStandard.hpp"
00013 #include "Base/spTreeNodeQuad.hpp"
00014 #include "SceneGraph/spSceneMesh.hpp"
00015 #include "RenderSystem/spTextureBase.hpp"
00016
00017 #include <vector>
00018 #include <list>
00019
00020
00021 namespace sp
00022 {
00023 namespace scene
00024 {
00025
00026
00030 class SP_EXPORT Terrain : public MaterialNode
00031 {
00032
00033 public:
00034
00035 Terrain(const video::SHeightMapTexture &HeightMap, const dim::size2di &Resolution, s32 GeoMIPLevels);
00036 virtual ~Terrain();
00037
00038
00039
00040 virtual void render();
00041
00042 void changeHeightMap(
00043 const video::SHeightMapTexture &HeightMap, const dim::size2di &Resolution, s32 GeoMIPLevels
00044 );
00045
00046
00047
00048 inline dim::size2di getResolution() const
00049 {
00050 return Resolution_;
00051 }
00052
00053 inline video::MeshBuffer* getTextureReferenceMesh()
00054 {
00055 return MeshTexReference_;
00056 }
00057
00058 protected:
00059
00060 friend void clbTerrainTreeNodeDestructor(TreeNode* Node);
00061
00062
00063
00064 struct STreeNodeData
00065 {
00066 STreeNodeData();
00067 ~STreeNodeData();
00068
00069
00070
00071 void recreateBottom (bool Lower, const dim::size2di &Resolution);
00072 void recreateTop (bool Lower, const dim::size2di &Resolution);
00073 void recreateLeft (bool Lower, const dim::size2di &Resolution);
00074 void recreateRight (bool Lower, const dim::size2di &Resolution);
00075
00076
00077
00078 s32 MIPLevel;
00079 dim::point2df Center;
00080 dim::size2di Resolution;
00081 dim::aabbox3df BoundBox;
00082 std::vector<f32> EdgeVerticesHeight;
00083 video::MeshBuffer Mesh;
00084 bool Selected;
00085 dim::rect2d<bool> EdgesLower;
00086 };
00087
00088
00089
00090 void init();
00091 void clear();
00092
00093 void createQuadTree(QuadTreeNode* Node, s32 &MIPLevel, dim::point2di CurPos);
00094 void createTreeNodeMesh(QuadTreeNode* Node, STreeNodeData* NodeData, const dim::point2di &CurPos);
00095 void selectTreeNodeMesh(QuadTreeNode* Node);
00096 void renderTreeNodeMesh(QuadTreeNode* Node);
00097 bool deformTreeNodeMesh(QuadTreeNode* Node, const dim::point2df &Pos);
00098
00099 s32 getNodeLevel(const QuadTreeNode* Node, const dim::point2df &Pos);
00100
00101
00102
00103 inline s32 getVertexIndex(s32 x, s32 y) const
00104 {
00105 return y * (MeshResolution_.Width + 1) + x;
00106 }
00107
00108 inline bool checkFurstumCulling(
00109 const scene::ViewFrustum &Frustum, const dim::matrix4f &Transformation, const dim::aabbox3df &BoundBox) const
00110 {
00111 return Frustum.isBoundBoxInside(BoundBox, Transformation);
00112 }
00113
00114
00115
00116 video::SHeightMapTexture HeightMap_;
00117
00118 dim::size2di Resolution_, MeshResolution_;
00119 s32 GeoMIPLevels_;
00120
00121 QuadTreeNode* RootTreeNode_;
00122 video::MeshBuffer* MeshTexReference_;
00123
00124 s32 RenderModeListSize_;
00125 std::vector<QuadTreeNode*> RenderNodeList_;
00126
00127 dim::matrix4f GlobalTerrainTransformation_;
00128 dim::vector3df GlobalCamPosition_;
00129
00130 };
00131
00132
00133 }
00134
00135 }
00136
00137
00138 #endif
00139
00140
00141
00142