mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 07:03:25 +00:00
removed usless code added constexpr
This commit is contained in:
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
namespace omath::pathfinding
|
namespace omath::pathfinding
|
||||||
{
|
{
|
||||||
class Astar
|
class Astar final
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
|
|||||||
@@ -12,19 +12,12 @@
|
|||||||
|
|
||||||
namespace omath::pathfinding
|
namespace omath::pathfinding
|
||||||
{
|
{
|
||||||
struct NavigationVertex
|
|
||||||
{
|
|
||||||
Vector3 origin;
|
|
||||||
std::vector<NavigationVertex*> connections;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class NavigationMesh final
|
class NavigationMesh final
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
std::expected<Vector3, std::string> GetClossestVertex(const Vector3& point) const;
|
std::expected<Vector3, std::string> GetClosestVertex(const Vector3& point) const;
|
||||||
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
|
|||||||
@@ -13,7 +13,15 @@ namespace omath::prediction
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Vector3 PredictPosition(float time, float gravity) const;
|
constexpr Vector3 PredictPosition(float time, float gravity) const
|
||||||
|
{
|
||||||
|
auto predicted = m_origin + m_velocity * time;
|
||||||
|
|
||||||
|
if (m_isAirborne)
|
||||||
|
predicted.z -= gravity * std::pow(time, 2.f) * 0.5f;
|
||||||
|
|
||||||
|
return predicted;
|
||||||
|
}
|
||||||
|
|
||||||
Vector3 m_origin;
|
Vector3 m_origin;
|
||||||
Vector3 m_velocity;
|
Vector3 m_velocity;
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ namespace omath::pathfinding
|
|||||||
std::unordered_map<Vector3, PathNode> closedList;
|
std::unordered_map<Vector3, PathNode> closedList;
|
||||||
std::unordered_map<Vector3, PathNode> openList;
|
std::unordered_map<Vector3, PathNode> openList;
|
||||||
|
|
||||||
const auto startVertex = navMesh.GetClossestVertex(start).value();
|
const auto startVertex = navMesh.GetClosestVertex(start).value();
|
||||||
const auto endVertex = navMesh.GetClossestVertex(end).value();
|
const auto endVertex = navMesh.GetClosestVertex(end).value();
|
||||||
|
|
||||||
openList.emplace(startVertex, PathNode{std::nullopt, 0.f});
|
openList.emplace(startVertex, PathNode{std::nullopt, 0.f});
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
namespace omath::pathfinding
|
namespace omath::pathfinding
|
||||||
{
|
{
|
||||||
std::expected<Vector3, std::string> NavigationMesh::GetClossestVertex(const Vector3 &point) const
|
std::expected<Vector3, std::string> NavigationMesh::GetClosestVertex(const Vector3 &point) const
|
||||||
{
|
{
|
||||||
const auto res = std::ranges::min_element(m_verTextMap,
|
const auto res = std::ranges::min_element(m_verTextMap,
|
||||||
[&point](const auto& a, const auto& b)
|
[&point](const auto& a, const auto& b)
|
||||||
|
|||||||
@@ -3,18 +3,9 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include "omath/prediction/Target.h"
|
#include "omath/prediction/Target.h"
|
||||||
#include <cmath>
|
|
||||||
|
|
||||||
|
|
||||||
namespace omath::prediction
|
namespace omath::prediction
|
||||||
{
|
{
|
||||||
Vector3 Target::PredictPosition(const float time, const float gravity) const
|
|
||||||
{
|
|
||||||
auto predicted = m_origin + m_velocity * time;
|
|
||||||
|
|
||||||
if (m_isAirborne)
|
|
||||||
predicted.z -= gravity * std::pow(time, 2.f) * 0.5f;
|
|
||||||
|
|
||||||
return predicted;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user