1 /* Copyright (C) 2014 Wildfire Games.
2 * This file is part of 0 A.D.
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.
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.
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/>.
19 * Determine intersection of rays with a heightfield.
22 #ifndef INCLUDED_HFTRACER
23 #define INCLUDED_HFTRACER
29 ///////////////////////////////////////////////////////////////////////////////
30 // CHFTracer: a class for determining ray intersections with a heightfield
34 // constructor; setup data
35 CHFTracer(CTerrain
*pTerrain
);
37 // intersect ray with this heightfield; return true if intersection
38 // occurs (and fill in grid coordinates and point of intersection), or false otherwise
39 bool RayIntersect(const CVector3D
& origin
, const CVector3D
& dir
, int& x
, int& z
, CVector3D
& ipt
) const;
42 * Intersects ray with a single patch.
43 * The ray is a half-infinite line starting at @p origin with direction @p dir
44 * (not required to be a unit vector).. The patch is treated as a collection
45 * of two-sided triangles, corresponding to the terrain tiles.
47 * If there is an intersection, returns true; and if @p out is not NULL, it
48 * is set to the intersection point. This is guaranteed to be the earliest
49 * tile intersected (starting at @p origin), but not necessarily the earlier
50 * triangle inside that tile.
52 * This partly duplicates RayIntersect, but it only operates on a single
53 * patch, and it's more precise (it uses the same tile triangulation as the
54 * renderer), and tries to be more numerically robust.
56 static bool PatchRayIntersect(CPatch
* patch
, const CVector3D
& origin
, const CVector3D
& dir
, CVector3D
* out
);
59 // test if ray intersects either of the triangles in the given
60 bool CellIntersect(int cx
, int cz
, const CVector3D
& origin
, const CVector3D
& dir
, float& dist
) const;
62 // The terrain we're operating on
64 // the heightfield were tracing
65 const u16
* m_Heightfield
;
66 // size of the heightfield
68 // cell size - size of each cell in x and z
70 // vertical scale - size of each cell in y