diff --git a/include/omath/Vector3.h b/include/omath/Vector3.h index 88d5d56..1bb8807 100644 --- a/include/omath/Vector3.h +++ b/include/omath/Vector3.h @@ -4,6 +4,9 @@ #pragma once +#include +#include + namespace omath { class Vector3 { @@ -73,3 +76,22 @@ namespace omath Vector3 Normalized() const; }; } +// ReSharper disable once CppRedundantNamespaceDefinition +namespace std +{ + template<> + struct hash + { + std::size_t operator()(const omath::Vector3& vec) const noexcept + { + std::size_t hash = 0; + constexpr std::hash hasher; + + hash ^= hasher(vec.x) + 0x9e3779b9 + (hash<<6) + (hash>>2); + hash ^= hasher(vec.y) + 0x9e3779b9 + (hash<<6) + (hash>>2); + hash ^= hasher(vec.z) + 0x9e3779b9 + (hash<<6) + (hash>>2); + + return hash; + } + }; +} diff --git a/include/omath/pathfinding/Astar.h b/include/omath/pathfinding/Astar.h new file mode 100644 index 0000000..0525679 --- /dev/null +++ b/include/omath/pathfinding/Astar.h @@ -0,0 +1,20 @@ +// +// Created by Vlad on 28.07.2024. +// + +#pragma once +#include +#include "NavigationMesh.h" +#include "omath/Vector3.h" + + +namespace omath::pathfinding +{ + class Astar + { + public: + [[nodiscard]] + static std::vector FindPath(const Vector3& start, const Vector3& end, const NavigationMesh& navMesh); + + }; +} \ No newline at end of file diff --git a/include/omath/pathfinding/NavigationMesh.h b/include/omath/pathfinding/NavigationMesh.h new file mode 100644 index 0000000..1af4b06 --- /dev/null +++ b/include/omath/pathfinding/NavigationMesh.h @@ -0,0 +1,33 @@ +// +// Created by Vlad on 28.07.2024. +// + +#pragma once + +#include "omath/Vector3.h" +#include +#include +#include + + +namespace omath::pathfinding +{ + struct NavigationVertex + { + Vector3 origin; + std::vector connections; + }; + + + class NavigationMesh final + { + public: + + [[nodiscard]] + std::expected GetClossestVertex(const Vector3& point) const; + + private: + + + }; +} \ No newline at end of file diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index 26a3d6a..499567c 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -4,4 +4,5 @@ target_sources(omath PRIVATE color.cpp Vector4.cpp) -add_subdirectory(prediction) \ No newline at end of file +add_subdirectory(prediction) +add_subdirectory(pathfinding) \ No newline at end of file diff --git a/source/pathfinding/Astar.cpp b/source/pathfinding/Astar.cpp new file mode 100644 index 0000000..f211de7 --- /dev/null +++ b/source/pathfinding/Astar.cpp @@ -0,0 +1,36 @@ +// +// Created by Vlad on 28.07.2024. +// +#include "omath/pathfinding/Astar.h" +#include + + + +namespace omath::pathfinding +{ + struct PathNode final + { + PathNode* cameFrom; + const NavigationVertex* navVertex; + float gCost = 0.f; + }; + + + std::vector Astar::FindPath(const Vector3 &start, const Vector3 &end, const NavigationMesh &navMesh) + { + std::unordered_map closedList; + std::unordered_map openList; + + const auto& startVertex = navMesh.GetClossestVertex(start).value(); + const auto& endVertex = navMesh.GetClossestVertex(end).value(); + + openList.emplace(startVertex.origin, PathNode{nullptr, &startVertex, 0.f}); + + while (!openList.empty()) + { + + } + + return {}; + } +} diff --git a/source/pathfinding/CMakeLists.txt b/source/pathfinding/CMakeLists.txt new file mode 100644 index 0000000..d1da67f --- /dev/null +++ b/source/pathfinding/CMakeLists.txt @@ -0,0 +1 @@ +target_sources(omath PRIVATE NavigationMesh.cpp Astar.cpp) \ No newline at end of file diff --git a/source/pathfinding/NavigationMesh.cpp b/source/pathfinding/NavigationMesh.cpp new file mode 100644 index 0000000..5ff1b3f --- /dev/null +++ b/source/pathfinding/NavigationMesh.cpp @@ -0,0 +1,4 @@ +// +// Created by Vlad on 28.07.2024. +// +#include "omath/pathfinding/NavigationMesh.h" \ No newline at end of file