mirror of
https://github.com/openmoh/openmohaa.git
synced 2025-05-01 23:27:59 +03:00
Fix infinite loop in R_TerrainHeightForPoly
This commit is contained in:
parent
1e0195f6e3
commit
c0d37c504a
1 changed files with 47 additions and 62 deletions
|
@ -1229,6 +1229,7 @@ qboolean R_TerrainHeightForPoly(cTerraPatchUnpacked_t *pPatch, polyVert_t *pVert
|
||||||
|
|
||||||
float x = pVerts->xyz[0];
|
float x = pVerts->xyz[0];
|
||||||
float y = pVerts->xyz[1];
|
float y = pVerts->xyz[1];
|
||||||
|
terraInt iTri;
|
||||||
|
|
||||||
// Calculate the average of the x and y coordinates of all vertices
|
// Calculate the average of the x and y coordinates of all vertices
|
||||||
if (nVerts > 1) {
|
if (nVerts > 1) {
|
||||||
|
@ -1243,24 +1244,10 @@ qboolean R_TerrainHeightForPoly(cTerraPatchUnpacked_t *pPatch, polyVert_t *pVert
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the first valid triangle in the patch
|
// Get the first valid triangle in the patch
|
||||||
terraInt iTri = pPatch->drawinfo.iTriHead;
|
iTri = pPatch->drawinfo.iTriHead;
|
||||||
if (!iTri) {
|
|
||||||
assert(
|
|
||||||
!pPatch->drawinfo.iTriHead
|
|
||||||
&& va(
|
|
||||||
"R_TerrainHeightForPoly: point(%f %f) not in patch(%f %f %f)\n",
|
|
||||||
x,
|
|
||||||
y,
|
|
||||||
pPatch->x0,
|
|
||||||
pPatch->y0,
|
|
||||||
pPatch->z0
|
|
||||||
)
|
|
||||||
);
|
|
||||||
return qfalse;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find a triangle that contains the point (x, y)
|
// Find a triangle that contains the point (x, y)
|
||||||
while (qtrue) {
|
for(iTri = pPatch->drawinfo.iTriHead; iTri; iTri = g_pTris[iTri].iNext) {
|
||||||
if (g_pTris[iTri].byConstChecks & 4) {
|
if (g_pTris[iTri].byConstChecks & 4) {
|
||||||
// Get all three x-y coordinates of the current triangle's vertices
|
// Get all three x-y coordinates of the current triangle's vertices
|
||||||
x0 = g_pVert[g_pTris[iTri].iPt[0]].xyz[0];
|
x0 = g_pVert[g_pTris[iTri].iPt[0]].xyz[0];
|
||||||
|
@ -1291,30 +1278,11 @@ qboolean R_TerrainHeightForPoly(cTerraPatchUnpacked_t *pPatch, polyVert_t *pVert
|
||||||
|
|
||||||
fAreaTotal = fArea[0] + fArea[1] + fArea[2];
|
fAreaTotal = fArea[0] + fArea[1] + fArea[2];
|
||||||
if (fAreaTotal > 0.0) {
|
if (fAreaTotal > 0.0) {
|
||||||
|
//
|
||||||
// Found it - the point is inside the triangle
|
// Found it - the point is inside the triangle
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
iTri = g_pTris[iTri].iNext;
|
|
||||||
if (!iTri) {
|
|
||||||
// There's no triangle that contains point (x, y) - bail out
|
|
||||||
assert(
|
|
||||||
!g_pTris[iTri].iNext
|
|
||||||
&& va(
|
|
||||||
"R_TerrainHeightForPoly: point(%f %f) not in patch(%f %f %f)\n",
|
|
||||||
x,
|
|
||||||
y,
|
|
||||||
pPatch->x0,
|
|
||||||
pPatch->y0,
|
|
||||||
pPatch->z0
|
|
||||||
)
|
|
||||||
);
|
|
||||||
return qfalse;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calculate the barycentric coordinates (fKx, fKy, fKz) of the triangle
|
// Calculate the barycentric coordinates (fKx, fKy, fKz) of the triangle
|
||||||
|
//
|
||||||
|
|
||||||
float z0 = g_pVert[g_pTris[iTri].iPt[0]].xyz[2] / fAreaTotal;
|
float z0 = g_pVert[g_pTris[iTri].iPt[0]].xyz[2] / fAreaTotal;
|
||||||
float z1 = g_pVert[g_pTris[iTri].iPt[1]].xyz[2] / fAreaTotal;
|
float z1 = g_pVert[g_pTris[iTri].iPt[1]].xyz[2] / fAreaTotal;
|
||||||
float z2 = g_pVert[g_pTris[iTri].iPt[2]].xyz[2] / fAreaTotal;
|
float z2 = g_pVert[g_pTris[iTri].iPt[2]].xyz[2] / fAreaTotal;
|
||||||
|
@ -1343,6 +1311,23 @@ qboolean R_TerrainHeightForPoly(cTerraPatchUnpacked_t *pPatch, polyVert_t *pVert
|
||||||
}
|
}
|
||||||
|
|
||||||
return qtrue;
|
return qtrue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(
|
||||||
|
!pPatch->drawinfo.iTriHead
|
||||||
|
&& va(
|
||||||
|
"R_TerrainHeightForPoly: point(%f %f) not in patch(%f %f %f)\n",
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
pPatch->x0,
|
||||||
|
pPatch->y0,
|
||||||
|
pPatch->z0
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return qfalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
void R_TerrainRestart_f(void)
|
void R_TerrainRestart_f(void)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue