-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNavmesh.h
More file actions
91 lines (73 loc) · 2.04 KB
/
Navmesh.h
File metadata and controls
91 lines (73 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#pragma once
#include "NavNode.h"
#include "NavGrid.h"
namespace KE
{
class Graphics;
class KittyMesh;
struct Mesh;
struct NodesAttachedToIndex
{
NodesAttachedToIndex(int aIndex) { index = aIndex; };
NodesAttachedToIndex(int aIndex, Vector3f aVertex, NavNode& aNode)
{
index = aIndex; vertex = aVertex; nodes.push_back(&aNode);
};
int index = INT_MIN;
Vector3f vertex = { FLT_MIN, FLT_MIN, FLT_MIN };
std::vector<NavNode*> nodes = {};
};
struct SharedLine
{
SharedLine(int v0, int v1) : indices({ v0, v1 }) {};
bool IsShared(int aV0, int aV1)
{
if ((indices[0] == aV0 && indices[1] == aV1) ||
(indices[1] == aV0 && indices[0] == aV1))
{
isShared = true;
}
return isShared;
}
std::array<int, 2> indices;
bool isShared = false;
};
struct EdgeLine
{
EdgeLine() {};
EdgeLine(Vector3f aV0, Vector3f aV1) : v0(aV0), v1(aV1) {};
Vector3f v0;
Vector3f v1;
};
class Navmesh
{
friend class CollisionHandler;
friend class Pathfinder;
KE_EDITOR_FRIEND
public:
Navmesh() = default;
~Navmesh() {}
bool Init(Graphics* aGraphics, std::string& aObjFilepath);
void DebugRender(Graphics* aGraphics);
void LoadKittyMesh(KE::KittyMesh& aFile);
void SaveKittyMesh(KE::KittyMesh& aFile);
void ClearNavmesh();
inline std::vector<NavNode*> GetNodesFromPos(Vector3f aPos);
private:
void CreateNodes(const Mesh& aMesh);
void CreateNodes(const KE::KittyMesh& aMesh, Vector3f& aMin, Vector3f& aMax);
void AttachNodes(NavNode* aNode);
void GenerateLineColliders(NavNode* aNode);
bool GotIndices(std::array<unsigned int, 2> aLine, NavNode& aNode);
std::vector<NavNode> myNodes;
std::vector<Vector3f> myVertices = {};
std::vector<unsigned int> myIndices = {};
std::unordered_map<int, NodesAttachedToIndex> myIndiceNodeMap;
std::vector<EdgeLine> myEdges;
NavGrid myNavGrid;
};
inline std::vector<NavNode*> Navmesh::GetNodesFromPos(Vector3f aPos)
{
return myNavGrid.GetNodesByPos(aPos);
}
}