Pyrogenesis trunk
HFTracer.h
Go to the documentation of this file.
1/* Copyright (C) 2023 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
25class CPatch;
26class CVector3D;
27class CTerrain;
28
29///////////////////////////////////////////////////////////////////////////////
30// CHFTracer: a class for determining ray intersections with a heightfield
32{
33public:
34 // constructor; setup data
35 CHFTracer(CTerrain& terrain);
36
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;
40
41 /**
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.
46 *
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.
51 *
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.
55 */
56 static bool PatchRayIntersect(CPatch* patch, const CVector3D& origin, const CVector3D& dir, CVector3D* out);
57
58private:
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;
61
62 // The terrain we're operating on
64 // the heightfield were tracing
66 // size of the heightfield
67 size_t m_MapSize;
68 // cell size - size of each cell in x and z
70 // vertical scale - size of each cell in y
72};
73
74#endif
Definition: HFTracer.h:32
bool CellIntersect(int cx, int cz, const CVector3D &origin, const CVector3D &dir, float &dist) const
Definition: HFTracer.cpp:106
CHFTracer(CTerrain &terrain)
Definition: HFTracer.cpp:44
CTerrain & m_Terrain
Definition: HFTracer.h:63
float m_CellSize
Definition: HFTracer.h:69
static bool PatchRayIntersect(CPatch *patch, const CVector3D &origin, const CVector3D &dir, CVector3D *out)
Intersects ray with a single patch.
Definition: HFTracer.cpp:275
float m_HeightScale
Definition: HFTracer.h:71
const u16 * m_Heightfield
Definition: HFTracer.h:65
size_t m_MapSize
Definition: HFTracer.h:67
bool RayIntersect(const CVector3D &origin, const CVector3D &dir, int &x, int &z, CVector3D &ipt) const
Definition: HFTracer.cpp:133
Definition: Patch.h:49
Definition: Terrain.h:52
Definition: Vector3D.h:31
uint16_t u16
Definition: types.h:38
static void out(const wchar_t *fmt,...)
Definition: wdbg_sym.cpp:407