This commit is contained in:
aozhiwei 2023-10-14 13:11:57 +08:00
parent 15488a4309
commit 4e29cd295f
3 changed files with 8 additions and 10 deletions

View File

@ -144,11 +144,10 @@ bool Collision::Check2dRotationRectangle(float rx, float ry, float r, float dx,
return (tmp_dx1 - new_rx) * (tmp_dx1 - new_rx) + (tmp_dy1 - new_ry) * (tmp_dy1 - new_ry) <= r * r; return (tmp_dx1 - new_rx) * (tmp_dx1 - new_rx) + (tmp_dy1 - new_ry) * (tmp_dy1 - new_ry) <= r * r;
} }
bool Collision::IsNearInRange(const glm::vec3& center, const glm::vec3& pos, float range) bool Collision::InSquare(const glm::vec3& center, const glm::vec3& pos, float side_len)
{ {
float x_distance = std::fabs(pos.x - center.x);
} float z_distance = std::fabs(pos.z - center.z);
return (x_distance < side_len &&
bool Collision::IsNearOutRange(const glm::vec3& center, const glm::vec3& pos, float range) { z_distance < side_len);
} }

View File

@ -24,7 +24,6 @@ class Collision
*/ */
static bool Check2dRotationRectangle(float rx, float ry, float r, float dx, float dy, float dw, float dh, float dro); static bool Check2dRotationRectangle(float rx, float ry, float r, float dx, float dy, float dw, float dh, float dro);
static bool IsNearInRange(const glm::vec3& center, const glm::vec3& pos, float range); static bool InSquare(const glm::vec3& center, const glm::vec3& pos, float side_len);
static bool IsNearOutRange(const glm::vec3& center, const glm::vec3& pos, float range);
}; };

View File

@ -248,7 +248,7 @@ bool HeroAgent::HasBuffEffect(int effect_id)
bool HeroAgent::IsNearGas(float range) bool HeroAgent::IsNearGas(float range)
{ {
return Collision::IsNearInRange return Collision::InSquare
(owner_->GetPos().ToGlmVec3(), (owner_->GetPos().ToGlmVec3(),
owner_->GetPos().ToGlmVec3(), owner_->GetPos().ToGlmVec3(),
range); range);
@ -260,7 +260,7 @@ bool HeroAgent::MasterInRange(float range)
!owner_->AsHero()->master.Get()) { !owner_->AsHero()->master.Get()) {
return false; return false;
} }
return Collision::IsNearInRange return Collision::InSquare
(owner_->AsHero()->master.Get()->GetPos().ToGlmVec3(), (owner_->AsHero()->master.Get()->GetPos().ToGlmVec3(),
owner_->GetPos().ToGlmVec3(), owner_->GetPos().ToGlmVec3(),
range); range);