22 #include "precompiled.h"
41 m_Heightfield(m_pTerrain->GetHeightMap()),
42 m_MapSize(m_pTerrain->GetVerticesPerSide()),
66 float det = edge0.
Dot(pvec);
67 if (fabs(det)<EPSILON)
70 float inv_det = 1.0f/det;
76 float u=tvec.
Dot(pvec)*inv_det;
77 if (u<-0.01f || u>1.01f)
84 float v=dir.
Dot(qvec)*inv_det;
85 if (v<0.0f || u+v>1.0f)
89 float d=edge1.
Dot(qvec)*inv_det;
134 debug_warn(L
"CHFTracer::RayIntersect called with zero-size map");
152 traversalPt=origin+dir*tmin;
158 int sx=dir.
X<0 ? -1 : 1;
159 int sz=dir.
Z<0 ? -1 : 1;
161 float invCellSize=1.0f/float(m_CellSize);
163 float fcx=traversalPt.
X*invCellSize;
164 int cx=(int)floor(fcx);
166 float fcz=traversalPt.
Z*invCellSize;
167 int cz=(int)floor(fcz);
169 float invdx = 1.0e20f;
170 float invdz = 1.0e20f;
172 if (fabs(dir.
X) > 1.0e-20)
173 invdx =
float(1.0/fabs(dir.
X));
174 if (fabs(dir.
Z) > 1.0e-20)
175 invdz =
float(1.0/fabs(dir.
Z));
205 fcx=traversalPt.
X*invCellSize;
206 fcz=traversalPt.
Z*invCellSize;
209 float dx=(sx==-1) ? fcx-
float(cx) : 1-(fcx-float(cx));
211 float dz=(sz==-1) ? fcz-
float(cz) : 1-(fcz-float(cz));
224 traversalPt+=dir*dist;
225 }
while (traversalPt.
Y>=0);
const ssize_t TERRAIN_TILE_SIZE
metres [world space units] per tile in x and z
float Dot(const CVector3D &vector) const
CVector3D Cross(const CVector3D &vector) const
void CalcPosition(ssize_t i, ssize_t j, CVector3D &pos) const
bool RayIntersect(const CVector3D &origin, const CVector3D &dir, int &x, int &z, CVector3D &ipt) const
bool CellIntersect(int cx, int cz, const CVector3D &origin, const CVector3D &dir, float &dist) const
const float HEIGHT_SCALE
metres per u16 height unit
static const int MARGIN_SIZE
bool RayTriIntersect(const CVector3D &v0, const CVector3D &v1, const CVector3D &v2, const CVector3D &origin, const CVector3D &dir, float &dist) const
bool RayIntersect(const CVector3D &origin, const CVector3D &dir, float &tmin, float &tmax) const
Check if a given ray intersects this AABB.
CHFTracer(CTerrain *pTerrain)
#define debug_warn(expr)
display the error dialog with the given text.