1 | /* |
---|
2 | * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> |
---|
3 | * |
---|
4 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
---|
5 | * |
---|
6 | * This program is free software; you can redistribute it and/or modify |
---|
7 | * it under the terms of the GNU General Public License as published by |
---|
8 | * the Free Software Foundation; either version 2 of the License, or |
---|
9 | * (at your option) any later version. |
---|
10 | * |
---|
11 | * This program is distributed in the hope that it will be useful, |
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | * GNU General Public License for more details. |
---|
15 | * |
---|
16 | * You should have received a copy of the GNU General Public License |
---|
17 | * along with this program; if not, write to the Free Software |
---|
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
19 | */ |
---|
20 | |
---|
21 | #ifndef _MODELCONTAINER_H |
---|
22 | #define _MODELCONTAINER_H |
---|
23 | |
---|
24 | // load our modified version first !! |
---|
25 | #include "AABSPTree.h" |
---|
26 | |
---|
27 | #include <G3D/AABox.h> |
---|
28 | #include <G3D/Vector3.h> |
---|
29 | #include <G3D/Ray.h> |
---|
30 | |
---|
31 | #include "ShortBox.h" |
---|
32 | #include "TreeNode.h" |
---|
33 | #include "VMapTools.h" |
---|
34 | #include "SubModel.h" |
---|
35 | #include "BaseModel.h" |
---|
36 | |
---|
37 | namespace VMAP |
---|
38 | { |
---|
39 | /** |
---|
40 | The ModelContainer is a balanced BSP-Tree of SubModels. |
---|
41 | We store a map tile or an instance in one ModelContainer. |
---|
42 | The ModelContainer manages the memory used for the tree nodes, the SubModels and its triangles in static arrays. |
---|
43 | The tree nodes are used for the BSP-Tree of SubModels as well as for the BSP-Tree of triangles within one SubModel. |
---|
44 | The references are done by indexes within these static arrays. |
---|
45 | Therefore we are able to just load a binary block and do not need to mess around with memory allocation and pointers. |
---|
46 | */ |
---|
47 | |
---|
48 | //===================================================== |
---|
49 | |
---|
50 | class ModelContainer : public BaseModel |
---|
51 | { |
---|
52 | private: |
---|
53 | unsigned int iNSubModel; |
---|
54 | SubModel *iSubModel; |
---|
55 | G3D::AABox iBox; |
---|
56 | |
---|
57 | ModelContainer (const ModelContainer& c): BaseModel(c) {} |
---|
58 | ModelContainer& operator=(const ModelContainer& ) {} |
---|
59 | |
---|
60 | public: |
---|
61 | ModelContainer() : BaseModel() { iNSubModel =0; iSubModel = 0; }; |
---|
62 | |
---|
63 | // for the mainnode |
---|
64 | ModelContainer(unsigned int pNTriangles, unsigned int pNNodes, unsigned int pNSubModel); |
---|
65 | |
---|
66 | ModelContainer(G3D::AABSPTree<SubModel *> *pTree); |
---|
67 | |
---|
68 | ~ModelContainer(void); |
---|
69 | |
---|
70 | inline const void setSubModel(const SubModel& pSubModel, int pPos) { iSubModel[pPos] = pSubModel; } |
---|
71 | |
---|
72 | inline const SubModel& getSubModel(int pPos) const { return iSubModel[pPos]; } |
---|
73 | |
---|
74 | inline unsigned int getNSubModel() const { return(iNSubModel); } |
---|
75 | |
---|
76 | void countSubModelsAndNodesAndTriangles(G3D::AABSPTree<SubModel *>::Node& pNode, int& nSubModels, int& nNodes, int& nTriangles); |
---|
77 | |
---|
78 | void fillContainer(const G3D::AABSPTree<SubModel *>::Node& pNode, int &pSubModelPos, int &pTreeNodePos, int &pTrianglePos, G3D::Vector3& pLo, G3D::Vector3& pHi, G3D::Vector3& pFinalLo, G3D::Vector3& pFinalHi); |
---|
79 | |
---|
80 | bool readRawFile(const char *name); |
---|
81 | |
---|
82 | inline const G3D::AABox& getAABoxBounds() const { return(iBox); } |
---|
83 | |
---|
84 | inline void setBounds(const G3D::Vector3& lo, const G3D::Vector3& hi) { iBox.set(lo,hi); } |
---|
85 | |
---|
86 | bool writeFile(const char *filename); |
---|
87 | |
---|
88 | bool readFile(const char *filename); |
---|
89 | |
---|
90 | size_t getMemUsage(); |
---|
91 | size_t hashCode() { return (getBasePosition() * getNTriangles()).hashCode(); } |
---|
92 | |
---|
93 | void intersect(const G3D::Ray& pRay, float& pMaxDist, bool pStopAtFirstHit, G3D::Vector3& pOutLocation, G3D::Vector3& pOutNormal) const; |
---|
94 | bool intersect(const G3D::Ray& pRay, float& pMaxDist) const; |
---|
95 | |
---|
96 | template<typename RayCallback> |
---|
97 | void intersectRay(const G3D::Ray& ray, RayCallback& intersectCallback, float& distance, bool pStopAtFirstHit, bool intersectCallbackIsFast = false); |
---|
98 | |
---|
99 | bool operator==(const ModelContainer& pMc2) const; |
---|
100 | }; |
---|
101 | |
---|
102 | //===================================================== |
---|
103 | |
---|
104 | //===================================================== |
---|
105 | |
---|
106 | size_t hashCode(const ModelContainer& pMc); |
---|
107 | void getBounds(const ModelContainer& pMc, G3D::AABox& pAABox); |
---|
108 | void getBounds(const ModelContainer* pMc, G3D::AABox& pAABox); |
---|
109 | } |
---|
110 | #endif |
---|