[7272] Trailing whitespace cleaning
[getmangos.git] / src / shared / vmap / BaseModel.cpp
blob4a131c46ad3a43ed6aca4d040b3b232277b45403
1 /*
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"
22 using namespace G3D;
24 namespace VMAP
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)
46 iNNodes = pNNodes;
47 iNTriangles = pNTriangles;
48 iTriangles = 0;
49 iTreeNodes = 0;
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,
70 pBox,
71 pOutLocation, isInside);
72 if (!isInside && ((d > 0) && (d < pMaxDist)))
74 pMaxDist = d;
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
83 Vector3 location;
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;
95 } // VMAP