This commit is contained in:
aozhiwei 2023-05-15 11:30:42 +08:00
parent 38e444124a
commit 0a9b10725a

View File

@ -1137,8 +1137,8 @@ void MapInstance::AdjustOnLandPoint(glm::vec3& point)
glm::vec3 orig;
glm::vec3 dir;
glm::vec2 bary_position;
float distance;
const dtPoly* nearest_poly = nullptr;
float nearest_distance = 0.0f;
for (int i = 0; i < poly_count; ++i) {
unsigned int slat = 0;
@ -1162,6 +1162,10 @@ void MapInstance::AdjustOnLandPoint(glm::vec3& point)
glm::vec3 v0 = glm::vec3(va[0], va[1], va[2]);
glm::vec3 v1 = glm::vec3(vb[0], vb[1], vb[2]);
glm::vec3 v2 = glm::vec3(vc[0], vc[1], vc[2]);
glm::vec2 bary_position;
float distance;
bool hit = glm::intersectRayTriangle
(orig,
dir,
@ -1171,7 +1175,21 @@ void MapInstance::AdjustOnLandPoint(glm::vec3& point)
bary_position,
distance
);
}
if (hit && distance > 0.00001f) {
if (nearest_poly) {
if (distance < nearest_distance) {
nearest_poly = poly;
nearest_distance = distance;
}
} else {
nearest_poly = poly;
nearest_distance = distance;
}
}
}//end for ii
}//end for i;
if (!nearest_poly) {
return;
}
glm::vec3 nearest_pt = orig + dir * nearest_distance;
}