This commit is contained in:
aozhiwei 2022-12-15 14:30:12 +08:00
parent 4498d8d556
commit a3a321069d
3 changed files with 20 additions and 4 deletions

View File

@ -499,3 +499,17 @@ bool MapInstance::GetPosHeight(const Position& pos, float& out_height)
{ {
return true; return true;
} }
void MapInstance::Scale(glm::vec3& v)
{
float old_y = v.y;
v *= GetMapMeta()->pb->scale();
v.y = old_y;
}
void MapInstance::UnScale(glm::vec3& v)
{
float old_y = v.y;
v /= GetMapMeta()->pb->scale();
v.y = old_y;
}

View File

@ -41,6 +41,8 @@ class MapInstance
int Raycast(int layer, const glm::vec3& start, const glm::vec3& end, glm::vec3& hit_point); int Raycast(int layer, const glm::vec3& start, const glm::vec3& end, glm::vec3& hit_point);
bool FindNearestPoint(const a8::Vec3& center, float radius, a8::Vec3& nearestPt); bool FindNearestPoint(const a8::Vec3& center, float radius, a8::Vec3& nearestPt);
bool GetPosHeight(const Position& pos, float& out_height); bool GetPosHeight(const Position& pos, float& out_height);
void Scale(glm::vec3& v);
void UnScale(glm::vec3& v);
private: private:
void CreateThings(); void CreateThings();

View File

@ -76,14 +76,14 @@ void MoveHelper::CalcTargetPos(float distance)
} }
} else { } else {
glm::vec3 hit_point; glm::vec3 hit_point;
start *= owner_->room->GetMapMeta()->pb->scale(); owner_->room->map_instance->Scale(start);
end *= owner_->room->GetMapMeta()->pb->scale(); owner_->room->map_instance->Scale(end);
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.FromGlmVec3(hit_point / owner_->room->GetMapMeta()->pb->scale()); owner_->room->map_instance->UnScale(hit_point);
} else { } else {
point.tar_pos.FromGlmVec3(end / owner_->room->GetMapMeta()->pb->scale()); owner_->room->map_instance->UnScale(end);
} }
} }
point.distance = owner_->GetPos().Distance2D2(point.tar_pos); point.distance = owner_->GetPos().Distance2D2(point.tar_pos);