TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
WorldModel.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
3  * Copyright (C) 2005-2010 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 _WORLDMODEL_H
20 #define _WORLDMODEL_H
21 
22 #include <G3D/HashTrait.h>
23 #include <G3D/Vector3.h>
24 #include <G3D/AABox.h>
25 #include <G3D/Ray.h>
27 
28 #include "Define.h"
29 
30 namespace VMAP
31 {
32  class TreeNode;
33  struct AreaInfo;
34  struct LocationInfo;
35 
37  {
38  public:
39  MeshTriangle() : idx0(0), idx1(0), idx2(0) { }
40  MeshTriangle(uint32 na, uint32 nb, uint32 nc): idx0(na), idx1(nb), idx2(nc) { }
41 
45  };
46 
48  {
49  public:
50  WmoLiquid(uint32 width, uint32 height, const G3D::Vector3 &corner, uint32 type);
51  WmoLiquid(const WmoLiquid &other);
52  ~WmoLiquid();
53  WmoLiquid& operator=(const WmoLiquid &other);
54  bool GetLiquidHeight(const G3D::Vector3 &pos, float &liqHeight) const;
55  uint32 GetType() const { return iType; }
56  float *GetHeightStorage() { return iHeight; }
57  uint8 *GetFlagsStorage() { return iFlags; }
58  uint32 GetFileSize();
59  bool writeToFile(FILE* wf);
60  static bool readFromFile(FILE* rf, WmoLiquid* &liquid);
61  void getPosInfo(uint32 &tilesX, uint32 &tilesY, G3D::Vector3 &corner) const;
62  private:
63  WmoLiquid() : iTilesX(0), iTilesY(0), iCorner(), iType(0), iHeight(NULL), iFlags(NULL) { }
68  float *iHeight;
70  };
71 
74  {
75  public:
76  GroupModel() : iBound(), iMogpFlags(0), iGroupWMOID(0), iLiquid(NULL) { }
77  GroupModel(const GroupModel &other);
78  GroupModel(uint32 mogpFlags, uint32 groupWMOID, const G3D::AABox &bound):
79  iBound(bound), iMogpFlags(mogpFlags), iGroupWMOID(groupWMOID), iLiquid(NULL) { }
80  ~GroupModel() { delete iLiquid; }
81 
83  void setMeshData(std::vector<G3D::Vector3> &vert, std::vector<MeshTriangle> &tri);
84  void setLiquidData(WmoLiquid*& liquid) { iLiquid = liquid; liquid = NULL; }
85  bool IntersectRay(const G3D::Ray &ray, float &distance, bool stopAtFirstHit) const;
86  bool IsInsideObject(const G3D::Vector3 &pos, const G3D::Vector3 &down, float &z_dist) const;
87  bool GetLiquidLevel(const G3D::Vector3 &pos, float &liqHeight) const;
88  uint32 GetLiquidType() const;
89  bool writeToFile(FILE* wf);
90  bool readFromFile(FILE* rf);
91  const G3D::AABox& GetBound() const { return iBound; }
92  uint32 GetMogpFlags() const { return iMogpFlags; }
93  uint32 GetWmoID() const { return iGroupWMOID; }
94  void getMeshData(std::vector<G3D::Vector3>& outVertices, std::vector<MeshTriangle>& outTriangles, WmoLiquid*& liquid);
95  protected:
97  uint32 iMogpFlags;// 0x8 outdor; 0x2000 indoor
99  std::vector<G3D::Vector3> vertices;
100  std::vector<MeshTriangle> triangles;
103  };
104 
107  {
108  public:
109  WorldModel(): RootWMOID(0) { }
110 
112  void setGroupModels(std::vector<GroupModel> &models);
113  void setRootWmoID(uint32 id) { RootWMOID = id; }
114  bool IntersectRay(const G3D::Ray &ray, float &distance, bool stopAtFirstHit) const;
115  bool IntersectPoint(const G3D::Vector3 &p, const G3D::Vector3 &down, float &dist, AreaInfo &info) const;
116  bool GetLocationInfo(const G3D::Vector3 &p, const G3D::Vector3 &down, float &dist, LocationInfo &info) const;
117  bool writeFile(const std::string &filename);
118  bool readFile(const std::string &filename);
119  void getGroupModels(std::vector<GroupModel>& outGroupModels);
120  protected:
122  std::vector<GroupModel> groupModels;
124  };
125 } // namespace VMAP
126 
127 #endif // _WORLDMODEL_H
Definition: MapTree.h:32
Definition: WorldModel.h:73
uint32 GetMogpFlags() const
Definition: WorldModel.h:92
float * iHeight
(tilesX + 1)*(tilesY + 1) height values
Definition: WorldModel.h:68
WorldModel()
Definition: WorldModel.h:109
arena_t NULL
Definition: jemalloc_internal.h:624
uint32 idx2
Definition: WorldModel.h:44
uint8 * iFlags
info if liquid tile is used
Definition: WorldModel.h:69
float * GetHeightStorage()
Definition: WorldModel.h:56
uint32 idx0
Definition: WorldModel.h:42
Definition: IVMapManager.h:31
double distance(double x, double y)
Definition: g3dmath.h:731
~GroupModel()
Definition: WorldModel.h:80
Definition: Vector3.h:58
std::vector< MeshTriangle > triangles
Definition: WorldModel.h:100
uint32 RootWMOID
Definition: WorldModel.h:121
std::vector< GroupModel > groupModels
Definition: WorldModel.h:122
MeshTriangle()
Definition: WorldModel.h:39
MeshTriangle(uint32 na, uint32 nb, uint32 nc)
Definition: WorldModel.h:40
Definition: WorldModel.h:36
void setRootWmoID(uint32 id)
Definition: WorldModel.h:113
Definition: MapTree.h:90
G3D::Vector3 iCorner
the lower corner
Definition: WorldModel.h:66
WmoLiquid()
Definition: WorldModel.h:63
BIH groupTree
Definition: WorldModel.h:123
Definition: WorldModel.h:106
uint32 iTilesX
number of tiles in x direction, each
Definition: WorldModel.h:64
uint32 idx1
Definition: WorldModel.h:43
Vector2int16 & operator=(const Any &a)
uint32_t uint32
Definition: Define.h:150
Definition: Ray.h:24
Definition: AABox.h:32
#define TC_COMMON_API
Definition: Define.h:116
GroupModel()
Definition: WorldModel.h:76
uint32 GetWmoID() const
Definition: WorldModel.h:93
uint8 * GetFlagsStorage()
Definition: WorldModel.h:57
BIH meshTree
Definition: WorldModel.h:101
Definition: WorldModel.h:47
G3D::AABox iBound
Definition: WorldModel.h:96
const G3D::AABox & GetBound() const
Definition: WorldModel.h:91
void setLiquidData(WmoLiquid *&liquid)
Definition: WorldModel.h:84
uint32 iMogpFlags
Definition: WorldModel.h:97
GroupModel(uint32 mogpFlags, uint32 groupWMOID, const G3D::AABox &bound)
Definition: WorldModel.h:78
uint32 iType
liquid type
Definition: WorldModel.h:67
uint8_t uint8
Definition: Define.h:152
std::vector< G3D::Vector3 > vertices
Definition: WorldModel.h:99
WmoLiquid * iLiquid
Definition: WorldModel.h:102
uint32 iTilesY
Definition: WorldModel.h:65
uint32 GetType() const
Definition: WorldModel.h:55
uint32 iGroupWMOID
Definition: WorldModel.h:98
Definition: BoundingIntervalHierarchy.h:70