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

Revision 102, 4.3 kB (checked in by yumileroy, 17 years ago)

[svn] Fixed copyright notices to comply with GPL.

Original author: w12x
Date: 2008-10-23 03:29:52-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
4 * Copyright (C) 2008 Trinity <http://www.trinitycore.org/>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#ifndef _BASEMODEL_H_
22#define _BASEMODEL_H_
23
24#include <G3D/AABox.h>
25#include <G3D/Vector3.h>
26
27#include "ShortVector.h"
28#include "ShortBox.h"
29#include "TreeNode.h"
30
31/**
32A model is based on triangles. To be able to check intersection we need a BSP-Tree.
33This Class holds the array of triangles as well as the management information for the BSP-Tree.
34Both are stored in static array and index information is used instead of pointers.
35Therefore we can load the whole object as a binary block.
36
37The vectors are relative to a base position.
38*/
39
40namespace VMAP
41{
42
43    class BaseModel
44    {
45        protected:
46            TriangleBox *iTriangles;
47            TreeNode *iTreeNodes;
48            unsigned int iNTriangles;
49            unsigned int iNNodes;
50            G3D::Vector3 iBasePosition;
51        public:
52            BaseModel() { iNTriangles = 0; iNNodes = 0; iTriangles = 0; iTreeNodes = 0;};
53            BaseModel(unsigned int pNNodes  , TreeNode* pTreeNode, unsigned int  pNTriangles, TriangleBox* pTriangleBox)
54            {
55                iNNodes = pNNodes; iNTriangles = pNTriangles; iTriangles = pTriangleBox; iTreeNodes = pTreeNode;
56            };
57            BaseModel(unsigned int pNNodes, unsigned int  pNTriangles);
58
59            // destructor does nothing ! The subclass controles the array memory and knows when to free it
60            ~BaseModel() {}
61
62            void free();
63            void init(unsigned int pNNodes, unsigned int  pNTriangles);
64
65            void getMember(G3D::Array<TriangleBox>& pMembers);
66
67            inline const TriangleBox& getTriangle(int pPos) const { return(iTriangles[pPos]); }
68            inline       TriangleBox& getTriangle(int pPos)       { return(iTriangles[pPos]); }
69
70            inline void setTriangle(const TriangleBox& pTriangleBox, int pPos) { iTriangles[pPos] = pTriangleBox; }
71
72            inline const TreeNode& getTreeNode(int pPos) const { return(getTreeNodes()[pPos]); }
73            inline       TreeNode& getTreeNode(int pPos)       { return(getTreeNodes()[pPos]); }
74
75            inline void setTreeNode(const TreeNode& pTreeNode, int pPos) { getTreeNodes()[pPos] = pTreeNode; }
76
77            inline void setBasePosition(const G3D::Vector3& pBasePosition) { iBasePosition = pBasePosition; }
78
79            inline const G3D::Vector3& getBasePosition() const { return(iBasePosition); }
80
81            inline unsigned int getNNodes() const { return(iNNodes); }
82            inline unsigned int getNTriangles() const { return(iNTriangles); }
83
84            inline void setNNodes(unsigned int pNNodes)  { iNNodes = pNNodes; }
85            inline void setNTriangles(unsigned int  pNTriangles)  { iNTriangles = pNTriangles; }
86
87            inline void setTriangleArray(TriangleBox *pGlobalTriangleArray ) { iTriangles = pGlobalTriangleArray ; }
88            inline void setTreeNodeArray(TreeNode *pGlobalTreeNodeArray ) { iTreeNodes = pGlobalTreeNodeArray ; }
89
90            inline TriangleBox* getTriangles() const { return(iTriangles); }
91
92            inline TreeNode* getTreeNodes() const{ return(iTreeNodes); }
93
94            inline size_t getMemUsage() { return(iNTriangles * sizeof(TriangleBox) + iNNodes * sizeof(TreeNode) + sizeof(BaseModel)); }
95
96            void intersect(const G3D::AABox& pBox, const G3D::Ray& pRay, float& pMaxDist, G3D::Vector3& pOutLocation, G3D::Vector3& pOutNormal) const;
97            bool intersect(const G3D::AABox& pBox, const G3D::Ray& pRay, float& pMaxDist) const;
98    };
99
100}
101#endif                                                      /*BASEMODEL_H_*/
Note: See TracBrowser for help on using the browser.