Saga
Saga Game Engine
Loading...
Searching...
No Matches
navMesh.h
Go to the documentation of this file.
1#pragma once
2
4#include <glm/vec3.hpp>
5#include <vector>
6#include <optional>
7
8namespace Saga {
9 class NavMesh {
10 private:
11 struct Face; struct Edge; struct Vertex; struct HalfEdge;
12 struct HalfEdge {
13 HalfEdge *twin;
14 HalfEdge *nxt;
15 Vertex *vertex;
16 Edge *edge;
17 Face *face;
18 };
19 struct Vertex {
20 HalfEdge *firstEdge;
21 glm::vec3 pos;
22 int degree;
23 };
24 struct Edge {
25 HalfEdge *halfEdge;
26 float highestAdminissibleRadius;
27 glm::vec3 center;
28 };
29 struct Face {
30 HalfEdge *halfEdge;
31 };
32
33 public:
35 int cell;
37 };
38
39 struct Path {
40 float length;
41 glm::vec3 from;
42 glm::vec3 to;
43 std::vector<int> edges;
44 };
45
46 void build(const std::vector<glm::vec3> &position, const std::vector<glm::ivec3> &faces);
47 std::optional<Path> findPath(glm::vec3 from, glm::vec3 to);
48 std::optional<LocationInCell> getCell(glm::vec3 pos);
49 private:
50 bool initialized;
51
52 std::vector<Vertex> vertices;
53 std::vector<Face> faces;
54 std::vector<Edge> edges;
55 std::vector<HalfEdge> halfEdges;
56
57 Geometry::Triangle toTriangle(const Face& face);
58 };
59}
60
Definition: navMesh.h:9
void build(const std::vector< glm::vec3 > &position, const std::vector< glm::ivec3 > &faces)
Definition: navMesh.cpp:13
std::optional< LocationInCell > getCell(glm::vec3 pos)
Definition: navMesh.cpp:188
std::optional< Path > findPath(glm::vec3 from, glm::vec3 to)
Definition: navMesh.cpp:90
Definition: app.cpp:8
Represents a 3D triangle, equipped with some utility functions.
Definition: triangle.h:13
Definition: navMesh.h:34
glm::vec3 projectedPosition
Definition: navMesh.h:36
int cell
Definition: navMesh.h:35
Definition: navMesh.h:39
std::vector< int > edges
Definition: navMesh.h:43
float length
Definition: navMesh.h:40
glm::vec3 from
Definition: navMesh.h:41
glm::vec3 to
Definition: navMesh.h:42