added finding path with A* and json file to know where character can walk
This commit is contained in:
1 parent
eff7322140
commit
4eaefd25d4
11 files changed
+905
-11
No files matched your search
@@ -0,0 +1,76 @@
|
||||
#pragma once
|
||||
|
||||
#include "render/Renderer.h"
|
||||
#include <Eigen/Core>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace ZL {
|
||||
|
||||
class PathFinder {
|
||||
public:
|
||||
struct ObstacleMesh {
|
||||
const VertexDataStruct* mesh = nullptr;
|
||||
Eigen::Vector3f offset = Eigen::Vector3f::Zero();
|
||||
};
|
||||
|
||||
struct Cell {
|
||||
int x = 0;
|
||||
int z = 0;
|
||||
};
|
||||
|
||||
void build(const std::vector<ObstacleMesh>& obstacleMeshes,
|
||||
const std::string& configPath,
|
||||
const std::string& zipPath = "");
|
||||
|
||||
std::vector<Eigen::Vector3f> findPath(const Eigen::Vector3f& start,
|
||||
const Eigen::Vector3f& end) const;
|
||||
|
||||
bool setAreaAvailable(const std::string& areaName, bool available);
|
||||
bool isReady() const { return ready; }
|
||||
bool isWalkable(const Eigen::Vector3f& point) const;
|
||||
|
||||
private:
|
||||
struct NavigationArea {
|
||||
std::string name;
|
||||
bool available = true;
|
||||
std::vector<Eigen::Vector2f> polygon;
|
||||
};
|
||||
|
||||
float cellSize = 0.4f;
|
||||
float agentRadius = 0.45f;
|
||||
float floorY = 0.0f;
|
||||
float objectPadding = 0.25f;
|
||||
|
||||
float minX = 0.0f;
|
||||
float minZ = 0.0f;
|
||||
int gridWidth = 0;
|
||||
int gridDepth = 0;
|
||||
bool ready = false;
|
||||
|
||||
std::string loadedConfigPath;
|
||||
std::string loadedZipPath;
|
||||
std::vector<ObstacleMesh> obstacles;
|
||||
std::vector<unsigned char> walkable;
|
||||
std::vector<NavigationArea> areas;
|
||||
|
||||
void loadConfig(const std::string& configPath, const std::string& zipPath);
|
||||
void resetGridBounds();
|
||||
void rebuildWalkableGrid();
|
||||
void markAvailableAreasWalkable();
|
||||
void markObstacleMeshesBlocked();
|
||||
|
||||
bool worldToCell(const Eigen::Vector3f& point, Cell& out) const;
|
||||
Eigen::Vector3f cellCenter(const Cell& cell) const;
|
||||
bool isInsideGrid(const Cell& cell) const;
|
||||
bool isCellWalkable(const Cell& cell) const;
|
||||
int indexOf(const Cell& cell) const;
|
||||
|
||||
bool findNearestWalkableCell(const Eigen::Vector3f& point, Cell& out) const;
|
||||
bool hasLineOfSight(const Cell& from, const Cell& to) const;
|
||||
std::vector<Cell> smoothCells(const std::vector<Cell>& cells) const;
|
||||
|
||||
static bool pointInPolygon(float x, float z, const std::vector<Eigen::Vector2f>& polygon);
|
||||
};
|
||||
|
||||
} // namespace ZL
|
||||
Reference in new issue
Block a user