now template

This commit is contained in:
Vladislav Alpatov
2025-03-01 21:11:46 +03:00
parent 9ba3bc754a
commit 6d0d267743
43 changed files with 224 additions and 256 deletions

View File

@@ -1,9 +1,6 @@
target_sources(omath PRIVATE
Vector3.cpp
Matrix.cpp
color.cpp
Vector4.cpp
Vector2.cpp
)
add_subdirectory(projectile_prediction)

View File

@@ -315,7 +315,7 @@ namespace omath
};
}
Matrix Matrix::TranslationMatrix(const Vector3& diff)
Matrix Matrix::TranslationMatrix(const Vector3<float>& diff)
{
return {
{1.f, 0.f, 0.f, 0.f},
@@ -325,7 +325,7 @@ namespace omath
};
}
Matrix Matrix::OrientationMatrix(const Vector3& forward, const Vector3& right, const Vector3& up)
Matrix Matrix::OrientationMatrix(const Vector3<float>& forward, const Vector3<float>& right, const Vector3<float>& up)
{
return {
{right.x, up.x, forward.x, 0.f},

View File

@@ -1,11 +0,0 @@
//
// Created by Vlad on 02.09.2024.
//
#include "omath/Vector2.hpp"
#include <cmath>
namespace omath
{
}

View File

@@ -1,23 +0,0 @@
//
// Created by vlad on 10/28/23.
//
#include <omath/Vector3.hpp>
#include <cmath>
#include <omath/Angles.hpp>
namespace omath
{
Vector3 Vector3::ViewAngleTo(const Vector3 &other) const
{
const float distance = DistTo(other);
const auto delta = other - *this;
return
{
angles::RadiansToDegrees(std::asin(delta.z / distance)),
angles::RadiansToDegrees(std::atan2(delta.y, delta.x)),
0.f
};
}
}

View File

@@ -1,16 +0,0 @@
//
// Vector4.cpp
//
#include "omath/Vector4.hpp"
#include <cmath>
namespace omath
{
float Vector4::Length() const
{
return std::sqrt(LengthSqr());
}
}

View File

@@ -5,21 +5,21 @@
namespace omath::collision
{
bool LineTracer::CanTraceLine(const Ray& ray, const Triangle<Vector3>& triangle)
bool LineTracer::CanTraceLine(const Ray& ray, const Triangle<Vector3<float>>& triangle)
{
return GetRayHitPoint(ray, triangle) == ray.end;
}
Vector3 Ray::DirectionVector() const
Vector3<float> Ray::DirectionVector() const
{
return end - start;
}
Vector3 Ray::DirectionVectorNormalized() const
Vector3<float> Ray::DirectionVectorNormalized() const
{
return DirectionVector().Normalized();
}
Vector3 LineTracer::GetRayHitPoint(const Ray& ray, const Triangle<Vector3>& triangle)
Vector3<float> LineTracer::GetRayHitPoint(const Ray& ray, const Triangle<Vector3<float>>& triangle)
{
constexpr float kEpsilon = std::numeric_limits<float>::epsilon();

View File

@@ -8,12 +8,12 @@
namespace omath::opengl
{
Camera::Camera(const Vector3& position, const ViewAngles& viewAngles, const projection::ViewPort& viewPort,
Camera::Camera(const Vector3<float>& position, const ViewAngles& viewAngles, const projection::ViewPort& viewPort,
const Angle<float, 0.f, 180.f, AngleFlags::Clamped>& fov, const float near, const float far) :
projection::Camera<Mat4x4, ViewAngles>(position, viewAngles, viewPort, fov, near, far)
{
}
void Camera::LookAt([[maybe_unused]] const Vector3& target)
void Camera::LookAt([[maybe_unused]] const Vector3<float>& target)
{
const float distance = m_origin.DistTo(target);
const auto delta = target - m_origin;

View File

@@ -8,12 +8,12 @@
namespace omath::source
{
Camera::Camera(const Vector3& position, const ViewAngles& viewAngles, const projection::ViewPort& viewPort,
Camera::Camera(const Vector3<float>& position, const ViewAngles& viewAngles, const projection::ViewPort& viewPort,
const projection::FieldOfView& fov, const float near, const float far) :
projection::Camera<Mat4x4, ViewAngles>(position, viewAngles, viewPort, fov, near, far)
{
}
void Camera::LookAt(const Vector3& target)
void Camera::LookAt(const Vector3<float>& target)
{
const float distance = m_origin.DistTo(target);
const auto delta = target - m_origin;

View File

@@ -13,15 +13,15 @@ namespace omath::pathfinding
{
struct PathNode final
{
std::optional<Vector3> cameFrom;
std::optional<Vector3<float>> cameFrom;
float gCost = 0.f;
};
std::vector<Vector3> Astar::ReconstructFinalPath(const std::unordered_map<Vector3, PathNode>& closedList,
const Vector3& current)
std::vector<Vector3<float>> Astar::ReconstructFinalPath(const std::unordered_map<Vector3<float>, PathNode>& closedList,
const Vector3<float>& current)
{
std::vector<Vector3> path;
std::vector<Vector3<float>> path;
std::optional currentOpt = current;
while (currentOpt)
@@ -39,7 +39,7 @@ namespace omath::pathfinding
std::ranges::reverse(path);
return path;
}
auto Astar::GetPerfectNode(const std::unordered_map<Vector3, PathNode>& openList, const Vector3& endVertex)
auto Astar::GetPerfectNode(const std::unordered_map<Vector3<float>, PathNode>& openList, const Vector3<float>& endVertex)
{
return std::ranges::min_element(openList,
[&endVertex](const auto& a, const auto& b)
@@ -50,10 +50,10 @@ namespace omath::pathfinding
});
}
std::vector<Vector3> Astar::FindPath(const Vector3& start, const Vector3& end, const NavigationMesh& navMesh)
std::vector<Vector3<float>> Astar::FindPath(const Vector3<float>& start, const Vector3<float>& end, const NavigationMesh& navMesh)
{
std::unordered_map<Vector3, PathNode> closedList;
std::unordered_map<Vector3, PathNode> openList;
std::unordered_map<Vector3<float>, PathNode> closedList;
std::unordered_map<Vector3<float>, PathNode> openList;
auto maybeStartVertex = navMesh.GetClosestVertex(start);
auto maybeEndVertex = navMesh.GetClosestVertex(end);

View File

@@ -7,7 +7,7 @@
#include <algorithm>
namespace omath::pathfinding
{
std::expected<Vector3, std::string> NavigationMesh::GetClosestVertex(const Vector3 &point) const
std::expected<Vector3<float>, std::string> NavigationMesh::GetClosestVertex(const Vector3<float> &point) const
{
const auto res = std::ranges::min_element(m_verTextMap,
[&point](const auto& a, const auto& b)
@@ -21,7 +21,7 @@ namespace omath::pathfinding
return res->first;
}
const std::vector<Vector3>& NavigationMesh::GetNeighbors(const Vector3 &vertex) const
const std::vector<Vector3<float>>& NavigationMesh::GetNeighbors(const Vector3<float> &vertex) const
{
return m_verTextMap.at(vertex);
}
@@ -73,18 +73,18 @@ namespace omath::pathfinding
while (offset < raw.size())
{
Vector3 vertex;
Vector3<float> vertex;
loadFromVector(raw, offset, vertex);
uint16_t neighborsCount;
loadFromVector(raw, offset, neighborsCount);
std::vector<Vector3> neighbors;
std::vector<Vector3<float>> neighbors;
neighbors.reserve(neighborsCount);
for (size_t i = 0; i < neighborsCount; ++i)
{
Vector3 neighbor;
Vector3<float> neighbor;
loadFromVector(raw, offset, neighbor);
neighbors.push_back(neighbor);
}

View File

@@ -6,7 +6,7 @@
namespace omath::projectile_prediction
{
std::optional<Vector3> ProjPredEngineAVX2::MaybeCalculateAimPoint(const Projectile& projectile,
std::optional<Vector3<float>> ProjPredEngineAVX2::MaybeCalculateAimPoint(const Projectile& projectile,
const Target& target) const
{
const float bulletGravity = m_gravityConstant * projectile.m_gravityScale;
@@ -110,7 +110,7 @@ namespace omath::projectile_prediction
m_maximumSimulationTime(simulationTimeStep)
{
}
std::optional<float> ProjPredEngineAVX2::CalculatePitch(const Vector3& projOrigin, const Vector3& targetPos,
std::optional<float> ProjPredEngineAVX2::CalculatePitch(const Vector3<float>& projOrigin, const Vector3<float>& targetPos,
const float bulletGravity, const float v0, const float time)
{
if (time <= 0.0f)

View File

@@ -11,7 +11,7 @@ namespace omath::projectile_prediction
{
}
std::optional<Vector3> ProjPredEngineLegacy::MaybeCalculateAimPoint(const Projectile& projectile,
std::optional<Vector3<float>> ProjPredEngineLegacy::MaybeCalculateAimPoint(const Projectile& projectile,
const Target& target) const
{
for (float time = 0.f; time < m_maximumSimulationTime; time += m_simulationTimeStep)
@@ -36,7 +36,7 @@ namespace omath::projectile_prediction
std::optional<float>
ProjPredEngineLegacy::MaybeCalculateProjectileLaunchPitchAngle(const Projectile& projectile,
const Vector3& targetPosition) const
const Vector3<float>& targetPosition) const
{
const auto bulletGravity = m_gravityConstant * projectile.m_gravityScale;
const auto delta = targetPosition - projectile.m_origin;
@@ -57,7 +57,7 @@ namespace omath::projectile_prediction
return angles::RadiansToDegrees(angle);
}
bool ProjPredEngineLegacy::IsProjectileReachedTarget(const Vector3& targetPosition, const Projectile& projectile,
bool ProjPredEngineLegacy::IsProjectileReachedTarget(const Vector3<float>& targetPosition, const Projectile& projectile,
const float pitch, const float time) const
{
const auto yaw = projectile.m_origin.ViewAngleTo(targetPosition).y;

View File

@@ -8,7 +8,7 @@
namespace omath::projectile_prediction
{
Vector3 Projectile::PredictPosition(const float pitch, const float yaw, const float time, const float gravity) const
Vector3<float> Projectile::PredictPosition(const float pitch, const float yaw, const float time, const float gravity) const
{
auto currentPos = m_origin + source::ForwardVector({source::PitchAngle::FromDegrees(-pitch),
source::YawAngle::FromDegrees(yaw),