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

Revision 2, 4.7 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 _SUBMODEL_H
20#define _SUBMODEL_H
21
22// load our modified version first !!
23#include "AABSPTree.h"
24
25#include "ShortVector.h"
26#include "ShortBox.h"
27#include "TreeNode.h"
28#include "VMapTools.h"
29#include "BaseModel.h"
30
31namespace VMAP
32{
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.
38    */
39    class SubModel : public BaseModel
40    {
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(){ };
51
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);
57
58            void fillRenderArray(G3D::Array<TriangleBox> &pArray, const TreeNode* pTreeNode);
59
60            void countNodesAndTriangles(G3D::AABSPTree<G3D::Triangle>::Node& pNode, int &pNNodes, int &pNTriabgles);
61
62            void fillContainer(const G3D::AABSPTree<G3D::Triangle>::Node& pNode, int &pTreeNodePos, int &pTrianglePos, G3D::Vector3& pLo, G3D::Vector3& pHi);
63
64            inline const ShortBox& getReletiveBounds() const { return(iBox); }
65
66            inline void setReletiveBounds(const ShortVector& lo, const ShortVector& hi) { iBox.setLo(lo); iBox.setHi(hi); }
67
68            inline const G3D::AABox getAABoxBounds() const { return(G3D::AABox(iBox.getLo().getVector3() + getBasePosition(), iBox.getHi().getVector3()+ getBasePosition())); }
69
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); }
73
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); }
77
78            // internal method usign internal offset
79            inline const TreeNode& getTreeNode(int pPos) const { return(SubModel::getTreeNodes()[pPos]); }
80
81            // internal method usign internal offset
82            inline const TriangleBox& getTriangle(int pPos) const { return(SubModel::getTriangles()[pPos]); }
83
84            inline unsigned int getNodesPos() const { return(iNodesPos); }
85            inline unsigned int getTrianglesPos() const { return(iTrianglesPos); }
86
87            //unsigned int hashCode() { return (getBasePosition() * getNTriangles()).hashCode(); }
88
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(); }
95    };
96
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
Note: See TracBrowser for help on using the browser.