This commit is contained in:
aozhiwei 2024-02-18 14:08:06 +08:00
parent a275cac33d
commit 9bb4cf37f4
6 changed files with 59 additions and 23 deletions

View File

@ -229,7 +229,7 @@ void MapInstance::AttachRoom(Room* room, RoomInitInfo& init_info)
int MapInstance::FindStraightPath(
const glm::vec3& start,
const glm::vec3& end,
std::vector<glm::vec3>& paths)
std::vector<MovePathPoint>& paths)
{
float spos[3];
spos[0] = start.x;
@ -264,7 +264,6 @@ int MapInstance::FindStraightPath(
unsigned char straightPathFlags[MAX_POLYS];
dtPolyRef straightPathPolys[MAX_POLYS];
int nstraightPath;
int pos = 0;
navmesh_query_->findPath
(startRef,
@ -295,17 +294,37 @@ int MapInstance::FindStraightPath(
straightPathPolys,
&nstraightPath,
MAX_POLYS);
glm::vec3 last_pos = start;
UnScale(last_pos);
for(int i = 0; i < nstraightPath * 3; ) {
glm::vec3 currpos;
currpos.x = straightPath[i++];
currpos.y = straightPath[i++];
currpos.z = straightPath[i++];
glm::vec3 pos;
pos.x = straightPath[i++];
pos.y = straightPath[i++];
pos.z = straightPath[i++];
UnScale(pos);
if (!GlmHelper::IsEqual2D(pos, last_pos)) {
glm::vec3 dir = pos - last_pos;
GlmHelper::Normalize(dir);
MovePathPoint point;
point.src_pos.FromGlmVec3(last_pos);
point.curr_pos.FromGlmVec3(last_pos);
point.dir.x = dir.x;
point.dir.y = dir.y;
point.dir.z = dir.z;
point.distance = GlmHelper::Norm2D(pos - last_pos);
point.tar_pos.FromGlmVec3(pos);
paths.push_back(point);
last_pos = pos;
}
#if 0
paths.push_back(currpos);
pos++;
#endif
}
}
return pos;
return paths.size();
}
bool MapInstance::RandPoint(const glm::vec3& center, float range, glm::vec3& out_point)

View File

@ -37,7 +37,7 @@ class MapInstance : public std::enable_shared_from_this<MapInstance>
dtNavMeshQuery* GetNavMeshQuery() { return navmesh_query_.get(); };
int FindStraightPath(const glm::vec3& start,
const glm::vec3& end,
std::vector<glm::vec3>& paths);
std::vector<MovePathPoint>& paths);
bool FindRandomPointAroundCircle(const glm::vec3& center_pos,
float max_radius,
glm::vec3& random_pt);

View File

@ -210,11 +210,25 @@ bool Movement::FindPath(const glm::vec3& target_pos, float distance)
glm::vec3 start = owner_->GetPos().ToGlmVec3();
glm::vec3 end = target_pos;
#if 1
owner_->room->map_instance->Scale(start);
owner_->room->map_instance->Scale(end);
owner_->room->map_instance->FindStraightPath(start, end, paths_);
if (!paths_.empty()) {
is_find_path_ = true;
if (!paths_.empty()) {
owner_->SetMoveDir(paths_.at(0).dir);
owner_->SetAttackDir(paths_.at(0).dir);
}
}
#else
std::vector<glm::vec3> paths;
owner_->room->map_instance->Scale(start);
owner_->room->map_instance->Scale(end);
#if 0
owner_->room->map_instance->FindStraightPath(start, end, paths);
#endif
if (paths.size() > 0) {
glm::vec3 last_pos = owner_->GetPos().ToGlmVec3();
for (const glm::vec3& pos1 : paths) {
@ -256,6 +270,7 @@ bool Movement::FindPath(const glm::vec3& target_pos, float distance)
owner_->SetAttackDir(paths_.at(0).dir);
}
}
#endif
AdjustLastPath(distance);
return !paths_.empty();
}

View File

@ -2,20 +2,6 @@
#include "DetourNavMeshQuery.h"
struct MovePathPoint
{
private:
Position src_pos;
Position tar_pos;
Position curr_pos;
glm::vec3 dir;
float distance = 0.0f;
int same_polys_flags = 0;
std::vector<dtPolyRef> spec_polys;
friend class Movement;
};
class Creature;
class Movement
{

View File

@ -1767,7 +1767,7 @@ void Human::SendUIUpdate()
[this, &notifymsg] (Human* ele_hum, bool& stop)
{
if (ele_hum == this || ele_hum->IsOb()) {
#ifdef MYDEBUG
#ifdef MYDEBUG1
a8::XPrintf("SendUIUpdate self_team_id:%d is_ob:%d data:%s\n",
{
ele_hum->GetTeam()->GetTeamId(),

View File

@ -1,6 +1,7 @@
#pragma once
#include "weakptr.h"
#include "DetourNavMesh.h"
namespace MetaData
{
@ -104,3 +105,18 @@ namespace a8
{
bool GtOrEqZero(float val);
}
struct MovePathPoint
{
private:
Position src_pos;
Position tar_pos;
Position curr_pos;
glm::vec3 dir;
float distance = 0.0f;
int same_polys_flags = 0;
std::vector<dtPolyRef> spec_polys;
friend class Movement;
friend class MapInstance;
};