[7272] Trailing whitespace cleaning
[getmangos.git] / src / shared / vmap / SubModel.h
blobeff14033e3fe790b29aaa71a6775711db76cbeac
1 /*
2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef _SUBMODEL_H
20 #define _SUBMODEL_H
22 // load our modified version first !!
23 #include "AABSPTree.h"
25 #include "ShortVector.h"
26 #include "ShortBox.h"
27 #include "TreeNode.h"
28 #include "VMapTools.h"
29 #include "BaseModel.h"
31 namespace VMAP
33 /**
34 This is a balanced static BSP-Tree of triangles.
35 The memory for the tree nodes and the triangles are managed by the ModelContainer.
36 The exception to this is during the conversion of raw data info balanced BSP-Trees.
37 During this conversion the memory management is done internally.
39 class SubModel : public BaseModel
41 private:
42 unsigned int iNodesPos;
43 unsigned int iTrianglesPos;
44 bool iHasInternalMemAlloc;
45 ShortBox iBox;
46 #ifdef _DEBUG_VIEW
47 G3D::Array<TriangleBox *> iDrawBox;
48 #endif
49 public:
50 SubModel() : BaseModel(){ };
52 SubModel(unsigned int pNTriangles, TriangleBox *pTriangles, unsigned int pTrianglesPos, unsigned int pNNodes, TreeNode *pTreeNodes, unsigned int pNodesPos);
53 SubModel(G3D::AABSPTree<G3D::Triangle> *pTree);
54 ~SubModel(void);
55 //Gets a 50 byte binary block
56 void initFromBinBlock(void *pBinBlock);
58 void fillRenderArray(G3D::Array<TriangleBox> &pArray, const TreeNode* pTreeNode);
60 void countNodesAndTriangles(G3D::AABSPTree<G3D::Triangle>::Node& pNode, int &pNNodes, int &pNTriabgles);
62 void fillContainer(const G3D::AABSPTree<G3D::Triangle>::Node& pNode, int &pTreeNodePos, int &pTrianglePos, G3D::Vector3& pLo, G3D::Vector3& pHi);
64 inline const ShortBox& getReletiveBounds() const { return(iBox); }
66 inline void setReletiveBounds(const ShortVector& lo, const ShortVector& hi) { iBox.setLo(lo); iBox.setHi(hi); }
68 inline const G3D::AABox getAABoxBounds() const { return(G3D::AABox(iBox.getLo().getVector3() + getBasePosition(), iBox.getHi().getVector3()+ getBasePosition())); }
70 // get start pos bases on the global array
71 inline TriangleBox const* getTriangles() const { return &BaseModel::getTriangle(iTrianglesPos); }
72 inline TriangleBox * getTriangles() { return &BaseModel::getTriangle(iTrianglesPos); }
74 // get start pos bases on the global array
75 inline TreeNode const* getTreeNodes() const { return &BaseModel::getTreeNode(iNodesPos); }
76 inline TreeNode * getTreeNodes() { return &BaseModel::getTreeNode(iNodesPos); }
78 // internal method usign internal offset
79 inline const TreeNode& getTreeNode(int pPos) const { return(SubModel::getTreeNodes()[pPos]); }
81 // internal method usign internal offset
82 inline const TriangleBox& getTriangle(int pPos) const { return(SubModel::getTriangles()[pPos]); }
84 inline unsigned int getNodesPos() const { return(iNodesPos); }
85 inline unsigned int getTrianglesPos() const { return(iTrianglesPos); }
87 //unsigned int hashCode() { return (getBasePosition() * getNTriangles()).hashCode(); }
89 void intersect(const G3D::Ray& pRay, float& pMaxDist, bool pStopAtFirstHit, G3D::Vector3& pOutLocation, G3D::Vector3& pOutNormal) const;
90 bool intersect(const G3D::Ray& pRay, float& pMaxDist) const;
91 template<typename RayCallback>
92 void intersectRay(const G3D::Ray& ray, RayCallback& intersectCallback, float& distance, bool pStopAtFirstHit, bool intersectCallbackIsFast = false);
93 bool operator==(const SubModel& pSm2) const;
94 unsigned int hashCode() const { return BaseModel::getNTriangles(); }
97 unsigned int hashCode(const SubModel& pSm);
98 void getBounds(const SubModel& pSm, G3D::AABox& pAABox);
99 void getBounds(const SubModel* pSm, G3D::AABox& pAABox);
100 //====================================
101 } // VMAP
102 #endif