1
This commit is contained in:
parent
f3b0d043c2
commit
3aaf66c96f
@ -173,6 +173,7 @@ void MapInstance::Init()
|
||||
end.y = 0;
|
||||
end.z = 51.25;
|
||||
bool hit_result = false;
|
||||
#if 0
|
||||
auto a = Raycast(0, start, end, hit_point, hit_result);
|
||||
|
||||
a8::XPrintf("ret:%d hit_point:%f,%f,%f\n",
|
||||
@ -183,6 +184,7 @@ void MapInstance::Init()
|
||||
hit_point.z
|
||||
});
|
||||
int i = 0;
|
||||
#endif
|
||||
}
|
||||
{
|
||||
std::set<float> group_y;
|
||||
@ -430,7 +432,7 @@ bool MapInstance::Raycast(int layer, const glm::vec3& start, const glm::vec3& en
|
||||
|
||||
#ifdef DEBUG
|
||||
{
|
||||
std::string dbg_data = a8::Format("npolys:%d ", {npolys});
|
||||
std::string dbg_data = a8::Format("npolys:%d t:%f ", {npolys, t});
|
||||
for (int i = 0; i < npolys; ++i) {
|
||||
auto itr = poly_hash.find(polys_[i]);
|
||||
if (itr != poly_hash.end()) {
|
||||
@ -458,12 +460,20 @@ 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_[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;
|
||||
hit_pos_[2] = spos[2] + (epos[2] - spos[2]) * t;*/
|
||||
dtVlerp(hit_pos_, spos, epos, t);
|
||||
if (npolys > 0) {
|
||||
float h = 0;
|
||||
navmesh_query_->getPolyHeight(polys_[npolys-1], hit_pos_, &h);
|
||||
{
|
||||
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);
|
||||
}
|
||||
hit_pos_[1] = h;
|
||||
}
|
||||
hit_result = true;
|
||||
@ -505,6 +515,29 @@ bool MapInstance::FindNearestPoint(const a8::Vec3& center, float radius, a8::Vec
|
||||
|
||||
bool MapInstance::GetPosHeight(const Position& pos, float& out_height)
|
||||
{
|
||||
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];
|
||||
|
||||
float center[3];
|
||||
center[0] = pos.x * GetMapMeta()->pb->scale();
|
||||
center[1] = pos.y;
|
||||
center[2] = pos.z * GetMapMeta()->pb->scale();
|
||||
|
||||
navmesh_query_->findNearestPoly(center, extents, &filter, &startRef, nearestPt);
|
||||
if (!startRef) {
|
||||
return false;
|
||||
}
|
||||
|
||||
a8::XPrintf("getPosHeight:%d\n", {startRef});
|
||||
auto ret = navmesh_query_->getPolyHeight(startRef, center, &out_height);
|
||||
assert(ret == DT_SUCCESS);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -24,11 +24,54 @@ bool MoveHelper::GetMovePosition(glm::vec3& out_pos)
|
||||
MovePathPoint& curr_point = paths_[path_index_];
|
||||
{
|
||||
a8::Vec2 dir = a8::Vec2(curr_point.dir.x, curr_point.dir.z);
|
||||
float h = 0.0f;
|
||||
if (owner_->room->map_instance->GetPosHeight(curr_point.curr_pos, h)) {
|
||||
a8::XPrintf("pos:%f,%f,%f h1:%f\n",
|
||||
{
|
||||
owner_->GetPos().x,
|
||||
owner_->GetPos().y,
|
||||
owner_->GetPos().z,
|
||||
h
|
||||
});
|
||||
curr_point.curr_pos.y = h;
|
||||
} else {
|
||||
abort();
|
||||
}
|
||||
curr_point.curr_pos.AddVec2(dir * owner_->GetSpeed());
|
||||
owner_->SetPos(curr_point.curr_pos);
|
||||
if (owner_->room->map_instance->GetPosHeight(owner_->GetPos(), h)) {
|
||||
a8::XPrintf("pos:%f,%f,%f h2:%f\n",
|
||||
{
|
||||
owner_->GetPos().x,
|
||||
owner_->GetPos().y,
|
||||
owner_->GetPos().z,
|
||||
h
|
||||
});
|
||||
auto new_pos = owner_->GetPos();
|
||||
new_pos.y = h;
|
||||
owner_->SetPos(new_pos);
|
||||
} else {
|
||||
abort();
|
||||
}
|
||||
}
|
||||
if (owner_->GetPos().Distance2D2(curr_point.src_pos) - curr_point.distance >= 0.0001f) {
|
||||
curr_point.tar_pos.y = curr_point.curr_pos.y;
|
||||
owner_->SetPos(curr_point.tar_pos);
|
||||
float h = 0.0f;
|
||||
if (owner_->room->map_instance->GetPosHeight(owner_->GetPos(), h)) {
|
||||
a8::XPrintf("pos:%f,%f,%f h3:%f\n",
|
||||
{
|
||||
owner_->GetPos().x,
|
||||
owner_->GetPos().y,
|
||||
owner_->GetPos().z,
|
||||
h
|
||||
});
|
||||
auto new_pos = owner_->GetPos();
|
||||
new_pos.y = h;
|
||||
owner_->SetPos(new_pos);
|
||||
} else {
|
||||
abort();
|
||||
}
|
||||
++path_index_;
|
||||
if (path_index_ < paths_.size()) {
|
||||
MovePathPoint& next_point = paths_[path_index_];
|
||||
|
Loading…
x
Reference in New Issue
Block a user