This commit is contained in:
aozhiwei 2022-12-16 12:52:23 +08:00
parent 3aaf66c96f
commit ea39a9387b

View File

@ -444,6 +444,11 @@ bool MapInstance::Raycast(int layer, const glm::vec3& start, const glm::vec3& en
const float* va = &tile->verts[poly->verts[ii] * 3];
dbg_data += a8::Format(" v:%d %f,%f,%f ", {ii, va[0], va[1], va[2]});
}
{
const unsigned int ip = (unsigned int)(poly - tile->polys);
const dtPolyDetail* pd = &tile->detailMeshes[ip];
}
} else {
abort();
}
@ -465,16 +470,61 @@ bool MapInstance::Raycast(int layer, const glm::vec3& start, const glm::vec3& en
hit_pos_[2] = spos[2] + (epos[2] - spos[2]) * t;*/
dtVlerp(hit_pos_, spos, epos, t);
if (npolys > 0) {
dtVlerp(hit_pos_, spos, epos, t - 0.01f);
float h = 0;
bool ok = false;
float hit_pos_copy[3];
dtVcopy(hit_pos_copy, hit_pos_);
#if 0
{
bool over_poly = false;
auto ret = navmesh_query_->closestPointOnPoly(polys_[npolys-1], hit_pos_, hit_pos_copy, &over_poly);
assert(ret == DT_SUCCESS);
}
{
auto ret = navmesh_query_->getPolyHeight(polys_[npolys-1], hit_pos_copy, &h);
assert(ret == DT_SUCCESS);
}
#else
for (int i = 0; i < npolys; ++i) {
auto ret = navmesh_query_->getPolyHeight(polys_[i], hit_pos_copy, &h);
if (ret == DT_SUCCESS){
ok = true;
break;
}
}
assert(ok);
#endif
hit_pos_[1] = h;
#if 0
#if 1
float h;
Position tmp_pos;
tmp_pos.x = hit_pos_[0] / GetMapMeta()->pb->scale();
tmp_pos.y = hit_pos_[1];
tmp_pos.z = hit_pos_[2] / GetMapMeta()->pb->scale();
GetPosHeight(tmp_pos, h);
hit_pos_[1] = h;
#else
float h = 0;
{
float hit_pos_copy[3];
dtVcopy(hit_pos_copy, hit_pos_);
hit_pos_copy[0] += 0.1f;
auto ret = navmesh_query_->getPolyHeight(polys_[npolys-1], hit_pos_copy, &h);
assert(ret == DT_SUCCESS);
{
bool over_poly = false;
auto ret = navmesh_query_->closestPointOnPoly(polys_[npolys-1], hit_pos_, hit_pos_copy, &over_poly);
assert(ret == DT_SUCCESS);
}
{
auto ret = navmesh_query_->getPolyHeight(polys_[npolys-1], hit_pos_copy, &h);
assert(ret == DT_SUCCESS);
}
}
hit_pos_[1] = h;
#endif
#endif
}
hit_result = true;
}
@ -529,13 +579,14 @@ bool MapInstance::GetPosHeight(const Position& pos, float& out_height)
center[1] = pos.y;
center[2] = pos.z * GetMapMeta()->pb->scale();
navmesh_query_->findNearestPoly(center, extents, &filter, &startRef, nearestPt);
bool isOverPoly;
navmesh_query_->findNearestPoly(center, extents, &filter, &startRef, nearestPt, &isOverPoly);
if (!startRef) {
return false;
}
a8::XPrintf("getPosHeight:%d\n", {startRef});
auto ret = navmesh_query_->getPolyHeight(startRef, center, &out_height);
auto ret = navmesh_query_->getPolyHeight(startRef, nearestPt, &out_height);
assert(ret == DT_SUCCESS);
return true;