This commit is contained in:
aozhiwei 2022-12-14 18:13:37 +08:00
parent 145caa62ee
commit 18d3b78ba6
3 changed files with 14 additions and 19 deletions

View File

@ -87,7 +87,7 @@ void MoveHelper::CalcTargetPos(float distance)
if (owner_->HasBuffEffect(kBET_ThroughWall) || if (owner_->HasBuffEffect(kBET_ThroughWall) ||
owner_->HasBuffEffect(kBET_Fly) || owner_->HasBuffEffect(kBET_Fly) ||
owner_->HasBuffEffect(kBET_Jump)) { owner_->HasBuffEffect(kBET_Jump)) {
point.tar_pos = end; point.tar_pos.FromGlmVec3(end);
if (point.tar_pos.x > owner_->room->GetMapMeta()->pb->map_width() + 10) { if (point.tar_pos.x > owner_->room->GetMapMeta()->pb->map_width() + 10) {
point.tar_pos.x = owner_->room->GetMapMeta()->pb->map_width() - 10; point.tar_pos.x = owner_->room->GetMapMeta()->pb->map_width() - 10;
} }
@ -107,15 +107,12 @@ void MoveHelper::CalcTargetPos(float distance)
int ret = owner_->room->map_instance->Raycast(0, start, end, hit_point); int ret = owner_->room->map_instance->Raycast(0, start, end, hit_point);
if (ret > 0) { if (ret > 0) {
is_hit = true; is_hit = true;
point.tar_pos = hit_point / owner_->room->GetMapMeta()->pb->scale(); point.tar_pos.FromGlmVec3(hit_point / owner_->room->GetMapMeta()->pb->scale());
} else { } else {
point.tar_pos = end / owner_->room->GetMapMeta()->pb->scale(); point.tar_pos.FromGlmVec3(end / owner_->room->GetMapMeta()->pb->scale());
} }
} }
a8::Vec2 v2; point.distance = owner_->GetPos().Distance2D2(point.tar_pos);
v2.x = point.tar_pos.x;
v2.y = point.tar_pos.z;
point.distance = owner_->GetPos().Distance2D(v2);
point.src_pos.x = owner_->GetPos().x; point.src_pos.x = owner_->GetPos().x;
point.src_pos.z = owner_->GetPos().y; point.src_pos.z = owner_->GetPos().y;
point.curr_pos.x = owner_->GetPos().x; point.curr_pos.x = owner_->GetPos().x;
@ -149,17 +146,10 @@ void MoveHelper::CalcTargetPos(float distance)
return; return;
} }
#if 1 a8::Vec2 dir = owner_->GetPos().CalcDir2D(point.tar_pos);
a8::Vec2 dir = owner_->GetPos().CalcDir2DEx(v2);
dir.Normalize(); dir.Normalize();
point.dir.x = dir.x; point.dir.x = dir.x;
point.dir.z = dir.y; point.dir.z = dir.y;
#else
a8::Vec2 dir = (v2 - owner_->GetPos());
dir.Normalize();
point.dir.x = dir.x;
point.dir.z = dir.y;
#endif
paths_.push_back(point); paths_.push_back(point);
} }
@ -172,6 +162,7 @@ void MoveHelper::ClearPath()
void MoveHelper::AddPaths(const a8::Vec3& start, std::vector<a8::Vec3>& paths) void MoveHelper::AddPaths(const a8::Vec3& start, std::vector<a8::Vec3>& paths)
{ {
#if 0
if (paths.empty()) { if (paths.empty()) {
abort(); abort();
return; return;
@ -251,6 +242,7 @@ void MoveHelper::AddPaths(const a8::Vec3& start, std::vector<a8::Vec3>& paths)
#endif #endif
paths_.push_back(p); paths_.push_back(p);
} }
#endif
} }
size_t MoveHelper::GetPathSize() size_t MoveHelper::GetPathSize()

View File

@ -2,11 +2,14 @@
struct MovePathPoint struct MovePathPoint
{ {
glm::vec3 src_pos; private:
glm::vec3 tar_pos; Position src_pos;
glm::vec3 curr_pos; Position tar_pos;
Position curr_pos;
glm::vec3 dir; glm::vec3 dir;
float distance = 0.0f; float distance = 0.0f;
friend class MoveHelper;
}; };
class Creature; class Creature;

View File

@ -22,7 +22,7 @@ float Position::ManhattanDistance2D(const Position& target_pos)
a8::Vec2 Position::CalcDir2D(const Position& target_pos) a8::Vec2 Position::CalcDir2D(const Position& target_pos)
{ {
return target_pos.ToVec2() - ToVec2(); return a8::Vec2(target_pos.x, target_pos.z) - a8::Vec2(x, z);
} }
a8::Vec2 Position::CalcDir2DEx(const a8::Vec2& target_pos) a8::Vec2 Position::CalcDir2DEx(const a8::Vec2& target_pos)