My Project
TerrainLattice.h
1 #pragma once
2 #include "IAttributeFields.h"
3 #include "TerrainLoadListener.h"
4 #include "TextureSet.h"
5 #include "TextureFactory.h"
6 #include "TTerrain.h"
7 #include "TerrainGeoMipmapIndices.h"
8 
9 namespace ParaEngine
10 {
11  struct TextureEntity;
12  class TTerrain;
13  class CShapeAABB;
14  class CShapeFrustum;
15 }
16 namespace ParaTerrain
17 {
30  {
31  public:
33  virtual Terrain * LoadTerrainAt(Terrain *pTerrain, int latticeX, int latticeY, bool useGeoMipmap = false) = 0;
35  virtual void UnloadTerrain(int latticeX, int latticeY, Terrain * pTerrain) = 0;
37  virtual float GetTerrainWidth() = 0;
39  virtual float GetTerrainHeight() = 0;
40 
45  virtual bool UpdateTileConfigFile(int x, int y, const string& sTileConfigFile) = 0;
46 
48  virtual bool SaveWorldConfigFile() = 0;
49  };
50 
53 
58  {
59  public:
60  typedef map<int, TerrainTileCacheItem> TerrainTileCacheMap_type;
61  TerrainLattice(TerrainLatticeLoader * pLoader, bool useGeoMipmap = false);
62  virtual ~TerrainLattice();
63 
64  ATTRIBUTE_DEFINE_CLASS(TerrainLattice);
65 
67  virtual IAttributeFields* GetChildAttributeObject(const std::string& sName);
69  virtual int GetChildAttributeObjectCount(int nColumnIndex = 0);
71  virtual int GetChildAttributeColumnCount();
72  virtual IAttributeFields* GetChildAttributeObject(int nRowIndex, int nColumnIndex = 0);
73 
74  void Load(char *szBaseName, int maxNumTriangles, int maxBlockSize, float commonRepeats);
75  void SetTileSize(float fTileSize);
79  Terrain *GetTerrain(int positionX, int positionY);
80  Terrain *GetTerrainAtPoint(float x, float y);
81  void SetCameraPosition(float x, float y, float z);
82  void ModelViewMatrixChanged();
83  void Render();
84  float GetElevation(float x, float y);
85 
90  DWORD GetRegionValue(const string& sLayerName, float x, float y);
91 
98  void GetNormal(float x, float y, float &normalX, float &normalY, float &normalZ);
99  float IntersectRay(float startX, float startY, float startZ, float dirX, float dirY, float dirZ, float &intersectX, float &intersectY, float &intersectZ, float fMaxDistance = INFINITY);
100 
102  void SetLowestVisibleHeight(float fHeight);
104  float GetLowestVisibleHeight();
105 
107  void Paint(ParaEngine::TextureEntity* detailTexture, float brushRadius, float brushIntensity, float maxIntensity, bool erase, float x, float y);
108 
123  void Flatten(float x, float y, float radius, int flatten_op, float elevation, float factor);
124 
135  void DigCircleFlat(float x, float y, float radius, float fFlatPercentage = 0.7f, float factor = 0.5f);
136 
137  /*
138  * This creates a Gaussian hill at the specified location with the specified parameters.
139  * it actually adds the hill to the original terrain surface.
140  * Here ElevNew(x,y) =
141  |(x,y)-(center_x,center_y)| < radius*smooth_factor, ElevOld(x,y)+hscale*exp(-[(x-center_x)^2+(y-center_y)^2]/(2*standard_deviation^2) ),
142  |(x,y)-(center_x,center_y)| > radius*smooth_factor, minimize hill effect.
143  * @param center_x: the center of the affected circle. value in the range [0,1]
144  * @param center_y: the center of the affected circle.value in the range [0,1]
145  * @param radius: the radius of the affected circle.value in the range [0,0.5]
146  * @param hscale: scale factor. One can think of it as the maximum height of the Gaussian Hill. this value can be negative
147  * @param standard_deviation: standard deviation of the unit height value. should be in the range (0,1).
148  * 0.1 is common value. larger than that will just make a flat hill with smoothing.
149  * @param smooth_factor: value is between [0,1]. 1 means fully transformed; 0 means nothing is changed
150  */
151  void GaussianHill(float x, float y, float radius, float hscale, float standard_deviation = 0.1f, float smooth_factor = 0.5f);
152 
159  void Spherical(float x, float y, float radius, float offset);
160 
172  void RadialScale(float x, float y, float scale_factor, float min_dist, float max_dist, float smooth_factor = 0.5f, int frequency = 1);
173 
188  void Roughen_Smooth(float x, float y, float radius, bool roughen = false, bool big_grid = false, float factor = 0.5f);
189 
199  void AddHeightField(float x, float y, const char* filename, int nSmoothPixels = 7);
219  void MergeHeightField(float x, float y, const char* filename, int mergeOperation = 0, float weight1 = 1.0, float weight2 = 1.0, int nSmoothPixels = 7);
220 
227  void Ramp(float x1, float y1, float x2, float y2, float radius, float borderpercentage = 0.5f, float factor = 1.0f);
228 
233  void UpdateHoles(float x, float y);
241  bool IsHole(float x, float y);
250  void SetHole(float x, float y, bool bIsHold);
251 
252  void InitDeviceObjects();
253  void DeleteDeviceObjects();
254  void InvalidateDeviceObjects();
255 
259  float GetVertexElevation(float x, float y);
264  void SetVertexElevation(float x, float y, float newElevation, bool recalculate_geometry = true);
265 
269  float GetVertexSpacing() const;
276  bool SnapPointToVertexGrid(float& x, float& y);
277 
283  int GetMaxTileCacheSize();
284 
290  void SetMaxTileCacheSize(int nNum);
291 
293  void ResizeTextureMaskWidth(int nWidth);
294 
296  void SetGlobalConfigModified(bool bEnable = true);
297  private:
306  bool Copy_Rect_to_HeightField(ParaEngine::TTerrain* pHeightField, float x, float y, float fRadius, bool bNormalize = true);
315  bool Apply_HeightField_to_Rect(ParaEngine::TTerrain* pHeightField, float x, float y, bool bRecalculateGeometry, bool bRecoverHeightData = true);
321  void RecalculateTerrainGeometry(float x, float y, float fRadius);
322 
323  void Tessellate();
324  Terrain * CreateTerrainTile(int positionX, int positionY);
325  ParaTerrain::DIRECTION GetOppositeDirection(ParaTerrain::DIRECTION direction);
326  Terrain *GetTerrainRelative(Terrain * pTerrain, int positionX, int positionY);
327  Terrain *GetTerrainRelative(Terrain * pTerrain, ParaTerrain::DIRECTION direction);
328  Terrain *LoadTerrain(int index);
329  TerrainLatticeLoader *m_pLoader;
330  //int m_WidthTerrains, m_HeightTerrains;
331  int m_WidthActiveTerrains, m_HeightActiveTerrains;
332  float m_TerrainWidth, m_TerrainHeight;
334  float m_fLowestVisibleHeight;
335 
337  TerrainTileCacheMap_type m_pCachedTerrains;
338  int m_nMaxCacheSize;
339 
340  int m_CurrentTerrainIndex[9];
341 
343  CShapeBox m_BoundingBox;
345  bool m_bIsGlobalConfigModified;
346  public:
348  const CShapeBox& GetBoundingBox() const;
358  void GetBoundingBoxes(vector<ParaEngine::CShapeAABB>& boxes, const Matrix4* modelView, const ParaEngine::CShapeFrustum& frustum, int nMaxBoxesNum = 1024, int nSmallestBoxStride = 4);
359 
361  static int GetTileIDFromXY(int X, int Y);
364  static bool GetXYFromTileID(int nTileID, int* X, int* Y);
365 
367  void SetAllLoadedModified(bool bIsModified = true, DWORD dwModifiedBits = 16);
368 
373  void SaveTerrain(bool bHeightMap, bool bTextures);
375  bool IsModified();
376 
377  public:
378  bool m_useGeoMipmap;
379  void SwitchLodStyle(bool useGeoMipmap);
380  bool IsWalkable(float x, float y, Vector3& oNormal);
381  void SetTerrainInfo(float x, float y, float radius, uint32 data, uint32 bitMask, uint32 bitOffset);
382  uint32 GetTerrainInfo(float x, float y, uint32 bitMask, uint32 bitOffset);
383  void SetEditorMode(bool enable);
384  void SetVisibleDataMask(uint32 mask, uint8 bitOffset);
385  private:
386  ParaIndexBuffer m_pIndices;
387 
388  GeoMipmapIndicesGroup m_geoMipmapIndices;
389  int m_terrainBlockXCount;
390  float m_camPosX;
391  float m_camPosY;
392  int m_Level0ChunkCount;;
393  int m_Level1ChunkCount;
394 
395  void CreateGeoMipmapIndexBuffer();
396  void GetIndexInfo(int level, GeoMipmapChunkType type);
397  void CalcGeoMipmapLod(float camX, float camY);
398  int CalcBlockLod(int* lodBounds, int blockIndexX, int blockIndexY, int maxLod);
399 
400  void SetVertexInfo(float x, float y, uint32 data, uint32 bitMask, uint32 bitOffset);
401  };
402 }
Which DXT Compression to Use? Obviously, there are some trade-offs between the different formats whic...
Definition: TextureEntity.h:29
Definition: SceneObject.h:15
Definition: TerrainGeoMipmapIndices.h:36
virtual float GetTerrainWidth()=0
Returns the width in world units of each of the individual Terrain objects in the lattice (they must ...
temp height field terrain data used by terrain filters.
Definition: TTerrain.h:16
different physics engine has different winding order.
Definition: EventBinding.h:32
virtual float GetTerrainHeight()=0
Returns the height in world units of each of the individual Terrain objects in the lattice (they must...
Standard 3-dimensional vector.
Definition: ParaVector3.h:16
virtual void UnloadTerrain(int latticeX, int latticeY, Terrain *pTerrain)=0
Called by the TerrainLattice when a Terrain object in the lattice is no longer within the visible reg...
virtual Terrain * LoadTerrainAt(Terrain *pTerrain, int latticeX, int latticeY, bool useGeoMipmap=false)=0
Called by the TerrainLattice when a Terrain object in the lattice has entered the visible region and...
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: ParaMatrix4.h:23
in OpenGL, there is no different between vertex and index buffer.
Definition: ParaVertexBuffer.h:78
A common interface for all classes implementing IAttributeFields By implementing this class&#39;s virtual...
Definition: IAttributeFields.h:59
You derive a concrete implementation of this interface in order to serve Terrains up to a TerrainLatt...
Definition: TerrainLattice.h:29
This class represents a single, contiguous chunk of terrain and is the primary public interface to De...
Definition: Terrain.h:386
Manages a network of Terrain objects arranged in a grid pattern to model extremely large worlds that ...
Definition: TerrainLattice.h:57
a general view frustum class.
Definition: ShapeFrustum.h:9
virtual bool UpdateTileConfigFile(int x, int y, const string &sTileConfigFile)=0
update the tile config file for the terrain terrain tile x,y.
a min max box.
Definition: ShapeAABB.h:190
virtual bool SaveWorldConfigFile()=0
save world config file to disk.