From 0a9b10725a8be343f8ec413f783b2d420bbeafd5 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 15 May 2023 11:30:42 +0800 Subject: [PATCH] 1 --- server/gameserver/mapinstance.cc | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/server/gameserver/mapinstance.cc b/server/gameserver/mapinstance.cc index e7b7b9fc..3dac2f6c 100644 --- a/server/gameserver/mapinstance.cc +++ b/server/gameserver/mapinstance.cc @@ -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; }