-
Notifications
You must be signed in to change notification settings - Fork 1
/
navmesh_types.h
184 lines (157 loc) · 6.34 KB
/
navmesh_types.h
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#ifndef PATHFINDER_NAVMESH_NAVMESH_TYPES_H_
#define PATHFINDER_NAVMESH_NAVMESH_TYPES_H_
#include "vector.h"
#include <optional>
#include <tuple>
#include <utility>
namespace pathfinder {
namespace navmesh {
template<typename IndexT>
class NavmeshTypes {
public:
using IndexType = IndexT;
using EdgeType = std::pair<Vector, Vector>;
using EdgeVertexIndicesType = std::pair<IndexType, IndexType>;
using TriangleVerticesType = std::tuple<Vector, Vector, Vector>;
using TriangleVertexIndicesType = std::tuple<IndexType, IndexType, IndexType>;
using TriangleEdgeIndicesType = std::tuple<IndexType, IndexType, IndexType>;
// // The indices of 3 neighbor triangles
using TriangleNeighborIndicesType = std::tuple<std::optional<IndexType>, std::optional<IndexType>, std::optional<IndexType>>;
struct NeighborAcrossEdgeIndices {
IndexType neighborTriangleIndex;
IndexType sharedEdgeIndex;
};
// // The indices of 3 neighboring triangles along with the index of the shared edge for each neighbor
using TriangleNeighborsAcrossEdgesIndicesType = std::tuple<std::optional<NeighborAcrossEdgeIndices>, std::optional<NeighborAcrossEdgeIndices>, std::optional<NeighborAcrossEdgeIndices>>;
};
/**
* Interface of a Navmesh
*
* A navmesh contains a set of triangles that represent a 2d plane. These
* triangles are made of vertices and edges. Vertex indices are [0, n)
* with no gaps in between. Edge indices are [0, n) with no gaps in between.
* Triangle indices are [0, n) with no gaps in between.
*
*/
// class NavmeshInterface {
// public:
// /**
// * Returns the number of vertices in the navmesh.
// *
// * @return The number of vertices in the navmesh
// */
// virtual std::size_t getVertexCount() const = 0;
// /**
// * Returns a vertex of a triangle.
// *
// * @param vertexIndex The vertex index
// * @return A point representing the vertex of some triangle
// */
// virtual const Vector& getVertex(const int vertexIndex) const = 0;
// /**
// * Returns the marker for a vertex. This indicates what type of constraint this is.
// *
// * @param vertexIndex The vertex index
// * @return The marker for the given vertex index
// */
// virtual unsigned int getVertexMarker(const int vertexIndex) const = 0;
// /**
// * Returns the number of edges in the navmesh.
// *
// * @return The number of edges in the navmesh
// */
// virtual std::size_t getEdgeCount() const = 0;
// /**
// * Returns an edge in the navmesh.
// *
// * @param edgeIndex The edge index
// * @return A pair of points defining the line segment that is the edge
// */
// virtual EdgeType getEdge(const int edgeIndex) const = 0;
// /**
// * Returns the indices of the vertices of an edge.
// *
// * @param edgeIndex The edge index
// * @return A pair of indices of the vertices that define the line segment that is the edge
// */
// virtual EdgeVertexIndicesType getEdgeVertexIndices(const int edgeIndex) const = 0;
// /**
// * Returns the marker for a edge. This indicates what type of constraint this is.
// *
// * @param edgeIndex The edge index
// * @return The marker for the given edge index
// */
// virtual unsigned int getEdgeMarker(const int edgeIndex) const = 0;
// /**
// * Returns the number of triangles in the navmesh.
// *
// * @return The number of triangles in the navmesh
// */
// virtual std::size_t getTriangleCount() const = 0;
// /**
// * Returns the indices of the vertices of a triangle.
// *
// * @param triangleIndex The triangle index
// * @return A tuple of indices of the vertices for the given triangle
// */
// virtual const TriangleVertexIndicesType& getTriangleVertexIndices(const int triangleIndex) const = 0;
// /**
// * Returns the vertices of a triangle.
// *
// * @param triangleIndex The triangle index
// * @return A tuple of vertices for the given triangle
// */
// virtual TriangleVerticesType getTriangleVertices(const int triangleIndex) const = 0;
// /**
// * Returns the indices of the edges of a triangle.
// *
// * @param triangleIndex The triangle index
// * @return A tuple of indices of the edges for the given triangle
// */
// virtual TriangleEdgeIndicesType getTriangleEdgeIndices(const int triangleIndex) const = 0;
// /**
// * Returns indices of the neighboring triangles for the given triangle along with the indices of the edge shared between the given triangle and the neighbor.
// *
// * @param triangleIndex The triangle index
// * @return The 3 neighboring triangle indices (-1 if no neighbor) and index of the shared edge between the given triangle and the neighbor (undefined if no neighbor, (TODO: Maybe a bad idea?)).
// */
// virtual const TriangleNeighborsAcrossEdgesIndicesType& getTriangleNeighborsWithSharedEdges(const int triangleIndex) const = 0;
// /**
// * Returns the shared edge between the two given triangles.
// *
// * Throws if invalid triangle given.
// * Throws if no edge exists between the two triangles.
// *
// * @param triangle1Index The triangle index
// * @param triangle2Index The triangle index
// * @return The edge between the the two given triangles
// */
// virtual EdgeType getSharedEdge(const int triangle1Index, const int triangle2Index) const = 0;
// /**
// * Returns the index of the vertex in the navmesh that matches the given vertex
// *
// * Note: Only exists for debugging. TODO: Remove
// *
// * @param vertex The vertex to search for
// * @return The index of the vertex if it exists, -1 otherwise
// */
// virtual int getVertexIndex(const Vector &vertex) const = 0;
// /**
// * Checks if a given point is inside of a triangle.
// *
// * @param point The point
// * @param triangleIndex The triangle index
// * @return `true` if the point is in the triangle, `false` otherwise.
// */
// virtual bool pointIsOnTriangle(const Vector &point, const int triangleIndex) const = 0;
// /**
// * Returns the index of the triangle that the given point is in
// *
// * @param point The point to find a triangle for
// * @return The index of the triangle if it exists, -1 otherwise
// */
// virtual int findTriangleForPoint(const Vector &point) const = 0;
// };
} // namespace navmesh
} // namespace pathfinder
#endif // PATHFINDER_NAVMESH_NAVMESH_TYPES_H_