This commit is contained in:
aozhiwei 2022-12-16 13:16:59 +08:00
parent ea39a9387b
commit 359c59f350

View File

@ -444,10 +444,6 @@ 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,66 +461,63 @@ bool MapInstance::Raycast(int layer, const glm::vec3& start, const glm::vec3& en
hit_result = false;
} else {
// Hit
/*hit_pos_[0] = spos[0] + (epos[0] - spos[0]) * t;
hit_pos_[1] = spos[1] + (epos[1] - spos[1]) * t;
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;
a8::Vec2 dir(epos[0] - spos[0], epos[2] - spos[2]);
dir.Normalize();
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);
float h = 0;
bool ok = false;
dir = dir / 10;
for (int ii = npolys - 1; ii >= 0; --ii) {
auto ret = navmesh_query_->getPolyHeight(polys_[ii], 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];
if (!ok){
ok = true;
} else {
for (int i = 0; i < 3; ++i) {
hit_pos_copy[0] -= dir.x;
hit_pos_copy[2] -= dir.y;
for (int ii = npolys - 1; ii >= 0; --ii) {
auto ret = navmesh_query_->getPolyHeight(polys_[ii], hit_pos_copy, &h);
if (ret == DT_SUCCESS){
ok = true;
break;
}
}
if (ok) {
break;
}
}
dtVcopy(hit_pos_copy, hit_pos_);
{
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);
for (int i = 0; i < 3; ++i) {
hit_pos_copy[0] += dir.x;
hit_pos_copy[2] += dir.y;
for (int ii = npolys - 1; ii >= 0; --ii) {
auto ret = navmesh_query_->getPolyHeight(polys_[ii], hit_pos_copy, &h);
if (ret == DT_SUCCESS){
ok = true;
break;
}
}
if (ok) {
break;
}
}
}
assert(ok);
hit_pos_[0] = hit_pos_copy[0];
hit_pos_[1] = h;
#endif
#endif
hit_pos_[2] = hit_pos_copy[2];
} else {
abort();
}
hit_result = true;
}