TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
TerrainBuilder.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
3  * Copyright (C) 2005-2011 MaNGOS <http://getmangos.com/>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; either version 2 of the License, or (at your
8  * option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef _MMAP_TERRAIN_BUILDER_H
20 #define _MMAP_TERRAIN_BUILDER_H
21 
22 #include "PathCommon.h"
23 #include "WorldModel.h"
24 
25 #include "G3D/Array.h"
26 #include "G3D/Vector3.h"
27 #include "G3D/Matrix3.h"
28 
29 namespace MMAP
30 {
31  enum Spot
32  {
33  TOP = 1,
34  RIGHT = 2,
35  LEFT = 3,
36  BOTTOM = 4,
37  ENTIRE = 5
38  };
39 
40  enum Grid
41  {
44  };
45 
46  static const int V9_SIZE = 129;
47  static const int V9_SIZE_SQ = V9_SIZE*V9_SIZE;
48  static const int V8_SIZE = 128;
49  static const int V8_SIZE_SQ = V8_SIZE*V8_SIZE;
50  static const float GRID_SIZE = 533.3333f;
51  static const float GRID_PART_SIZE = GRID_SIZE/V8_SIZE;
52 
53  // see contrib/extractor/system.cpp, CONF_use_minHeight
54  static const float INVALID_MAP_LIQ_HEIGHT = -500.f;
55  static const float INVALID_MAP_LIQ_HEIGHT_MAX = 5000.0f;
56 
57  // see following files:
58  // contrib/extractor/system.cpp
59  // src/game/Map.cpp
60 
61  struct MeshData
62  {
65 
69 
70  // offmesh connection data
71  G3D::Array<float> offMeshConnections; // [p0y,p0z,p0x,p1y,p1z,p1x] - per connection
76  };
77 
79  {
80  public:
81  TerrainBuilder(bool skipLiquid);
83 
84  void loadMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData);
85  bool loadVMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData);
86  void loadOffMeshConnections(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData, const char* offMeshFilePath);
87 
88  bool usesLiquids() { return !m_skipLiquid; }
89 
90  // vert and triangle methods
91  static void transform(std::vector<G3D::Vector3> &original, std::vector<G3D::Vector3> &transformed,
92  float scale, G3D::Matrix3 &rotation, G3D::Vector3 &position);
93  static void copyVertices(std::vector<G3D::Vector3> &source, G3D::Array<float> &dest);
94  static void copyIndices(std::vector<VMAP::MeshTriangle> &source, G3D::Array<int> &dest, int offest, bool flip);
95  static void copyIndices(G3D::Array<int> &src, G3D::Array<int> &dest, int offset);
96  static void cleanVertices(G3D::Array<float> &verts, G3D::Array<int> &tris);
97  private:
99  bool loadMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData, Spot portion);
100 
102  void getLoopVars(Spot portion, int &loopStart, int &loopEnd, int &loopInc);
103 
106 
108  bool loadHeightMap(uint32 mapID, uint32 tileX, uint32 tileY, G3D::Array<float> &vertices, G3D::Array<int> &triangles, Spot portion);
109 
111  void getHeightCoord(int index, Grid grid, float xOffset, float yOffset, float* coord, float* v);
112 
114  void getHeightTriangle(int square, Spot triangle, int* indices, bool liquid = false);
115 
117  bool isHole(int square, uint8 const holes[16][16][8]);
118 
120  void getLiquidCoord(int index, int index2, float xOffset, float yOffset, float* coord, float* v);
121 
123  uint8 getLiquidType(int square, const uint8 liquid_type[16][16]);
124 
125  // hide parameterless and copy constructor
126  TerrainBuilder();
127  TerrainBuilder(const TerrainBuilder &tb);
128  };
129 }
130 
131 #endif
132 
Definition: TerrainBuilder.h:43
Definition: TerrainBuilder.h:35
void getHeightCoord(int index, Grid grid, float xOffset, float yOffset, float *coord, float *v)
Get the vector coordinate for a specific position.
Definition: TerrainBuilder.cpp:526
Definition: TerrainBuilder.h:34
bool usesLiquids()
Definition: TerrainBuilder.h:88
Definition: TerrainBuilder.h:78
void loadMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData)
Definition: TerrainBuilder.cpp:122
Definition: adtfile.h:46
static void cleanVertices(G3D::Array< float > &verts, G3D::Array< int > &tris)
Definition: TerrainBuilder.cpp:838
~TerrainBuilder()
Definition: TerrainBuilder.cpp:86
bool loadHeightMap(uint32 mapID, uint32 tileX, uint32 tileY, G3D::Array< float > &vertices, G3D::Array< int > &triangles, Spot portion)
Load the map terrain from file.
static const int V8_SIZE
Definition: TerrainBuilder.h:48
G3D::Array< unsigned char > offMeshConnectionDirs
Definition: TerrainBuilder.h:73
G3D::Array< unsigned short > offMeshConnectionsFlags
Definition: TerrainBuilder.h:75
Definition: TerrainBuilder.h:42
static const int V9_SIZE_SQ
Definition: TerrainBuilder.h:47
bool isHole(int square, uint8 const holes[16][16][8])
Determines if the specific position's triangles should be rendered.
Definition: TerrainBuilder.cpp:603
Definition: Grid.h:46
G3D::Array< float > offMeshConnectionRads
Definition: TerrainBuilder.h:72
Definition: MMapFactory.cpp:22
G3D::Array< int > liquidTris
Definition: TerrainBuilder.h:67
Definition: Vector3.h:58
G3D::Array< uint8 > liquidType
Definition: TerrainBuilder.h:68
Definition: TerrainBuilder.h:37
G3D::Array< int > solidTris
Definition: TerrainBuilder.h:64
bool m_skipLiquid
Controls whether liquids are loaded.
Definition: TerrainBuilder.h:105
void getLiquidCoord(int index, int index2, float xOffset, float yOffset, float *coord, float *v)
Get the liquid vector coordinate for a specific position.
Definition: TerrainBuilder.cpp:593
bool loadVMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData)
Definition: TerrainBuilder.cpp:627
G3D::Array< float > liquidVerts
Definition: TerrainBuilder.h:66
uint8 getLiquidType(int square, const uint8 liquid_type[16][16])
Get the liquid type for a specific position.
Definition: TerrainBuilder.cpp:616
static const float INVALID_MAP_LIQ_HEIGHT_MAX
Definition: TerrainBuilder.h:55
static void transform(std::vector< G3D::Vector3 > &original, std::vector< G3D::Vector3 > &transformed, float scale, G3D::Matrix3 &rotation, G3D::Vector3 &position)
Definition: TerrainBuilder.cpp:783
static const int V9_SIZE
Definition: TerrainBuilder.h:46
uint32_t uint32
Definition: Define.h:150
double square(double fValue)
Definition: g3dmath.h:698
uint8 holes[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID][8]
Definition: System.cpp:444
Definition: TerrainBuilder.h:33
Definition: Matrix3.h:37
void getLoopVars(Spot portion, int &loopStart, int &loopEnd, int &loopInc)
Sets loop variables for selecting only certain parts of a map's terrain.
Definition: TerrainBuilder.cpp:89
static void copyVertices(std::vector< G3D::Vector3 > &source, G3D::Array< float > &dest)
Definition: TerrainBuilder.cpp:796
Spot
Definition: TerrainBuilder.h:31
static const float INVALID_MAP_LIQ_HEIGHT
Definition: TerrainBuilder.h:54
G3D::Array< float > solidVerts
Definition: TerrainBuilder.h:63
G3D::Array< float > offMeshConnections
Definition: TerrainBuilder.h:71
void loadOffMeshConnections(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData, const char *offMeshFilePath)
Definition: TerrainBuilder.cpp:881
Definition: TerrainBuilder.h:61
uint8_t uint8
Definition: Define.h:152
Definition: TerrainBuilder.h:36
static const int V8_SIZE_SQ
Definition: TerrainBuilder.h:49
G3D::Array< unsigned char > offMeshConnectionsAreas
Definition: TerrainBuilder.h:74
static const float GRID_PART_SIZE
Definition: TerrainBuilder.h:51
static const float GRID_SIZE
Definition: TerrainBuilder.h:50
static void copyIndices(std::vector< VMAP::MeshTriangle > &source, G3D::Array< int > &dest, int offest, bool flip)
Definition: TerrainBuilder.cpp:807
void getHeightTriangle(int square, Spot triangle, int *indices, bool liquid=false)
Get the triangle's vector indices for a specific position.
Definition: TerrainBuilder.cpp:546