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

Revision 102, 3.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#include "BaseModel.h"
22#include "VMapTools.h"
23
24using namespace G3D;
25
26namespace VMAP
27{
28    //==========================================================
29
30    void BaseModel::getMember(Array<TriangleBox>& pMembers)
31    {
32        for(unsigned int i=0; i<iNTriangles; i++)
33        {
34            pMembers.append(iTriangles[i]);
35        }
36    }
37
38    //==========================================================
39    BaseModel::BaseModel(unsigned int pNNodes, unsigned int  pNTriangles)
40    {
41        init(pNNodes, pNTriangles);
42    };
43
44    //==========================================================
45
46    void BaseModel::init(unsigned int pNNodes, unsigned int  pNTriangles)
47    {
48        iNNodes = pNNodes;
49        iNTriangles = pNTriangles;
50        iTriangles = 0;
51        iTreeNodes = 0;
52        if(iNNodes >0) iTreeNodes = new TreeNode[iNNodes];
53        if(iNTriangles >0) iTriangles = new TriangleBox[iNTriangles];
54    }
55
56    //==========================================================
57
58    void BaseModel::free()
59    {
60        if(getTriangles() != 0) delete [] getTriangles(); setNTriangles(0);
61        if(getTreeNodes() != 0) delete [] getTreeNodes(); setNNodes(0);
62    }
63
64    //==========================================================
65
66    void BaseModel::intersect(const G3D::AABox& pBox, const G3D::Ray& pRay, float& pMaxDist, G3D::Vector3& pOutLocation, G3D::Vector3& /*pOutNormal*/) const
67    {
68        bool isInside = false;
69
70        float d = MyCollisionDetection::collisionLocationForMovingPointFixedAABox(
71            pRay.origin, pRay.direction,
72            pBox,
73            pOutLocation, isInside);
74        if (!isInside && ((d > 0) && (d < pMaxDist)))
75        {
76            pMaxDist = d;
77        }
78    }
79
80    //==========================================================
81
82    bool BaseModel::intersect(const G3D::AABox& pBox, const G3D::Ray& pRay, float& pMaxDist) const
83    {
84        // See if the ray will ever hit this node or its children
85        Vector3 location;
86        bool alreadyInsideBounds = false;
87        bool rayWillHitBounds = 
88            MyCollisionDetection::collisionLocationForMovingPointFixedAABox(
89            pRay.origin, pRay.direction, pBox, location, alreadyInsideBounds);
90
91        bool canHitThisNode = (alreadyInsideBounds ||               
92            (rayWillHitBounds && ((location - pRay.origin).squaredLength() < (pMaxDist * pMaxDist))));
93
94        return canHitThisNode;
95    }
96
97}                                                           // VMAP
Note: See TracBrowser for help on using the browser.