root/trunk/src/shared/vmap/ShortBox.h @ 2

Revision 2, 5.0 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#ifndef _SHORTBOX_H
20#define _SHORTBOX_H
21
22#include <G3D/Vector3.h>
23#include <G3D/AABox.h>
24#include <G3D/Triangle.h>
25#include <G3D/Ray.h>
26
27#include "ShortVector.h"
28
29/**
30This is a box and a triangle Class using ShortVectors. Each vector has 16 bit an a fixed point 12.4 representation.
31*/
32
33namespace VMAP
34{
35
36    class ShortBox
37    {
38        private:
39            ShortVector iV1;
40            ShortVector iV2;
41        public:
42            ShortBox() {}
43            inline const ShortVector& getLo() const { return(iV1); }
44            inline const ShortVector& getHi() const { return(iV2); }
45            inline void setLo(const ShortVector& pV){ iV1 = pV; }
46            inline void setHi(const ShortVector& pV){ iV2 = pV; }
47            inline void setLo(const G3D::Vector3& pV){ iV1 = ShortVector(pV); }
48            inline void setHi(const G3D::Vector3& pV){ iV2 = ShortVector(pV); }
49
50            inline bool operator==(const ShortBox& b) const
51            {
52                return ((iV1 == b.iV1) && (iV2 == b.iV2));
53            }
54
55            inline bool operator!=(const ShortBox& b) const
56            {
57                return !((iV1 == b.iV1) && (iV2 == b.iV2));
58            }
59    };
60
61    //=====================================================================
62#ifdef _DEBUG_VMAPS
63#ifndef gBoxArray
64    extern G3D::Vector3 p1,p2,p3,p4,p5,p6,p7;
65    extern G3D::Array<G3D::AABox>gBoxArray;
66    extern G3D::Array<G3D::Triangle>gTriArray;
67    extern int gCount1, gCount2, gCount3, gCount4;
68    extern bool myfound;
69#endif
70#endif
71
72    static const G3D::Vector3 dummyZeroPosition = G3D::Vector3(0,0,0);
73
74    class TriangleBox
75    {
76        private:
77            ShortVector _vertex[3];
78            //ShortBox iBox;
79        public:
80            inline TriangleBox() { }
81            inline TriangleBox(const ShortVector& pV1, const ShortVector& pV2, const ShortVector& pV3)
82            {
83                _vertex[0] = pV1;
84                _vertex[1] = pV2;
85                _vertex[2] = pV3;
86
87            }
88            inline const ShortVector& vertex (int n) const
89            {
90                return(_vertex[n]);
91            }
92
93            inline const ShortBox getBounds()const
94            {
95                ShortBox box;
96
97                ShortVector lo = _vertex[0];
98                ShortVector hi = lo;
99
100                for (int i = 1; i < 3; ++i)
101                {
102                    lo = lo.min(_vertex[i]);
103                    hi = hi.max(_vertex[i]);
104                }
105                box.setLo(lo);
106                box.setHi(hi);
107                return(box);
108            }
109            inline const G3D::Vector3& getBasePosition() { return(dummyZeroPosition); }
110
111            inline const G3D::AABox getAABoxBounds() const { ShortBox box = getBounds(); return(G3D::AABox(box.getLo().getVector3(), box.getHi().getVector3())); }
112
113            inline bool operator==(const TriangleBox& t) const
114            {
115                return ((_vertex[0] == t._vertex[0]) && (_vertex[1] == t._vertex[1]) &&(_vertex[2] == t._vertex[2]));
116            }
117
118            inline bool operator!=(const TriangleBox& t) const
119            {
120                return !((_vertex[0] == t._vertex[0]) && (_vertex[1] == t._vertex[1]) &&(_vertex[2] == t._vertex[2]));
121            }
122
123            inline void intersect(const G3D::Ray& pRay, float& pMaxDist, bool /*pStopAtFirstHitDummy*/, G3D::Vector3& /*pOutLocationDummy*/, G3D::Vector3& /*pOutNormalDummy*/) const
124            {
125                static const double epsilon = 0.00001;
126                G3D::Triangle testT(vertex(0).getVector3(),vertex(1).getVector3(),vertex(2).getVector3());
127                float t = pRay.intersectionTime(testT);
128                if ((t < pMaxDist) || t < (pMaxDist + epsilon))
129                    pMaxDist = t;
130                else
131                {
132                    testT = G3D::Triangle(vertex(2).getVector3(),vertex(1).getVector3(),vertex(0).getVector3());
133
134#ifdef _DEBUG_VMAPS
135                    {
136                        G3D::Triangle myt(testT.vertex(0)+p6, testT.vertex(1)+p6,testT.vertex(2)+p6);
137                        gTriArray.push_back(myt);
138                    }
139#endif
140                    t = pRay.intersectionTime(testT);
141                    if ((t < pMaxDist) || t < (pMaxDist + epsilon))
142                        pMaxDist = t;
143                }
144            }
145    };
146
147}
148#endif
Note: See TracBrowser for help on using the browser.