Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HFTracer.h
Go to the documentation of this file.
1 /* Copyright (C) 2009 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. 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  * 0 A.D. 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 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 /*
19  * Determine intersection of rays with a heightfield.
20  */
21 
22 #ifndef INCLUDED_HFTRACER
23 #define INCLUDED_HFTRACER
24 
25 class CVector3D;
26 class CTerrain;
27 
28 ///////////////////////////////////////////////////////////////////////////////
29 // CHFTracer: a class for determining ray intersections with a heightfield
30 class CHFTracer
31 {
32 public:
33  // constructor; setup data
34  CHFTracer(CTerrain *pTerrain);
35 
36  // intersect ray with this heightfield; return true if intersection
37  // occurs (and fill in grid coordinates and point of intersection), or false otherwise
38  bool RayIntersect(const CVector3D& origin, const CVector3D& dir, int& x, int& z, CVector3D& ipt) const;
39 
40 private:
41  // intersect a ray with triangle defined by vertices
42  // v0,v1,v2; return true if ray hits triangle at distance less than dist,
43  // or false otherwise
44  bool RayTriIntersect(const CVector3D& v0, const CVector3D& v1, const CVector3D& v2,
45  const CVector3D& origin, const CVector3D& dir, float& dist) const;
46 
47  // test if ray intersects either of the triangles in the given
48  bool CellIntersect(int cx, int cz, const CVector3D& origin, const CVector3D& dir, float& dist) const;
49 
50  // The terrain we're operating on
52  // the heightfield were tracing
54  // size of the heightfield
55  size_t m_MapSize;
56  // cell size - size of each cell in x and z
57  float m_CellSize;
58  // vertical scale - size of each cell in y
60 };
61 
62 #endif
float m_HeightScale
Definition: HFTracer.h:59
const u16 * m_Heightfield
Definition: HFTracer.h:53
float m_CellSize
Definition: HFTracer.h:57
bool RayIntersect(const CVector3D &origin, const CVector3D &dir, int &x, int &z, CVector3D &ipt) const
Definition: HFTracer.cpp:128
bool CellIntersect(int cx, int cz, const CVector3D &origin, const CVector3D &dir, float &dist) const
Definition: HFTracer.cpp:101
CTerrain * m_pTerrain
Definition: HFTracer.h:51
bool RayTriIntersect(const CVector3D &v0, const CVector3D &v1, const CVector3D &v2, const CVector3D &origin, const CVector3D &dir, float &dist) const
Definition: HFTracer.cpp:53
#define u16
Definition: types.h:40
CHFTracer(CTerrain *pTerrain)
Definition: HFTracer.cpp:39
size_t m_MapSize
Definition: HFTracer.h:55