2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
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
22 #include <G3D/AABox.h>
23 #include <G3D/Vector3.h>
25 #include "ShortVector.h"
30 A model is based on triangles. To be able to check intersection we need a BSP-Tree.
31 This Class holds the array of triangles as well as the management information for the BSP-Tree.
32 Both are stored in static array and index information is used instead of pointers.
33 Therefore we can load the whole object as a binary block.
35 The vectors are relative to a base position.
44 TriangleBox
*iTriangles
;
46 unsigned int iNTriangles
;
48 G3D::Vector3 iBasePosition
;
50 BaseModel() { iNTriangles
= 0; iNNodes
= 0; iTriangles
= 0; iTreeNodes
= 0;};
51 BaseModel(unsigned int pNNodes
, TreeNode
* pTreeNode
, unsigned int pNTriangles
, TriangleBox
* pTriangleBox
)
53 iNNodes
= pNNodes
; iNTriangles
= pNTriangles
; iTriangles
= pTriangleBox
; iTreeNodes
= pTreeNode
;
55 BaseModel(unsigned int pNNodes
, unsigned int pNTriangles
);
57 // destructor does nothing ! The subclass controles the array memory and knows when to free it
61 void init(unsigned int pNNodes
, unsigned int pNTriangles
);
63 void getMember(G3D::Array
<TriangleBox
>& pMembers
);
65 inline const TriangleBox
& getTriangle(int pPos
) const { return(iTriangles
[pPos
]); }
66 inline TriangleBox
& getTriangle(int pPos
) { return(iTriangles
[pPos
]); }
68 inline void setTriangle(const TriangleBox
& pTriangleBox
, int pPos
) { iTriangles
[pPos
] = pTriangleBox
; }
70 inline const TreeNode
& getTreeNode(int pPos
) const { return(getTreeNodes()[pPos
]); }
71 inline TreeNode
& getTreeNode(int pPos
) { return(getTreeNodes()[pPos
]); }
73 inline void setTreeNode(const TreeNode
& pTreeNode
, int pPos
) { getTreeNodes()[pPos
] = pTreeNode
; }
75 inline void setBasePosition(const G3D::Vector3
& pBasePosition
) { iBasePosition
= pBasePosition
; }
77 inline const G3D::Vector3
& getBasePosition() const { return(iBasePosition
); }
79 inline unsigned int getNNodes() const { return(iNNodes
); }
80 inline unsigned int getNTriangles() const { return(iNTriangles
); }
82 inline void setNNodes(unsigned int pNNodes
) { iNNodes
= pNNodes
; }
83 inline void setNTriangles(unsigned int pNTriangles
) { iNTriangles
= pNTriangles
; }
85 inline void setTriangleArray(TriangleBox
*pGlobalTriangleArray
) { iTriangles
= pGlobalTriangleArray
; }
86 inline void setTreeNodeArray(TreeNode
*pGlobalTreeNodeArray
) { iTreeNodes
= pGlobalTreeNodeArray
; }
88 inline TriangleBox
* getTriangles() const { return(iTriangles
); }
90 inline TreeNode
* getTreeNodes() const{ return(iTreeNodes
); }
92 inline size_t getMemUsage() { return(iNTriangles
* sizeof(TriangleBox
) + iNNodes
* sizeof(TreeNode
) + sizeof(BaseModel
)); }
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;
99 #endif /*BASEMODEL_H_*/