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

Revision 2, 3.2 kB (checked in by yumileroy, 17 years ago)

[svn] * Proper SVN structure

Original author: Neo2003
Date: 2008-10-02 16:23:55-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
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.
8 *
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.
13 *
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
17 */
18
19#include "BaseModel.h"
20#include "VMapTools.h"
21
22using namespace G3D;
23
24namespace VMAP
25{
26    //==========================================================
27
28    void BaseModel::getMember(Array<TriangleBox>& pMembers)
29    {
30        for(unsigned int i=0; i<iNTriangles; i++)
31        {
32            pMembers.append(iTriangles[i]);
33        }
34    }
35
36    //==========================================================
37    BaseModel::BaseModel(unsigned int pNNodes, unsigned int  pNTriangles)
38    {
39        init(pNNodes, pNTriangles);
40    };
41
42    //==========================================================
43
44    void BaseModel::init(unsigned int pNNodes, unsigned int  pNTriangles)
45    {
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];
52    }
53
54    //==========================================================
55
56    void BaseModel::free()
57    {
58        if(getTriangles() != 0) delete [] getTriangles(); setNTriangles(0);
59        if(getTreeNodes() != 0) delete [] getTreeNodes(); setNNodes(0);
60    }
61
62    //==========================================================
63
64    void BaseModel::intersect(const G3D::AABox& pBox, const G3D::Ray& pRay, float& pMaxDist, G3D::Vector3& pOutLocation, G3D::Vector3& /*pOutNormal*/) const
65    {
66        bool isInside = false;
67
68        float d = MyCollisionDetection::collisionLocationForMovingPointFixedAABox(
69            pRay.origin, pRay.direction,
70            pBox,
71            pOutLocation, isInside);
72        if (!isInside && ((d > 0) && (d < pMaxDist)))
73        {
74            pMaxDist = d;
75        }
76    }
77
78    //==========================================================
79
80    bool BaseModel::intersect(const G3D::AABox& pBox, const G3D::Ray& pRay, float& pMaxDist) const
81    {
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);
88
89        bool canHitThisNode = (alreadyInsideBounds ||               
90            (rayWillHitBounds && ((location - pRay.origin).squaredLength() < (pMaxDist * pMaxDist))));
91
92        return canHitThisNode;
93    }
94
95}                                                           // VMAP
Note: See TracBrowser for help on using the browser.