My Project
TTerrain.h
1 #pragma once
2 
3 namespace ParaTerrain
4 {
5  class Terrain;
6 }
7 
8 namespace ParaEngine
9 {
10  using namespace ParaTerrain;
16  class TTerrain
17  {
18  private:
20  float fMin,fMax;
22  float y_scale_factor;
24  bool bIsNormalized;
25 
26  public:
28  int width, height;
29  float fVertexSpacing;
30  float* heightfield;
31  float* selection;
32 
34  float sealevel;
35  public:
36  inline float* GetHeightmap(){return heightfield;};
44  void Normalize();
46  void NormalizeHeight(float& height);
49  void Recover();
51  bool CreatePlane(int gridSize, float fHeight, float fVertexSpacing_=1 );
56  bool CreatePlane(const char* filename,float fVertexSpacing = 1);
57 
59  void SetHeight(int x, int y, float fValue);
63  float GetHeight(int x, int y);
65  float GetHeightFinal(int x, int y);
66 
67  float GetVertexSpacing();
68  void SetVertexSpacing(float fSpacing);
69 
70  float GetMinHeight();
71  void SetMinHeight(float fMinHeight);
72 
73  float GetMaxHeight();
75  float GetYScale();
76  int GetGridSize();
77 
79  void SetNormalized(bool bSet);
81  bool IsNormalized();
82 
84  int GetGridWidth(){return width;}
85  int GetGridHeight(){return height;}
86  public:
87  TTerrain();
88  ~TTerrain();
90  void Cleanup();
91 
92  friend class CTerrainFilters;
93  };
94 
99  {
101  union
102  {
103  Terrain * pTerrain;
104  TTerrain* pHeightmap;
105  };
106 
110  DWORD nHitCount;
111  TerrainTileCacheItem(Terrain * pTerrain)
112  {
113  this->pTerrain = pTerrain;
114  this->nHitCount = 1<<31;
115  }
116  TerrainTileCacheItem(TTerrain * pHeightmap)
117  {
118  this->pHeightmap = pHeightmap;
119  this->nHitCount = 1<<31;
120  }
122  {
123  this->pTerrain = NULL;
124  this->nHitCount = 1<<31;
125  }
127  void OnHit(){
128  this->nHitCount |= 1<<31;
129  }
131  void FrameMove(){
132  if(this->nHitCount<0x0000ffff)
133  this->nHitCount --;
134  else
135  this->nHitCount = this->nHitCount>>1;
136  }
137  };
138 }
void SetNormalized(bool bSet)
set whether the heightfield data is normalized.
Definition: TTerrain.cpp:135
Definition: SceneObject.h:15
temp height field terrain data used by terrain filters.
Definition: TTerrain.h:16
different physics engine has different winding order.
Definition: EventBinding.h:32
float GetHeightFinal(int x, int y)
get the unnormalized (final) height at the specified gird position.
Definition: TTerrain.cpp:117
void Recover()
recover normalized data back: i.e.
Definition: TTerrain.cpp:200
void Normalize()
it is good practice to normalize terrain height field before computation, this will increase floating...
Definition: TTerrain.cpp:140
void FrameMove()
this is called every rendering frame.
Definition: TTerrain.h:131
void SetHeight(int x, int y, float fValue)
set the height at the specified gird position.
Definition: TTerrain.cpp:107
a cached Terrain tile item
Definition: TTerrain.h:98
bool IsNormalized()
whether height field data is normalized
Definition: TTerrain.cpp:131
float sealevel
sea level
Definition: TTerrain.h:34
void OnHit()
on hit
Definition: TTerrain.h:127
int width
size of the terrain.
Definition: TTerrain.h:28
TTerrain()
TTerrain class.
Definition: TTerrain.cpp:23
void NormalizeHeight(float &height)
normalize a height using current setting
Definition: TTerrain.cpp:175
float GetHeight(int x, int y)
Get the height at the specified gird position.
Definition: TTerrain.cpp:112
int GetGridWidth()
get the grid size
Definition: TTerrain.h:84
DWORD nHitCount
a bits mask of number of times that this tile is hit in the last 32 render frames.
Definition: TTerrain.h:110
This class represents a single, contiguous chunk of terrain and is the primary public interface to De...
Definition: Terrain.h:386
Perform filtering on a terrain height field.
Definition: TerrainFilters.h:12
void Cleanup()
delete terrain data
Definition: TTerrain.cpp:34
float GetYScale()
Note: if 0 is returned, it means that there is no scale.
Definition: TTerrain.cpp:102
bool CreatePlane(int gridSize, float fHeight, float fVertexSpacing_=1)
create an unnormalized plane containing gridSize*gridSize number of vertices
Definition: TTerrain.cpp:40