1
This commit is contained in:
parent
885bc6eae0
commit
c2356b57b9
@ -216,3 +216,32 @@ size_t Movement::GetPathSize()
|
||||
{
|
||||
return paths_.size();
|
||||
}
|
||||
|
||||
bool Movement::FindPath(const glm::vec3& target_pos, float distance)
|
||||
{
|
||||
ClearPath();
|
||||
|
||||
glm::vec3 start = owner_->GetPos().ToGlmVec3();
|
||||
glm::vec3 end = target_pos;
|
||||
std::vector<glm::vec3> paths;
|
||||
|
||||
owner_->room->map_instance->FindStraightPath(start, end, paths);
|
||||
if (paths.size() > 0) {
|
||||
glm::vec3 last_pos = owner_->GetPos().ToGlmVec3();
|
||||
for (const glm::vec3& pos : paths) {
|
||||
glm::vec3 dir = pos - last_pos;
|
||||
GlmHelper::Normalize(dir);
|
||||
MovePathPoint point;
|
||||
point.src_pos.FromGlmVec3(last_pos);
|
||||
point.dir.x = dir.x;
|
||||
point.dir.y = dir.y;
|
||||
point.dir.z = dir.z;
|
||||
point.distance -= GlmHelper::Norm(pos - last_pos);
|
||||
point.tar_pos.FromGlmVec3(pos);
|
||||
paths_.push_back(point);
|
||||
|
||||
last_pos = pos;
|
||||
}
|
||||
}
|
||||
return !paths.empty();
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ class Movement
|
||||
void AddPaths(const glm::vec3& start, std::vector<glm::vec3>& paths);
|
||||
size_t GetPathSize();
|
||||
bool IsFindPath() { return is_find_path_; }
|
||||
bool FindPath(const glm::vec3& target_pos, float distance);
|
||||
|
||||
private:
|
||||
std::vector<MovePathPoint> paths_;
|
||||
|
Loading…
x
Reference in New Issue
Block a user