root/trunk/src/shared/vmap/BaseModel.h @ 8

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 _BASEMODEL_H_
20#define _BASEMODEL_H_
21
22#include <G3D/AABox.h>
23#include <G3D/Vector3.h>
24
25#include "ShortVector.h"
26#include "ShortBox.h"
27#include "TreeNode.h"
28
29/**
30A model is based on triangles. To be able to check intersection we need a BSP-Tree.
31This Class holds the array of triangles as well as the management information for the BSP-Tree.
32Both are stored in static array and index information is used instead of pointers.
33Therefore we can load the whole object as a binary block.
34
35The vectors are relative to a base position.
36*/
37
38namespace VMAP
39{
40
41    class BaseModel
42    {
43        protected:
44            TriangleBox *iTriangles;
45            TreeNode *iTreeNodes;
46            unsigned int iNTriangles;
47            unsigned int iNNodes;
48            G3D::Vector3 iBasePosition;
49        public:
50            BaseModel() { iNTriangles = 0; iNNodes = 0; iTriangles = 0; iTreeNodes = 0;};
51            BaseModel(unsigned int pNNodes  , TreeNode* pTreeNode, unsigned int  pNTriangles, TriangleBox* pTriangleBox)
52            {
53                iNNodes = pNNodes; iNTriangles = pNTriangles; iTriangles = pTriangleBox; iTreeNodes = pTreeNode;
54            };
55            BaseModel(unsigned int pNNodes, unsigned int  pNTriangles);
56
57            // destructor does nothing ! The subclass controles the array memory and knows when to free it
58            ~BaseModel() {}
59
60            void free();
61            void init(unsigned int pNNodes, unsigned int  pNTriangles);
62
63            void getMember(G3D::Array<TriangleBox>& pMembers);
64
65            inline const TriangleBox& getTriangle(int pPos) const { return(iTriangles[pPos]); }
66            inline       TriangleBox& getTriangle(int pPos)       { return(iTriangles[pPos]); }
67
68            inline void setTriangle(const TriangleBox& pTriangleBox, int pPos) { iTriangles[pPos] = pTriangleBox; }
69
70            inline const TreeNode& getTreeNode(int pPos) const { return(getTreeNodes()[pPos]); }
71            inline       TreeNode& getTreeNode(int pPos)       { return(getTreeNodes()[pPos]); }
72
73            inline void setTreeNode(const TreeNode& pTreeNode, int pPos) { getTreeNodes()[pPos] = pTreeNode; }
74
75            inline void setBasePosition(const G3D::Vector3& pBasePosition) { iBasePosition = pBasePosition; }
76
77            inline const G3D::Vector3& getBasePosition() const { return(iBasePosition); }
78
79            inline unsigned int getNNodes() const { return(iNNodes); }
80            inline unsigned int getNTriangles() const { return(iNTriangles); }
81
82            inline void setNNodes(unsigned int pNNodes)  { iNNodes = pNNodes; }
83            inline void setNTriangles(unsigned int  pNTriangles)  { iNTriangles = pNTriangles; }
84
85            inline void setTriangleArray(TriangleBox *pGlobalTriangleArray ) { iTriangles = pGlobalTriangleArray ; }
86            inline void setTreeNodeArray(TreeNode *pGlobalTreeNodeArray ) { iTreeNodes = pGlobalTreeNodeArray ; }
87
88            inline TriangleBox* getTriangles() const { return(iTriangles); }
89
90            inline TreeNode* getTreeNodes() const{ return(iTreeNodes); }
91
92            inline size_t getMemUsage() { return(iNTriangles * sizeof(TriangleBox) + iNNodes * sizeof(TreeNode) + sizeof(BaseModel)); }
93
94            void intersect(const G3D::AABox& pBox, const G3D::Ray& pRay, float& pMaxDist, G3D::Vector3& pOutLocation, G3D::Vector3& pOutNormal) const;
95            bool intersect(const G3D::AABox& pBox, const G3D::Ray& pRay, float& pMaxDist) const;
96    };
97
98}
99#endif                                                      /*BASEMODEL_H_*/
Note: See TracBrowser for help on using the browser.