[4054] added: Line of sight (vmaps) [part 1]
[mangos-git.git] / src / game / ModelContainer.h
blob5efb6720aeed8259c2f08514bf191d6fa21ae331
1 /*
2 * Copyright (C) 2005,2006,2007 MaNGOS <http://www.mangosproject.org/>
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 _MODELCONTAINER_H
20 #define _MODELCONTAINER_H
23 // load our modified version first !!
24 #include <G3D/AABSPTree.h>
26 #include <G3D/AABox.h>
27 #include <G3D/Vector3.h>
28 #include <G3D/Ray.h>
30 #include "ShortBox.h"
31 #include "TreeNode.h"
32 #include "RayIntersectionIterator.h"
33 #include "SubModel.h"
34 #include "BaseModel.h"
37 namespace VMAP
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.
49 //=====================================================
51 class ModelContainer : public BaseModel
53 private:
54 unsigned int iNSubModel;
55 SubModel *iSubModel;
56 //Vector3 iDirection;
57 AABox iBox;
59 public:
60 ModelContainer() : BaseModel() { iNSubModel =0; iSubModel = 0; };
62 // for the mainnode
63 ModelContainer(unsigned int pNTriangles, unsigned int pNNodes, unsigned int pNSubModel);
65 ModelContainer(AABSPTree<SubModel *> *pTree);
67 ~ModelContainer(void);
69 RayIntersectionIterator<TreeNode, SubModel> beginRayIntersection(const Ray& ray, double pMaxTime, bool skipAABoxTests = false) const;
71 RayIntersectionIterator<TreeNode, SubModel> endRayIntersection() const;
73 inline const void setSubModel(const SubModel& pSubModel, int pPos) { iSubModel[pPos] = pSubModel; }
75 inline const SubModel& getSubModel(int pPos) const { return iSubModel[pPos]; }
77 inline unsigned int getNSubModel() const { return(iNSubModel); }
79 RealTime getIntersectionTime(const Ray&, bool pExitAtFirst, float pMaxDist);
81 void countSubModelsAndNodesAndTriangles(AABSPTree<SubModel *>::Node& pNode, int& nSubModels, int& nNodes, int& nTriangles);
83 void fillContainer(const AABSPTree<SubModel *>::Node& pNode, int &pSubModelPos, int &pTreeNodePos, int &pTrianglePos, Vector3& pLo, Vector3& pHi, Vector3& pFinalLo, Vector3& pFinalHi);
85 bool readRawFile(const char *name);
87 inline const AABox& getAABoxBounds() const { return(iBox); }
89 inline void setBounds(const Vector3& lo, const Vector3& hi) { iBox.set(lo,hi); }
91 bool writeFile(const char *filename);
93 bool readFile(const char *filename);
95 size_t getMemUsage();
98 //=====================================================
100 //=====================================================
102 unsigned int hashCode(const ModelContainer& pMc);
103 bool operator==(const ModelContainer& pMc1, const ModelContainer& pMc2);
104 void getBounds(const ModelContainer& pMc, G3D::AABox& pAABox);
105 void getBounds(const ModelContainer* pMc, G3D::AABox& pAABox);
108 #endif