This commit is contained in:
aozhiwei 2023-01-05 16:30:09 +08:00
parent 838e078e0f
commit e9aa79fa00
2 changed files with 32 additions and 0 deletions

View File

@ -612,3 +612,34 @@ glm::vec3 MapInstance::UnScaleEx(const glm::vec3& v)
UnScale(result);
return result;
}
dtPoly* MapInstance::GetPoly(glm::vec3 pos)
{
dtPolyRef startRef = INVALID_NAVMESH_POLYREF;
dtQueryFilter filter;
filter.setIncludeFlags(0xffff);
filter.setExcludeFlags(0);
const float extents[3] = {2.f, 4.f, 2.f};
float nearestPt[3];
Scale(pos);
float pos1[3];
pos1[0] = pos.x;
pos1[1] = pos.y;
pos1[2] = pos.z;
const dtMeshTile* tile = navmesh_->getTileAt(0, 0, 0);
assert(tile);
navmesh_query_->findNearestPoly(pos1, extents, &filter, &startRef, nearestPt);
if (startRef) {
unsigned int slat = 0;
unsigned int it = 0;
unsigned int ip = 0;
navmesh_->decodePolyId(startRef, slat, it, ip);
return &tile->polys[ip];
}
return nullptr;
}

View File

@ -37,6 +37,7 @@ class MapInstance : public std::enable_shared_from_this<MapInstance>
glm::vec3& hit_point, bool& hit_result);
bool FindNearestPoint(const glm::vec3& center, float radius, glm::vec3& nearestPt);
bool GetPosHeight(const Position& pos, float& out_height);
dtPoly* GetPoly(glm::vec3 pos);
void Scale(glm::vec3& v);
void UnScale(glm::vec3& v);
glm::vec3 UnScaleEx(const glm::vec3& v);