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
19 #include "BaseModel.h"
20 #include "VMapTools.h"
26 //==========================================================
28 void BaseModel::getMember(Array
<TriangleBox
>& pMembers
)
30 for(unsigned int i
=0; i
<iNTriangles
; i
++)
32 pMembers
.append(iTriangles
[i
]);
36 //==========================================================
37 BaseModel::BaseModel(unsigned int pNNodes
, unsigned int pNTriangles
)
39 init(pNNodes
, pNTriangles
);
42 //==========================================================
44 void BaseModel::init(unsigned int pNNodes
, unsigned int pNTriangles
)
47 iNTriangles
= pNTriangles
;
50 if(iNNodes
>0) iTreeNodes
= new TreeNode
[iNNodes
];
51 if(iNTriangles
>0) iTriangles
= new TriangleBox
[iNTriangles
];
54 //==========================================================
56 void BaseModel::free()
58 if(getTriangles() != 0) delete [] getTriangles(); setNTriangles(0);
59 if(getTreeNodes() != 0) delete [] getTreeNodes(); setNNodes(0);
62 //==========================================================
64 void BaseModel::intersect(const G3D::AABox
& pBox
, const G3D::Ray
& pRay
, float& pMaxDist
, G3D::Vector3
& pOutLocation
, G3D::Vector3
& /*pOutNormal*/) const
66 bool isInside
= false;
68 float d
= MyCollisionDetection::collisionLocationForMovingPointFixedAABox(
69 pRay
.origin
, pRay
.direction
,
71 pOutLocation
, isInside
);
72 if (!isInside
&& ((d
> 0) && (d
< pMaxDist
)))
78 //==========================================================
80 bool BaseModel::intersect(const G3D::AABox
& pBox
, const G3D::Ray
& pRay
, float& pMaxDist
) const
82 // See if the ray will ever hit this node or its children
84 bool alreadyInsideBounds
= false;
85 bool rayWillHitBounds
=
86 MyCollisionDetection::collisionLocationForMovingPointFixedAABox(
87 pRay
.origin
, pRay
.direction
, pBox
, location
, alreadyInsideBounds
);
89 bool canHitThisNode
= (alreadyInsideBounds
||
90 (rayWillHitBounds
&& ((location
- pRay
.origin
).squaredLength() < (pMaxDist
* pMaxDist
))));
92 return canHitThisNode
;