Skylicht Engine
Loading...
Searching...
No Matches
CGraphQuery.h
1/*
2!@
3MIT License
4
5Copyright (c) 2024 Skylicht Technology CO., LTD
6
7Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
8(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
9merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
10subject to the following conditions:
11
12The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
20This file is part of the "Skylicht Engine".
21https://github.com/skylicht-lab/skylicht-engine
22!#
23*/
24
25#pragma once
26
27#include "RenderMesh/CRenderMeshData.h"
28#include "ObstacleAvoidance/CObstacleAvoidance.h"
29#include "WalkingMap/CWalkingTileMap.h"
30
31namespace Skylicht
32{
33 namespace Graph
34 {
35 class COctreeNode
36 {
37 public:
39 core::aabbox3df OctreeBox;
40
41 int Level;
42
43 COctreeNode* Parent;
44 COctreeNode* Childs[8];
45
47 CObstacleAvoidance Obstacle;
48
49 COctreeNode();
50
51 virtual ~COctreeNode();
52 };
53
55 {
56 float Distance;
57 STile* Tile;
58 };
59
60 class CDistancePriorityQueue
61 {
62 protected:
64
65 public:
66 CDistancePriorityQueue();
67
68 virtual ~CDistancePriorityQueue();
69
70 void push(const SDistanceTile& d);
71
72 void pop();
73
74 inline bool empty()
75 {
76 return m_queue.empty();
77 }
78
79 const SDistanceTile& top();
80 };
81
82 class CGraphQuery
83 {
84 protected:
85 COctreeNode* m_root;
86
87 u32 m_minimalPolysPerNode;
88
89 public:
90 CGraphQuery();
91
92 virtual ~CGraphQuery();
93
94 void release();
95
96 void buildIndexNavMesh(CMesh* navMesh, CObstacleAvoidance* obstacle);
97
98 inline COctreeNode* getRootNode()
99 {
100 return m_root;
101 }
102
103 bool getCollisionPoint(
104 const core::line3d<f32>& ray,
105 f32& outBestDistanceSquared,
106 core::vector3df& outIntersection,
107 core::triangle3df& outTriangle);
108
109 void getTriangles(const core::aabbox3df& box, core::array<core::triangle3df*>& result);
110
111 void getObstacles(const core::aabbox3df& box, CObstacleAvoidance& obstacle);
112
113 bool findPath(CWalkingTileMap* map, STile* from, STile* to, core::array<STile*>& result);
114
115 protected:
116
117 void constructOctree(COctreeNode* node);
118
119 void getTrianglesFromOctree(
121 COctreeNode* node,
122 const core::vector3df& midLine,
123 const core::vector3df& lineVect,
124 float halfLength);
125
126 void getTrianglesFromOctree(
128 COctreeNode* node,
129 const core::aabbox3df& box);
130
131 void getObstacleFromOctree(
132 CObstacleAvoidance& obstacle,
133 COctreeNode* node,
134 const core::aabbox3df& box);
135 };
136 }
137}
Definition CMesh.h:75
Definition CObstacleAvoidance.h:38
Definition CGraphQuery.h:36
Definition CWalkingTileMap.h:106
Self reallocating template array (like stl vector) with additional features.
Definition irrArray.h:23
3D line between two points with intersection methods.
Definition line3d.h:19
Component that manages the navigation lifecycle, including NavMesh generation and pathfinding.
Definition CGraphComponent.h:41
Everything in the Skylicht Engine. You can start by looking at the topics.
Definition AudioDebugLog.h:29
vector3d< f32 > vector3df
Typedef for a f32 3d vector.
Definition vector3d.h:445
triangle3d< f32 > triangle3df
Typedef for a f32 3d triangle.
Definition triangle3d.h:335
aabbox3d< f32 > aabbox3df
Typedef for a f32 3d bounding box.
Definition aabbox3d.h:351
float f32
32 bit floating point variable.
Definition irrTypes.h:104
unsigned int u32
32 bit unsigned variable.
Definition irrTypes.h:58
Definition CGraphQuery.h:55
Definition CWalkingTileMap.h:36