root/trunk/src/shared/vmap/ModelContainer.h @ 13

Revision 2, 4.2 kB (checked in by yumileroy, 17 years ago)

[svn] * Proper SVN structure

Original author: Neo2003
Date: 2008-10-02 16:23:55-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
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.
8 *
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.
13 *
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
17 */
18
19#ifndef _MODELCONTAINER_H
20#define _MODELCONTAINER_H
21
22// load our modified version first !!
23#include "AABSPTree.h"
24
25#include <G3D/AABox.h>
26#include <G3D/Vector3.h>
27#include <G3D/Ray.h>
28
29#include "ShortBox.h"
30#include "TreeNode.h"
31#include "VMapTools.h"
32#include "SubModel.h"
33#include "BaseModel.h"
34
35namespace VMAP
36{
37    /**
38    The ModelContainer is a balanced BSP-Tree of SubModels.
39    We store a map tile or an instance in one ModelContainer.
40    The ModelContainer manages the memory used for the tree nodes, the SubModels and its triangles in static arrays.
41    The tree nodes are used for the BSP-Tree of SubModels as well as for the BSP-Tree of triangles within one SubModel.
42    The references are done by indexes within these static arrays.
43    Therefore we are able to just load a binary block and do not need to mess around with memory allocation and pointers.
44    */
45
46    //=====================================================
47
48    class ModelContainer : public BaseModel
49    {
50        private:
51            unsigned int iNSubModel;
52            SubModel *iSubModel;
53            G3D::AABox iBox;
54
55            ModelContainer (const ModelContainer& c): BaseModel(c) {}
56            ModelContainer& operator=(const ModelContainer& ) {}
57
58        public:
59            ModelContainer() : BaseModel() { iNSubModel =0; iSubModel = 0; };
60
61            // for the mainnode
62            ModelContainer(unsigned int pNTriangles, unsigned int pNNodes, unsigned int pNSubModel);
63
64            ModelContainer(G3D::AABSPTree<SubModel *> *pTree);
65
66            ~ModelContainer(void);
67
68            inline const void setSubModel(const SubModel& pSubModel, int pPos) { iSubModel[pPos] = pSubModel; }
69
70            inline const SubModel& getSubModel(int pPos) const { return iSubModel[pPos]; }
71
72            inline unsigned int getNSubModel() const { return(iNSubModel); }
73
74            void countSubModelsAndNodesAndTriangles(G3D::AABSPTree<SubModel *>::Node& pNode, int& nSubModels, int& nNodes, int& nTriangles);
75
76            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);
77
78            bool readRawFile(const char *name);
79
80            inline const G3D::AABox& getAABoxBounds() const { return(iBox); }
81
82            inline void setBounds(const G3D::Vector3& lo, const G3D::Vector3& hi) { iBox.set(lo,hi); }
83
84            bool writeFile(const char *filename);
85
86            bool readFile(const char *filename);
87
88            size_t getMemUsage();
89            size_t 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
94            template<typename RayCallback>
95            void intersectRay(const G3D::Ray& ray, RayCallback& intersectCallback, float& distance, bool pStopAtFirstHit, bool intersectCallbackIsFast = false);
96
97            bool operator==(const ModelContainer& pMc2) const;
98    };
99
100    //=====================================================
101
102    //=====================================================
103
104    size_t hashCode(const ModelContainer& pMc);
105    void getBounds(const ModelContainer& pMc, G3D::AABox& pAABox);
106    void getBounds(const ModelContainer* pMc, G3D::AABox& pAABox);
107}
108#endif
Note: See TracBrowser for help on using the browser.