This commit is contained in:
aozhiwei 2022-12-14 15:09:07 +08:00
parent 879ae26490
commit 3091de966c
4 changed files with 40 additions and 7 deletions

View File

@ -19,6 +19,13 @@ namespace MetaData
void Map::Init() void Map::Init()
{ {
{
metatable::Map* mutable_pb = (metatable::Map*)pb;
#if DEBUG
mutable_pb->set_scale(0.1f);
#else
#endif
}
rand_space = 0; rand_space = 0;
{ {
std::vector<std::string> strings; std::vector<std::string> strings;

View File

@ -79,24 +79,31 @@ void MoveHelper::CalcTargetPos(float distance)
a8::XPrintf("CalcTaretPos old_size:%d\n", {paths_.size()}); a8::XPrintf("CalcTaretPos old_size:%d\n", {paths_.size()});
} }
#endif #endif
glm::vec3 start; glm::vec3 start = owner_->GetPos().ToGlmVec3();
glm::vec3 end; glm::vec3 end;
glm::vec3 hit_point; glm::vec3 hit_point;
#if 1
start *= owner_->room->GetMapMeta()->pb->scale();
#else
start.x = owner_->GetPos().x / 10.0f; start.x = owner_->GetPos().x / 10.0f;
start.y = 0; start.y = 0;
start.z = owner_->GetPos().y / 10.0f; start.z = owner_->GetPos().y / 10.0f;
#endif
#if 1
#else
a8::Vec2 target_pos2d = owner_->GetPos() + owner_->GetMoveDir() * distance; a8::Vec2 target_pos2d = owner_->GetPos() + owner_->GetMoveDir() * distance;
end.x = target_pos2d.x / 10.0f; end.x = target_pos2d.x / 10.0f;
end.y = 0; end.y = 0;
end.z = target_pos2d.y / 10.0f; end.z = target_pos2d.y / 10.0f;
#endif
bool is_hit = false; bool is_hit = false;
MovePathPoint point; MovePathPoint point;
if (c->HasBuffEffect(kBET_ThroughWall) || if (owner_->HasBuffEffect(kBET_ThroughWall) ||
c->HasBuffEffect(kBET_Fly) || owner_->HasBuffEffect(kBET_Fly) ||
c->HasBuffEffect(kBET_Jump)) { owner_->HasBuffEffect(kBET_Jump)) {
point.tar_pos = end * 10.f; point.tar_pos = end * 10.f;
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;
@ -122,7 +129,7 @@ void MoveHelper::CalcTargetPos(float distance)
a8::Vec2 v2; a8::Vec2 v2;
v2.x = point.tar_pos.x; v2.x = point.tar_pos.x;
v2.y = point.tar_pos.z; v2.y = point.tar_pos.z;
point.distance = v2.Distance(owner_->GetPos()); 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;
@ -152,14 +159,21 @@ void MoveHelper::CalcTargetPos(float distance)
}); });
#endif #endif
if (v2.Distance(owner_->GetPos()) < 0.00001f) { if (point.distance < 0.00001f / owner_->room->GetMapMeta()->pb->scale()) {
return; return;
} }
#if 1
a8::Vec2 dir = owner_->GetPos().CalcDir2DEx(v2);
dir.Normalize();
point.dir.x = dir.x;
point.dir.z = dir.y;
#else
a8::Vec2 dir = (v2 - owner_->GetPos()); a8::Vec2 dir = (v2 - owner_->GetPos());
dir.Normalize(); dir.Normalize();
point.dir.x = dir.x; point.dir.x = dir.x;
point.dir.z = dir.y; point.dir.z = dir.y;
#endif
paths_.push_back(point); paths_.push_back(point);
} }

View File

@ -25,6 +25,16 @@ a8::Vec2 Position::CalcDir2D(const Position& target_pos)
return target_pos.ToVec2() - ToVec2(); return target_pos.ToVec2() - ToVec2();
} }
a8::Vec2 Position::CalcDir2DEx(const a8::Vec2& target_pos)
{
return target_pos - ToVec2();
}
a8::Vec2 Position::CalcDirGlm2DEx(const glm::vec2& target_pos)
{
return a8::Vec2(target_pos.x, target_pos.y) - ToVec2();
}
void Position::FromVec2(const a8::Vec2 v) void Position::FromVec2(const a8::Vec2 v)
{ {
x = v.x; x = v.x;
@ -45,7 +55,7 @@ void Position::FromVec3(const a8::Vec3 v)
z = v.z; z = v.z;
} }
void Position::FromGlmVec2Ex(const glm::vec2 v) void Position::FromGlmVec2(const glm::vec2 v)
{ {
x = v.x; x = v.x;
y = v.y; y = v.y;

View File

@ -76,6 +76,8 @@ struct Position
float Distance2D2(const Position& pos); float Distance2D2(const Position& pos);
float ManhattanDistance2D(const Position& target_pos); float ManhattanDistance2D(const Position& target_pos);
a8::Vec2 CalcDir2D(const Position& target_pos); a8::Vec2 CalcDir2D(const Position& target_pos);
a8::Vec2 CalcDir2DEx(const a8::Vec2& target_pos);
a8::Vec2 CalcDirGlm2DEx(const glm::vec2& target_pos);
void FromVec2(const a8::Vec2 v); void FromVec2(const a8::Vec2 v);
void FromVec2Ex(const a8::Vec2 v); void FromVec2Ex(const a8::Vec2 v);