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 _SUBMODEL_H |
---|
22 | #define _SUBMODEL_H |
---|
23 | |
---|
24 | // load our modified version first !! |
---|
25 | #include "AABSPTree.h" |
---|
26 | |
---|
27 | #include "ShortVector.h" |
---|
28 | #include "ShortBox.h" |
---|
29 | #include "TreeNode.h" |
---|
30 | #include "VMapTools.h" |
---|
31 | #include "BaseModel.h" |
---|
32 | |
---|
33 | namespace VMAP |
---|
34 | { |
---|
35 | /** |
---|
36 | This is a balanced static BSP-Tree of triangles. |
---|
37 | The memory for the tree nodes and the triangles are managed by the ModelContainer. |
---|
38 | The exception to this is during the conversion of raw data info balanced BSP-Trees. |
---|
39 | During this conversion the memory management is done internally. |
---|
40 | */ |
---|
41 | class SubModel : public BaseModel |
---|
42 | { |
---|
43 | private: |
---|
44 | unsigned int iNodesPos; |
---|
45 | unsigned int iTrianglesPos; |
---|
46 | bool iHasInternalMemAlloc; |
---|
47 | ShortBox iBox; |
---|
48 | #ifdef _DEBUG_VIEW |
---|
49 | G3D::Array<TriangleBox *> iDrawBox; |
---|
50 | #endif |
---|
51 | public: |
---|
52 | SubModel() : BaseModel(){ }; |
---|
53 | |
---|
54 | SubModel(unsigned int pNTriangles, TriangleBox *pTriangles, unsigned int pTrianglesPos, unsigned int pNNodes, TreeNode *pTreeNodes, unsigned int pNodesPos); |
---|
55 | SubModel(G3D::AABSPTree<G3D::Triangle> *pTree); |
---|
56 | ~SubModel(void); |
---|
57 | //Gets a 50 byte binary block |
---|
58 | void initFromBinBlock(void *pBinBlock); |
---|
59 | |
---|
60 | void fillRenderArray(G3D::Array<TriangleBox> &pArray, const TreeNode* pTreeNode); |
---|
61 | |
---|
62 | void countNodesAndTriangles(G3D::AABSPTree<G3D::Triangle>::Node& pNode, int &pNNodes, int &pNTriabgles); |
---|
63 | |
---|
64 | void fillContainer(const G3D::AABSPTree<G3D::Triangle>::Node& pNode, int &pTreeNodePos, int &pTrianglePos, G3D::Vector3& pLo, G3D::Vector3& pHi); |
---|
65 | |
---|
66 | inline const ShortBox& getReletiveBounds() const { return(iBox); } |
---|
67 | |
---|
68 | inline void setReletiveBounds(const ShortVector& lo, const ShortVector& hi) { iBox.setLo(lo); iBox.setHi(hi); } |
---|
69 | |
---|
70 | inline const G3D::AABox getAABoxBounds() const { return(G3D::AABox(iBox.getLo().getVector3() + getBasePosition(), iBox.getHi().getVector3()+ getBasePosition())); } |
---|
71 | |
---|
72 | // get start pos bases on the global array |
---|
73 | inline TriangleBox const* getTriangles() const { return &BaseModel::getTriangle(iTrianglesPos); } |
---|
74 | inline TriangleBox * getTriangles() { return &BaseModel::getTriangle(iTrianglesPos); } |
---|
75 | |
---|
76 | // get start pos bases on the global array |
---|
77 | inline TreeNode const* getTreeNodes() const { return &BaseModel::getTreeNode(iNodesPos); } |
---|
78 | inline TreeNode * getTreeNodes() { return &BaseModel::getTreeNode(iNodesPos); } |
---|
79 | |
---|
80 | // internal method usign internal offset |
---|
81 | inline const TreeNode& getTreeNode(int pPos) const { return(SubModel::getTreeNodes()[pPos]); } |
---|
82 | |
---|
83 | // internal method usign internal offset |
---|
84 | inline const TriangleBox& getTriangle(int pPos) const { return(SubModel::getTriangles()[pPos]); } |
---|
85 | |
---|
86 | inline unsigned int getNodesPos() const { return(iNodesPos); } |
---|
87 | inline unsigned int getTrianglesPos() const { return(iTrianglesPos); } |
---|
88 | |
---|
89 | //unsigned int hashCode() { return (getBasePosition() * getNTriangles()).hashCode(); } |
---|
90 | |
---|
91 | void intersect(const G3D::Ray& pRay, float& pMaxDist, bool pStopAtFirstHit, G3D::Vector3& pOutLocation, G3D::Vector3& pOutNormal) const; |
---|
92 | bool intersect(const G3D::Ray& pRay, float& pMaxDist) const; |
---|
93 | template<typename RayCallback> |
---|
94 | void intersectRay(const G3D::Ray& ray, RayCallback& intersectCallback, float& distance, bool pStopAtFirstHit, bool intersectCallbackIsFast = false); |
---|
95 | bool operator==(const SubModel& pSm2) const; |
---|
96 | unsigned int hashCode() const { return BaseModel::getNTriangles(); } |
---|
97 | }; |
---|
98 | |
---|
99 | unsigned int hashCode(const SubModel& pSm); |
---|
100 | void getBounds(const SubModel& pSm, G3D::AABox& pAABox); |
---|
101 | void getBounds(const SubModel* pSm, G3D::AABox& pAABox); |
---|
102 | //==================================== |
---|
103 | } // VMAP |
---|
104 | #endif |
---|