diff --git a/.idea/editor.xml b/.idea/editor.xml
index bce786e..9b5acf8 100644
--- a/.idea/editor.xml
+++ b/.idea/editor.xml
@@ -103,7 +103,7 @@
-
+
@@ -202,7 +202,7 @@
-
+
@@ -216,7 +216,7 @@
-
+
diff --git a/benchmark/benchmark_projectile_pred.cpp b/benchmark/benchmark_projectile_pred.cpp
index a633754..208a6c8 100644
--- a/benchmark/benchmark_projectile_pred.cpp
+++ b/benchmark/benchmark_projectile_pred.cpp
@@ -12,11 +12,11 @@ constexpr float hit_distance_tolerance = 5.f;
void source_engine_projectile_prediction(benchmark::State& state)
{
- constexpr Target target{.m_origin = {100, 0, 90}, .m_velocity = {0, 0, 0}, .m_is_airborne = false};
- constexpr Projectile projectile = {.m_origin = {3, 2, 1}, .m_launch_speed = 5000, .m_gravity_scale = 0.4};
+ constexpr Target target{.m_origin = {100, 0, 90}, .m_velocity = {0, 0, 0}, .m_is_airborne = false};
+ constexpr Projectile projectile = {.m_origin = {3, 2, 1}, .m_launch_speed = 5000.f, .m_gravity_scale = 0.4f};
for ([[maybe_unused]] const auto _: state)
- std::ignore = ProjPredEngineLegacy(400, simulation_time_step, 50, hit_distance_tolerance)
+ std::ignore = ProjPredEngineLegacy<>(400.f, simulation_time_step, 50.f, hit_distance_tolerance)
.maybe_calculate_aim_point(projectile, target);
}
diff --git a/include/omath/engines/cry_engine/traits/pred_engine_trait.hpp b/include/omath/engines/cry_engine/traits/pred_engine_trait.hpp
index fc28b53..13f58c6 100644
--- a/include/omath/engines/cry_engine/traits/pred_engine_trait.hpp
+++ b/include/omath/engines/cry_engine/traits/pred_engine_trait.hpp
@@ -12,7 +12,7 @@ namespace omath::cry_engine
class PredEngineTrait final
{
public:
- constexpr static Vector3 predict_projectile_position(const projectile_prediction::Projectile& projectile,
+ constexpr static Vector3 predict_projectile_position(const projectile_prediction::Projectile& projectile,
const float pitch, const float yaw,
const float time, const float gravity) noexcept
{
@@ -26,7 +26,7 @@ namespace omath::cry_engine
return current_pos;
}
[[nodiscard]]
- static constexpr Vector3 predict_target_position(const projectile_prediction::Target& target,
+ static constexpr Vector3 predict_target_position(const projectile_prediction::Target& target,
const float time, const float gravity) noexcept
{
auto predicted = target.m_origin + target.m_velocity * time;
@@ -49,7 +49,7 @@ namespace omath::cry_engine
}
[[nodiscard]]
- static Vector3 calc_viewpoint_from_angles(const projectile_prediction::Projectile& projectile,
+ static Vector3 calc_viewpoint_from_angles(const projectile_prediction::Projectile& projectile,
Vector3 predicted_target_position,
const std::optional projectile_pitch) noexcept
{
diff --git a/include/omath/engines/frostbite_engine/traits/pred_engine_trait.hpp b/include/omath/engines/frostbite_engine/traits/pred_engine_trait.hpp
index 0a5ad75..4e6197c 100644
--- a/include/omath/engines/frostbite_engine/traits/pred_engine_trait.hpp
+++ b/include/omath/engines/frostbite_engine/traits/pred_engine_trait.hpp
@@ -12,7 +12,7 @@ namespace omath::frostbite_engine
class PredEngineTrait final
{
public:
- constexpr static Vector3 predict_projectile_position(const projectile_prediction::Projectile& projectile,
+ constexpr static Vector3 predict_projectile_position(const projectile_prediction::Projectile& projectile,
const float pitch, const float yaw,
const float time, const float gravity) noexcept
{
@@ -26,7 +26,7 @@ namespace omath::frostbite_engine
return current_pos;
}
[[nodiscard]]
- static constexpr Vector3 predict_target_position(const projectile_prediction::Target& target,
+ static constexpr Vector3 predict_target_position(const projectile_prediction::Target& target,
const float time, const float gravity) noexcept
{
auto predicted = target.m_origin + target.m_velocity * time;
@@ -49,7 +49,7 @@ namespace omath::frostbite_engine
}
[[nodiscard]]
- static Vector3 calc_viewpoint_from_angles(const projectile_prediction::Projectile& projectile,
+ static Vector3 calc_viewpoint_from_angles(const projectile_prediction::Projectile& projectile,
Vector3 predicted_target_position,
const std::optional projectile_pitch) noexcept
{
diff --git a/include/omath/engines/iw_engine/traits/pred_engine_trait.hpp b/include/omath/engines/iw_engine/traits/pred_engine_trait.hpp
index 728fd75..5b441b9 100644
--- a/include/omath/engines/iw_engine/traits/pred_engine_trait.hpp
+++ b/include/omath/engines/iw_engine/traits/pred_engine_trait.hpp
@@ -13,7 +13,7 @@ namespace omath::iw_engine
class PredEngineTrait final
{
public:
- constexpr static Vector3 predict_projectile_position(const projectile_prediction::Projectile& projectile,
+ constexpr static Vector3 predict_projectile_position(const projectile_prediction::Projectile& projectile,
const float pitch, const float yaw,
const float time, const float gravity) noexcept
{
@@ -27,7 +27,7 @@ namespace omath::iw_engine
return current_pos;
}
[[nodiscard]]
- static constexpr Vector3 predict_target_position(const projectile_prediction::Target& target,
+ static constexpr Vector3 predict_target_position(const projectile_prediction::Target& target,
const float time, const float gravity) noexcept
{
auto predicted = target.m_origin + target.m_velocity * time;
@@ -50,7 +50,7 @@ namespace omath::iw_engine
}
[[nodiscard]]
- static Vector3 calc_viewpoint_from_angles(const projectile_prediction::Projectile& projectile,
+ static Vector3 calc_viewpoint_from_angles(const projectile_prediction::Projectile& projectile,
Vector3 predicted_target_position,
const std::optional projectile_pitch) noexcept
{
diff --git a/include/omath/engines/opengl_engine/traits/pred_engine_trait.hpp b/include/omath/engines/opengl_engine/traits/pred_engine_trait.hpp
index 83e758c..f9f463f 100644
--- a/include/omath/engines/opengl_engine/traits/pred_engine_trait.hpp
+++ b/include/omath/engines/opengl_engine/traits/pred_engine_trait.hpp
@@ -12,7 +12,7 @@ namespace omath::opengl_engine
class PredEngineTrait final
{
public:
- constexpr static Vector3 predict_projectile_position(const projectile_prediction::Projectile& projectile,
+ constexpr static Vector3 predict_projectile_position(const projectile_prediction::Projectile& projectile,
const float pitch, const float yaw,
const float time, const float gravity) noexcept
{
@@ -26,7 +26,7 @@ namespace omath::opengl_engine
return current_pos;
}
[[nodiscard]]
- static constexpr Vector3 predict_target_position(const projectile_prediction::Target& target,
+ static constexpr Vector3 predict_target_position(const projectile_prediction::Target& target,
const float time, const float gravity) noexcept
{
auto predicted = target.m_origin + target.m_velocity * time;
@@ -49,7 +49,7 @@ namespace omath::opengl_engine
}
[[nodiscard]]
- static Vector3 calc_viewpoint_from_angles(const projectile_prediction::Projectile& projectile,
+ static Vector3 calc_viewpoint_from_angles(const projectile_prediction::Projectile& projectile,
Vector3 predicted_target_position,
const std::optional projectile_pitch) noexcept
{
diff --git a/include/omath/engines/source_engine/traits/pred_engine_trait.hpp b/include/omath/engines/source_engine/traits/pred_engine_trait.hpp
index 7f8cc8e..ef4144c 100644
--- a/include/omath/engines/source_engine/traits/pred_engine_trait.hpp
+++ b/include/omath/engines/source_engine/traits/pred_engine_trait.hpp
@@ -13,7 +13,7 @@ namespace omath::source_engine
class PredEngineTrait final
{
public:
- constexpr static Vector3 predict_projectile_position(const projectile_prediction::Projectile& projectile,
+ constexpr static Vector3 predict_projectile_position(const projectile_prediction::Projectile& projectile,
const float pitch, const float yaw,
const float time, const float gravity) noexcept
{
@@ -27,7 +27,7 @@ namespace omath::source_engine
return current_pos;
}
[[nodiscard]]
- static constexpr Vector3 predict_target_position(const projectile_prediction::Target& target,
+ static constexpr Vector3 predict_target_position(const projectile_prediction::Target& target,
const float time, const float gravity) noexcept
{
auto predicted = target.m_origin + target.m_velocity * time;
@@ -50,7 +50,7 @@ namespace omath::source_engine
}
[[nodiscard]]
- static Vector3 calc_viewpoint_from_angles(const projectile_prediction::Projectile& projectile,
+ static Vector3 calc_viewpoint_from_angles(const projectile_prediction::Projectile& projectile,
Vector3 predicted_target_position,
const std::optional projectile_pitch) noexcept
{
diff --git a/include/omath/engines/unity_engine/traits/pred_engine_trait.hpp b/include/omath/engines/unity_engine/traits/pred_engine_trait.hpp
index 52044b8..8c71141 100644
--- a/include/omath/engines/unity_engine/traits/pred_engine_trait.hpp
+++ b/include/omath/engines/unity_engine/traits/pred_engine_trait.hpp
@@ -12,7 +12,7 @@ namespace omath::unity_engine
class PredEngineTrait final
{
public:
- constexpr static Vector3 predict_projectile_position(const projectile_prediction::Projectile& projectile,
+ constexpr static Vector3 predict_projectile_position(const projectile_prediction::Projectile& projectile,
const float pitch, const float yaw,
const float time, const float gravity) noexcept
{
@@ -26,7 +26,7 @@ namespace omath::unity_engine
return current_pos;
}
[[nodiscard]]
- static constexpr Vector3 predict_target_position(const projectile_prediction::Target& target,
+ static constexpr Vector3 predict_target_position(const projectile_prediction::Target& target,
const float time, const float gravity) noexcept
{
auto predicted = target.m_origin + target.m_velocity * time;
@@ -49,7 +49,7 @@ namespace omath::unity_engine
}
[[nodiscard]]
- static Vector3 calc_viewpoint_from_angles(const projectile_prediction::Projectile& projectile,
+ static Vector3 calc_viewpoint_from_angles(const projectile_prediction::Projectile& projectile,
Vector3 predicted_target_position,
const std::optional projectile_pitch) noexcept
{
diff --git a/include/omath/engines/unreal_engine/camera.hpp b/include/omath/engines/unreal_engine/camera.hpp
index 1f62c3c..b3032a4 100644
--- a/include/omath/engines/unreal_engine/camera.hpp
+++ b/include/omath/engines/unreal_engine/camera.hpp
@@ -9,5 +9,5 @@
namespace omath::unreal_engine
{
- using Camera = projection::Camera;
+ using Camera = projection::Camera;
} // namespace omath::unreal_engine
\ No newline at end of file
diff --git a/include/omath/engines/unreal_engine/constants.hpp b/include/omath/engines/unreal_engine/constants.hpp
index 98ecf04..9b3bb21 100644
--- a/include/omath/engines/unreal_engine/constants.hpp
+++ b/include/omath/engines/unreal_engine/constants.hpp
@@ -11,16 +11,16 @@
namespace omath::unreal_engine
{
- constexpr Vector3 k_abs_up = {0, 0, 1};
- constexpr Vector3 k_abs_right = {0, 1, 0};
- constexpr Vector3 k_abs_forward = {1, 0, 0};
+ constexpr Vector3 k_abs_up = {0, 0, 1};
+ constexpr Vector3 k_abs_right = {0, 1, 0};
+ constexpr Vector3 k_abs_forward = {1, 0, 0};
- using Mat4X4 = Mat<4, 4, float, MatStoreType::ROW_MAJOR>;
- using Mat3X3 = Mat<4, 4, float, MatStoreType::ROW_MAJOR>;
- using Mat1X3 = Mat<1, 3, float, MatStoreType::ROW_MAJOR>;
- using PitchAngle = Angle;
- using YawAngle = Angle;
- using RollAngle = Angle;
+ using Mat4X4 = Mat<4, 4, double, MatStoreType::ROW_MAJOR>;
+ using Mat3X3 = Mat<4, 4, double, MatStoreType::ROW_MAJOR>;
+ using Mat1X3 = Mat<1, 3, double, MatStoreType::ROW_MAJOR>;
+ using PitchAngle = Angle;
+ using YawAngle = Angle;
+ using RollAngle = Angle;
using ViewAngles = omath::ViewAngles;
} // namespace omath::unreal_engine
diff --git a/include/omath/engines/unreal_engine/formulas.hpp b/include/omath/engines/unreal_engine/formulas.hpp
index 650bebd..68a4060 100644
--- a/include/omath/engines/unreal_engine/formulas.hpp
+++ b/include/omath/engines/unreal_engine/formulas.hpp
@@ -8,21 +8,21 @@
namespace omath::unreal_engine
{
[[nodiscard]]
- Vector3 forward_vector(const ViewAngles& angles) noexcept;
+ Vector3 forward_vector(const ViewAngles& angles) noexcept;
[[nodiscard]]
- Vector3 right_vector(const ViewAngles& angles) noexcept;
+ Vector3 right_vector(const ViewAngles& angles) noexcept;
[[nodiscard]]
- Vector3 up_vector(const ViewAngles& angles) noexcept;
+ Vector3 up_vector(const ViewAngles& angles) noexcept;
- [[nodiscard]] Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) noexcept;
+ [[nodiscard]] Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) noexcept;
[[nodiscard]]
Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
[[nodiscard]]
- Mat4X4 calc_perspective_projection_matrix(float field_of_view, float aspect_ratio, float near, float far,
+ Mat4X4 calc_perspective_projection_matrix(double field_of_view, double aspect_ratio, double near, double far,
NDCDepthRange ndc_depth_range = NDCDepthRange::NEGATIVE_ONE_TO_ONE) noexcept;
template
diff --git a/include/omath/engines/unreal_engine/traits/camera_trait.hpp b/include/omath/engines/unreal_engine/traits/camera_trait.hpp
index 952542c..4b0fe77 100644
--- a/include/omath/engines/unreal_engine/traits/camera_trait.hpp
+++ b/include/omath/engines/unreal_engine/traits/camera_trait.hpp
@@ -12,13 +12,13 @@ namespace omath::unreal_engine
{
public:
[[nodiscard]]
- static ViewAngles calc_look_at_angle(const Vector3& cam_origin, const Vector3& look_at) noexcept;
+ static ViewAngles calc_look_at_angle(const Vector3& cam_origin, const Vector3& look_at) noexcept;
[[nodiscard]]
- static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) noexcept;
+ static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) noexcept;
[[nodiscard]]
static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov, const projection::ViewPort& view_port,
- float near, float far, NDCDepthRange ndc_depth_range) noexcept;
+ double near, double far, NDCDepthRange ndc_depth_range) noexcept;
};
} // namespace omath::unreal_engine
\ No newline at end of file
diff --git a/include/omath/engines/unreal_engine/traits/pred_engine_trait.hpp b/include/omath/engines/unreal_engine/traits/pred_engine_trait.hpp
index f2a2214..b98b65d 100644
--- a/include/omath/engines/unreal_engine/traits/pred_engine_trait.hpp
+++ b/include/omath/engines/unreal_engine/traits/pred_engine_trait.hpp
@@ -12,67 +12,72 @@ namespace omath::unreal_engine
class PredEngineTrait final
{
public:
- constexpr static Vector3 predict_projectile_position(const projectile_prediction::Projectile& projectile,
- const float pitch, const float yaw,
- const float time, const float gravity) noexcept
+ static Vector3 predict_projectile_position(const projectile_prediction::Projectile& projectile,
+ const double pitch, const double yaw,
+ const double time, const double gravity) noexcept
{
const auto launch_pos = projectile.m_origin + projectile.m_launch_offset;
+ const auto fwd_d = forward_vector({PitchAngle::from_degrees(-pitch), YawAngle::from_degrees(yaw),
+ RollAngle::from_degrees(0)});
auto current_pos = launch_pos
- + forward_vector({PitchAngle::from_degrees(-pitch), YawAngle::from_degrees(yaw),
- RollAngle::from_degrees(0)})
+ + Vector3{fwd_d.x, fwd_d.y, fwd_d.z}
* projectile.m_launch_speed * time;
- current_pos.y -= (gravity * projectile.m_gravity_scale) * (time * time) * 0.5f;
+ current_pos.y -= (gravity * projectile.m_gravity_scale) * (time * time) * 0.5;
return current_pos;
}
+
[[nodiscard]]
- static constexpr Vector3 predict_target_position(const projectile_prediction::Target& target,
- const float time, const float gravity) noexcept
+ static Vector3 predict_target_position(const projectile_prediction::Target& target,
+ const double time, const double gravity) noexcept
{
auto predicted = target.m_origin + target.m_velocity * time;
if (target.m_is_airborne)
- predicted.y -= gravity * (time * time) * 0.5f;
+ predicted.y -= gravity * (time * time) * 0.5;
return predicted;
}
+
[[nodiscard]]
- static float calc_vector_2d_distance(const Vector3& delta) noexcept
+ static double calc_vector_2d_distance(const Vector3& delta) noexcept
{
return std::sqrt(delta.x * delta.x + delta.z * delta.z);
}
[[nodiscard]]
- constexpr static float get_vector_height_coordinate(const Vector3& vec) noexcept
+ static double get_vector_height_coordinate(const Vector3& vec) noexcept
{
return vec.y;
}
[[nodiscard]]
- static Vector3 calc_viewpoint_from_angles(const projectile_prediction::Projectile& projectile,
- Vector3 predicted_target_position,
- const std::optional projectile_pitch) noexcept
+ static Vector3 calc_viewpoint_from_angles(const projectile_prediction::Projectile& projectile,
+ Vector3 predicted_target_position,
+ const std::optional projectile_pitch) noexcept
{
const auto delta2d = calc_vector_2d_distance(predicted_target_position - projectile.m_origin);
const auto height = delta2d * std::tan(angles::degrees_to_radians(projectile_pitch.value()));
return {predicted_target_position.x, predicted_target_position.y, projectile.m_origin.z + height};
}
+
// Due to specification of maybe_calculate_projectile_launch_pitch_angle, pitch angle must be:
// 89 look up, -89 look down
[[nodiscard]]
- static float calc_direct_pitch_angle(const Vector3& origin, const Vector3& view_to) noexcept
+ static double calc_direct_pitch_angle(const Vector3& origin, const Vector3& view_to) noexcept
{
const auto direction = (view_to - origin).normalized();
return angles::radians_to_degrees(std::asin(direction.z));
}
+
[[nodiscard]]
- static float calc_direct_yaw_angle(const Vector3& origin, const Vector3& view_to) noexcept
+ static double calc_direct_yaw_angle(const Vector3& origin, const Vector3& view_to) noexcept
{
const auto direction = (view_to - origin).normalized();
return angles::radians_to_degrees(std::atan2(direction.y, direction.x));
- };
+ }
};
} // namespace omath::unreal_engine
diff --git a/include/omath/linear_algebra/mat.hpp b/include/omath/linear_algebra/mat.hpp
index a262b69..ca04b8c 100644
--- a/include/omath/linear_algebra/mat.hpp
+++ b/include/omath/linear_algebra/mat.hpp
@@ -667,21 +667,21 @@ namespace omath
template
[[nodiscard]]
- Mat<4, 4, Type, St> mat_perspective_left_handed(const float field_of_view, const float aspect_ratio,
- const float near, const float far) noexcept
+ Mat<4, 4, Type, St> mat_perspective_left_handed(const Type field_of_view, const Type aspect_ratio,
+ const Type near, const Type far) noexcept
{
- const float fov_half_tan = std::tan(angles::degrees_to_radians(field_of_view) / 2.f);
+ const auto fov_half_tan = std::tan(angles::degrees_to_radians(field_of_view) / Type{2});
if constexpr (DepthRange == NDCDepthRange::ZERO_TO_ONE)
- return {{1.f / (aspect_ratio * fov_half_tan), 0.f, 0.f, 0.f},
- {0.f, 1.f / fov_half_tan, 0.f, 0.f},
- {0.f, 0.f, far / (far - near), -(near * far) / (far - near)},
- {0.f, 0.f, 1.f, 0.f}};
+ return {{Type{1} / (aspect_ratio * fov_half_tan), Type{0}, Type{0}, Type{0}},
+ {Type{0}, Type{1} / fov_half_tan, Type{0}, Type{0}},
+ {Type{0}, Type{0}, far / (far - near), -(near * far) / (far - near)},
+ {Type{0}, Type{0}, Type{1}, Type{0}}};
else if constexpr (DepthRange == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
- return {{1.f / (aspect_ratio * fov_half_tan), 0.f, 0.f, 0.f},
- {0.f, 1.f / fov_half_tan, 0.f, 0.f},
- {0.f, 0.f, (far + near) / (far - near), -(2.f * near * far) / (far - near)},
- {0.f, 0.f, 1.f, 0.f}};
+ return {{Type{1} / (aspect_ratio * fov_half_tan), Type{0}, Type{0}, Type{0}},
+ {Type{0}, Type{1} / fov_half_tan, Type{0}, Type{0}},
+ {Type{0}, Type{0}, (far + near) / (far - near), -(Type{2} * near * far) / (far - near)},
+ {Type{0}, Type{0}, Type{1}, Type{0}}};
else
std::unreachable();
}
@@ -689,21 +689,21 @@ namespace omath
template
[[nodiscard]]
- Mat<4, 4, Type, St> mat_perspective_right_handed(const float field_of_view, const float aspect_ratio,
- const float near, const float far) noexcept
+ Mat<4, 4, Type, St> mat_perspective_right_handed(const Type field_of_view, const Type aspect_ratio,
+ const Type near, const Type far) noexcept
{
- const float fov_half_tan = std::tan(angles::degrees_to_radians(field_of_view) / 2.f);
+ const auto fov_half_tan = std::tan(angles::degrees_to_radians(field_of_view) / Type{2});
if constexpr (DepthRange == NDCDepthRange::ZERO_TO_ONE)
- return {{1.f / (aspect_ratio * fov_half_tan), 0.f, 0.f, 0.f},
- {0.f, 1.f / fov_half_tan, 0.f, 0.f},
- {0.f, 0.f, -far / (far - near), -(near * far) / (far - near)},
- {0.f, 0.f, -1.f, 0.f}};
+ return {{Type{1} / (aspect_ratio * fov_half_tan), Type{0}, Type{0}, Type{0}},
+ {Type{0}, Type{1} / fov_half_tan, Type{0}, Type{0}},
+ {Type{0}, Type{0}, -far / (far - near), -(near * far) / (far - near)},
+ {Type{0}, Type{0}, -Type{1}, Type{0}}};
else if constexpr (DepthRange == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
- return {{1.f / (aspect_ratio * fov_half_tan), 0.f, 0.f, 0.f},
- {0.f, 1.f / fov_half_tan, 0.f, 0.f},
- {0.f, 0.f, -(far + near) / (far - near), -(2.f * near * far) / (far - near)},
- {0.f, 0.f, -1.f, 0.f}};
+ return {{Type{1} / (aspect_ratio * fov_half_tan), Type{0}, Type{0}, Type{0}},
+ {Type{0}, Type{1} / fov_half_tan, Type{0}, Type{0}},
+ {Type{0}, Type{0}, -(far + near) / (far - near), -(Type{2} * near * far) / (far - near)},
+ {Type{0}, Type{0}, -Type{1}, Type{0}}};
else
std::unreachable();
}
@@ -714,24 +714,24 @@ namespace omath
template
[[nodiscard]]
- Mat<4, 4, Type, St> mat_perspective_left_handed_horizontal_fov(const float horizontal_fov,
- const float aspect_ratio, const float near,
- const float far) noexcept
+ Mat<4, 4, Type, St> mat_perspective_left_handed_horizontal_fov(const Type horizontal_fov,
+ const Type aspect_ratio, const Type near,
+ const Type far) noexcept
{
- const float inv_tan_half_hfov = 1.f / std::tan(angles::degrees_to_radians(horizontal_fov) / 2.f);
- const float x_axis = inv_tan_half_hfov;
- const float y_axis = inv_tan_half_hfov * aspect_ratio;
+ const auto inv_tan_half_hfov = Type{1} / std::tan(angles::degrees_to_radians(horizontal_fov) / Type{2});
+ const auto x_axis = inv_tan_half_hfov;
+ const auto y_axis = inv_tan_half_hfov * aspect_ratio;
if constexpr (DepthRange == NDCDepthRange::ZERO_TO_ONE)
- return {{x_axis, 0.f, 0.f, 0.f},
- {0.f, y_axis, 0.f, 0.f},
- {0.f, 0.f, far / (far - near), -(near * far) / (far - near)},
- {0.f, 0.f, 1.f, 0.f}};
+ return {{x_axis, Type{0}, Type{0}, Type{0}},
+ {Type{0}, y_axis, Type{0}, Type{0}},
+ {Type{0}, Type{0}, far / (far - near), -(near * far) / (far - near)},
+ {Type{0}, Type{0}, Type{1}, Type{0}}};
else if constexpr (DepthRange == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
- return {{x_axis, 0.f, 0.f, 0.f},
- {0.f, y_axis, 0.f, 0.f},
- {0.f, 0.f, (far + near) / (far - near), -(2.f * near * far) / (far - near)},
- {0.f, 0.f, 1.f, 0.f}};
+ return {{x_axis, Type{0}, Type{0}, Type{0}},
+ {Type{0}, y_axis, Type{0}, Type{0}},
+ {Type{0}, Type{0}, (far + near) / (far - near), -(2.f * near * far) / (far - near)},
+ {Type{0}, Type{0}, Type{1}, Type{0}}};
else
std::unreachable();
}
@@ -739,24 +739,24 @@ namespace omath
template
[[nodiscard]]
- Mat<4, 4, Type, St> mat_perspective_right_handed_horizontal_fov(const float horizontal_fov,
- const float aspect_ratio, const float near,
- const float far) noexcept
+ Mat<4, 4, Type, St> mat_perspective_right_handed_horizontal_fov(const Type horizontal_fov,
+ const Type aspect_ratio, const Type near,
+ const Type far) noexcept
{
- const float inv_tan_half_hfov = 1.f / std::tan(angles::degrees_to_radians(horizontal_fov) / 2.f);
- const float x_axis = inv_tan_half_hfov;
- const float y_axis = inv_tan_half_hfov * aspect_ratio;
+ const auto inv_tan_half_hfov = Type{1} / std::tan(angles::degrees_to_radians(horizontal_fov) / Type{2});
+ const auto x_axis = inv_tan_half_hfov;
+ const auto y_axis = inv_tan_half_hfov * aspect_ratio;
if constexpr (DepthRange == NDCDepthRange::ZERO_TO_ONE)
- return {{x_axis, 0.f, 0.f, 0.f},
- {0.f, y_axis, 0.f, 0.f},
- {0.f, 0.f, -far / (far - near), -(near * far) / (far - near)},
- {0.f, 0.f, -1.f, 0.f}};
+ return {{x_axis, Type{0}, Type{0}, Type{0}},
+ {Type{0}, y_axis, Type{0}, Type{0}},
+ {Type{0}, Type{0}, -far / (far - near), -(near * far) / (far - near)},
+ {Type{0}, Type{0}, -Type{1}, Type{0}}};
else if constexpr (DepthRange == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
- return {{x_axis, 0.f, 0.f, 0.f},
- {0.f, y_axis, 0.f, 0.f},
- {0.f, 0.f, -(far + near) / (far - near), -(2.f * near * far) / (far - near)},
- {0.f, 0.f, -1.f, 0.f}};
+ return {{x_axis, Type{0}, Type{0}, Type{0}},
+ {Type{0}, y_axis, Type{0}, Type{0}},
+ {Type{0}, Type{0}, -(far + near) / (far - near), -(2.f * near * far) / (far - near)},
+ {Type{0}, Type{0}, -Type{1}, Type{0}}};
else
std::unreachable();
}
diff --git a/include/omath/projectile_prediction/proj_pred_engine.hpp b/include/omath/projectile_prediction/proj_pred_engine.hpp
index 8b2b6f7..f4c2fbc 100644
--- a/include/omath/projectile_prediction/proj_pred_engine.hpp
+++ b/include/omath/projectile_prediction/proj_pred_engine.hpp
@@ -8,22 +8,24 @@
namespace omath::projectile_prediction
{
+ template
struct AimAngles
{
- float pitch{};
- float yaw{};
+ ArithmeticType pitch{};
+ ArithmeticType yaw{};
};
+ template
class ProjPredEngineInterface
{
public:
[[nodiscard]]
- virtual std::optional> maybe_calculate_aim_point(const Projectile& projectile,
- const Target& target) const = 0;
+ virtual std::optional> maybe_calculate_aim_point(
+ const Projectile& projectile, const Target& target) const = 0;
[[nodiscard]]
- virtual std::optional maybe_calculate_aim_angles(const Projectile& projectile,
- const Target& target) const = 0;
+ virtual std::optional> maybe_calculate_aim_angles(
+ const Projectile& projectile, const Target& target) const = 0;
virtual ~ProjPredEngineInterface() = default;
};
diff --git a/include/omath/projectile_prediction/proj_pred_engine_avx2.hpp b/include/omath/projectile_prediction/proj_pred_engine_avx2.hpp
index da41c64..0ec2eb3 100644
--- a/include/omath/projectile_prediction/proj_pred_engine_avx2.hpp
+++ b/include/omath/projectile_prediction/proj_pred_engine_avx2.hpp
@@ -6,14 +6,14 @@
namespace omath::projectile_prediction
{
- class ProjPredEngineAvx2 final : public ProjPredEngineInterface
+ class ProjPredEngineAvx2 final : public ProjPredEngineInterface
{
public:
[[nodiscard]] std::optional>
- maybe_calculate_aim_point(const Projectile& projectile, const Target& target) const override;
+ maybe_calculate_aim_point(const Projectile& projectile, const Target& target) const override;
- [[nodiscard]] std::optional
- maybe_calculate_aim_angles(const Projectile& projectile, const Target& target) const override;
+ [[nodiscard]] std::optional>
+ maybe_calculate_aim_angles(const Projectile& projectile, const Target& target) const override;
ProjPredEngineAvx2(float gravity_constant, float simulation_time_step, float maximum_simulation_time);
~ProjPredEngineAvx2() override = default;
@@ -21,7 +21,7 @@ namespace omath::projectile_prediction
private:
[[nodiscard]] static std::optional calculate_pitch(const Vector3& proj_origin,
const Vector3& target_pos,
- float bullet_gravity, float v0, float time) ;
+ float bullet_gravity, float v0, float time);
// We use [[maybe_unused]] here since AVX2 is not available for ARM and ARM64 CPU
[[maybe_unused]] const float m_gravity_constant;
diff --git a/include/omath/projectile_prediction/proj_pred_engine_legacy.hpp b/include/omath/projectile_prediction/proj_pred_engine_legacy.hpp
index eb2b983..0800a44 100644
--- a/include/omath/projectile_prediction/proj_pred_engine_legacy.hpp
+++ b/include/omath/projectile_prediction/proj_pred_engine_legacy.hpp
@@ -13,24 +13,23 @@
namespace omath::projectile_prediction
{
- template
+ template
concept PredEngineConcept =
- requires(const Projectile& projectile, const Target& target, const Vector3& vec_a,
- const Vector3& vec_b,
- Vector3 v3, // by-value for calc_viewpoint_from_angles
- float pitch, float yaw, float time, float gravity, std::optional maybe_pitch) {
- // Presence + return types
+ requires(const Projectile& projectile, const Target& target,
+ const Vector3& vec_a, const Vector3& vec_b,
+ Vector3 v3,
+ ArithmeticType pitch, ArithmeticType yaw, ArithmeticType time, ArithmeticType gravity,
+ std::optional maybe_pitch) {
{
T::predict_projectile_position(projectile, pitch, yaw, time, gravity)
- } -> std::same_as>;
- { T::predict_target_position(target, time, gravity) } -> std::same_as>;
- { T::calc_vector_2d_distance(vec_a) } -> std::same_as;
- { T::get_vector_height_coordinate(vec_b) } -> std::same_as;
- { T::calc_viewpoint_from_angles(projectile, v3, maybe_pitch) } -> std::same_as>;
- { T::calc_direct_pitch_angle(vec_a, vec_b) } -> std::same_as;
- { T::calc_direct_yaw_angle(vec_a, vec_b) } -> std::same_as;
+ } -> std::same_as>;
+ { T::predict_target_position(target, time, gravity) } -> std::same_as>;
+ { T::calc_vector_2d_distance(vec_a) } -> std::same_as;
+ { T::get_vector_height_coordinate(vec_b) } -> std::same_as;
+ { T::calc_viewpoint_from_angles(projectile, v3, maybe_pitch) } -> std::same_as>;
+ { T::calc_direct_pitch_angle(vec_a, vec_b) } -> std::same_as;
+ { T::calc_direct_yaw_angle(vec_a, vec_b) } -> std::same_as;
- // Enforce noexcept as in PredEngineTrait
requires noexcept(T::predict_projectile_position(projectile, pitch, yaw, time, gravity));
requires noexcept(T::predict_target_position(target, time, gravity));
requires noexcept(T::calc_vector_2d_distance(vec_a));
@@ -39,21 +38,24 @@ namespace omath::projectile_prediction
requires noexcept(T::calc_direct_pitch_angle(vec_a, vec_b));
requires noexcept(T::calc_direct_yaw_angle(vec_a, vec_b));
};
- template
- requires PredEngineConcept
- class ProjPredEngineLegacy final : public ProjPredEngineInterface
+
+ template
+ requires PredEngineConcept
+ class ProjPredEngineLegacy final : public ProjPredEngineInterface
{
public:
- explicit ProjPredEngineLegacy(const float gravity_constant, const float simulation_time_step,
- const float maximum_simulation_time, const float distance_tolerance)
+ explicit ProjPredEngineLegacy(const ArithmeticType gravity_constant,
+ const ArithmeticType simulation_time_step,
+ const ArithmeticType maximum_simulation_time,
+ const ArithmeticType distance_tolerance)
: m_gravity_constant(gravity_constant), m_simulation_time_step(simulation_time_step),
m_maximum_simulation_time(maximum_simulation_time), m_distance_tolerance(distance_tolerance)
{
}
[[nodiscard]]
- std::optional> maybe_calculate_aim_point(const Projectile& projectile,
- const Target& target) const override
+ std::optional> maybe_calculate_aim_point(
+ const Projectile& projectile, const Target& target) const override
{
const auto solution = find_solution(projectile, target);
if (!solution)
@@ -64,28 +66,31 @@ namespace omath::projectile_prediction
}
[[nodiscard]]
- std::optional maybe_calculate_aim_angles(const Projectile& projectile,
- const Target& target) const override
+ std::optional> maybe_calculate_aim_angles(
+ const Projectile& projectile, const Target& target) const override
{
const auto solution = find_solution(projectile, target);
if (!solution)
return std::nullopt;
- const auto yaw = EngineTrait::calc_direct_yaw_angle(projectile.m_origin + projectile.m_launch_offset, solution->predicted_target_position);
- return AimAngles{solution->pitch, yaw};
+ const auto yaw = EngineTrait::calc_direct_yaw_angle(
+ projectile.m_origin + projectile.m_launch_offset, solution->predicted_target_position);
+ return AimAngles{solution->pitch, yaw};
}
private:
struct Solution
{
- Vector3 predicted_target_position;
- float pitch;
+ Vector3 predicted_target_position;
+ ArithmeticType pitch;
};
[[nodiscard]]
- std::optional find_solution(const Projectile& projectile, const Target& target) const
+ std::optional find_solution(const Projectile& projectile,
+ const Target& target) const
{
- for (float time = 0.f; time < m_maximum_simulation_time; time += m_simulation_time_step)
+ for (ArithmeticType time = ArithmeticType{0}; time < m_maximum_simulation_time;
+ time += m_simulation_time_step)
{
const auto predicted_target_position =
EngineTrait::predict_target_position(target, time, m_gravity_constant);
@@ -105,10 +110,10 @@ namespace omath::projectile_prediction
return std::nullopt;
}
- const float m_gravity_constant;
- const float m_simulation_time_step;
- const float m_maximum_simulation_time;
- const float m_distance_tolerance;
+ const ArithmeticType m_gravity_constant;
+ const ArithmeticType m_simulation_time_step;
+ const ArithmeticType m_maximum_simulation_time;
+ const ArithmeticType m_distance_tolerance;
// Realization of this formula:
// https://stackoverflow.com/questions/54917375/how-to-calculate-the-angle-to-shoot-a-bullet-in-order-to-hit-a-moving-target
@@ -123,15 +128,15 @@ namespace omath::projectile_prediction
\]
*/
[[nodiscard]]
- std::optional
- maybe_calculate_projectile_launch_pitch_angle(const Projectile& projectile,
- const Vector3& target_position) const noexcept
+ std::optional
+ maybe_calculate_projectile_launch_pitch_angle(const Projectile& projectile,
+ const Vector3& target_position) const noexcept
{
const auto bullet_gravity = m_gravity_constant * projectile.m_gravity_scale;
const auto launch_origin = projectile.m_origin + projectile.m_launch_offset;
- if (bullet_gravity == 0.f)
+ if (bullet_gravity == ArithmeticType{0})
return EngineTrait::calc_direct_pitch_angle(launch_origin, target_position);
const auto delta = target_position - launch_origin;
@@ -140,24 +145,28 @@ namespace omath::projectile_prediction
const auto distance2d_sqr = distance2d * distance2d;
const auto launch_speed_sqr = projectile.m_launch_speed * projectile.m_launch_speed;
- float root = launch_speed_sqr * launch_speed_sqr
- - bullet_gravity
- * (bullet_gravity * distance2d_sqr
- + 2.0f * EngineTrait::get_vector_height_coordinate(delta) * launch_speed_sqr);
+ ArithmeticType root = launch_speed_sqr * launch_speed_sqr
+ - bullet_gravity
+ * (bullet_gravity * distance2d_sqr
+ + ArithmeticType{2} * EngineTrait::get_vector_height_coordinate(delta)
+ * launch_speed_sqr);
- if (root < 0.0f) [[unlikely]]
+ if (root < ArithmeticType{0}) [[unlikely]]
return std::nullopt;
root = std::sqrt(root);
- const float angle = std::atan((launch_speed_sqr - root) / (bullet_gravity * distance2d));
+ const ArithmeticType angle = std::atan((launch_speed_sqr - root) / (bullet_gravity * distance2d));
return angles::radians_to_degrees(angle);
}
+
[[nodiscard]]
- bool is_projectile_reached_target(const Vector3& target_position, const Projectile& projectile,
- const float pitch, const float time) const noexcept
+ bool is_projectile_reached_target(const Vector3& target_position,
+ const Projectile& projectile,
+ const ArithmeticType pitch, const ArithmeticType time) const noexcept
{
- const auto yaw = EngineTrait::calc_direct_yaw_angle(projectile.m_origin + projectile.m_launch_offset, target_position);
+ const auto yaw = EngineTrait::calc_direct_yaw_angle(
+ projectile.m_origin + projectile.m_launch_offset, target_position);
const auto projectile_position =
EngineTrait::predict_projectile_position(projectile, pitch, yaw, time, m_gravity_constant);
diff --git a/include/omath/projectile_prediction/projectile.hpp b/include/omath/projectile_prediction/projectile.hpp
index 92537ed..841ea50 100644
--- a/include/omath/projectile_prediction/projectile.hpp
+++ b/include/omath/projectile_prediction/projectile.hpp
@@ -7,12 +7,13 @@
namespace omath::projectile_prediction
{
+ template
class Projectile final
{
public:
- Vector3 m_origin;
- Vector3 m_launch_offset{0.f, 0.f, 0.f};
- float m_launch_speed{};
- float m_gravity_scale{};
+ Vector3 m_origin;
+ Vector3 m_launch_offset{};
+ ArithmeticType m_launch_speed{};
+ ArithmeticType m_gravity_scale{};
};
} // namespace omath::projectile_prediction
\ No newline at end of file
diff --git a/include/omath/projectile_prediction/target.hpp b/include/omath/projectile_prediction/target.hpp
index 5b3f5db..6866da5 100644
--- a/include/omath/projectile_prediction/target.hpp
+++ b/include/omath/projectile_prediction/target.hpp
@@ -7,11 +7,12 @@
namespace omath::projectile_prediction
{
+ template
class Target final
{
public:
- Vector3 m_origin;
- Vector3 m_velocity;
+ Vector3 m_origin;
+ Vector3 m_velocity;
bool m_is_airborne{};
};
-} // namespace omath::projectile_prediction
\ No newline at end of file
+} // namespace omath::projectile_prediction
diff --git a/include/omath/projection/camera.hpp b/include/omath/projection/camera.hpp
index 4b71f17..28e9703 100644
--- a/include/omath/projection/camera.hpp
+++ b/include/omath/projection/camera.hpp
@@ -45,29 +45,29 @@ namespace omath::projection
struct CameraAxes
{
bool inverted_forward = false;
- bool inverted_right = false;
+ bool inverted_right = false;
};
- template
+ template
concept CameraEngineConcept =
- requires(const Vector3& cam_origin, const Vector3& look_at, const ViewAnglesType& angles,
- const FieldOfView& fov, const ViewPort& viewport, float znear, float zfar,
- NDCDepthRange ndc_depth_range) {
+ requires(const Vector3& cam_origin, const Vector3& look_at,
+ const ViewAnglesType& angles, const FieldOfView& fov, const ViewPort& viewport, NumericType z_near,
+ NumericType z_far, NDCDepthRange ndc_depth_range) {
// Presence + return types
{ T::calc_look_at_angle(cam_origin, look_at) } -> std::same_as;
{ T::calc_view_matrix(angles, cam_origin) } -> std::same_as;
- { T::calc_projection_matrix(fov, viewport, znear, zfar, ndc_depth_range) } -> std::same_as;
-
+ { T::calc_projection_matrix(fov, viewport, z_near, z_far, ndc_depth_range) } -> std::same_as;
+ requires std::is_floating_point_v;
// Enforce noexcept as in the trait declaration
requires noexcept(T::calc_look_at_angle(cam_origin, look_at));
requires noexcept(T::calc_view_matrix(angles, cam_origin));
- requires noexcept(T::calc_projection_matrix(fov, viewport, znear, zfar, ndc_depth_range));
+ requires noexcept(T::calc_projection_matrix(fov, viewport, z_near, z_far, ndc_depth_range));
};
template
- requires CameraEngineConcept
+ NDCDepthRange depth_range = NDCDepthRange::NEGATIVE_ONE_TO_ONE, CameraAxes axes = {},
+ class NumericType = float>
+ requires CameraEngineConcept
class Camera final
{
#ifdef OMATH_BUILD_TESTS
@@ -83,17 +83,17 @@ namespace omath::projection
};
~Camera() = default;
- Camera(const Vector3& position, const ViewAnglesType& view_angles, const ViewPort& view_port,
- const FieldOfView& fov, const float near, const float far) noexcept
+ Camera(const Vector3& position, const ViewAnglesType& view_angles, const ViewPort& view_port,
+ const FieldOfView& fov, const NumericType near, const NumericType far) noexcept
: m_view_port(view_port), m_field_of_view(fov), m_far_plane_distance(far), m_near_plane_distance(near),
m_view_angles(view_angles), m_origin(position)
{
}
- struct ProjectionParams
+ struct ProjectionParams final
{
FieldOfView fov;
- float aspect_ratio;
+ NumericType aspect_ratio{};
};
// Recovers vertical FOV and aspect ratio from a perspective projection matrix
@@ -104,66 +104,70 @@ namespace omath::projection
static ProjectionParams extract_projection_params(const Mat4X4Type& proj_matrix) noexcept
{
// m[1,1] == 1 / tan(fov/2) => fov = 2 * atan(1 / m[1,1])
- const float f = proj_matrix.at(1, 1);
+ const auto f = proj_matrix.at(1, 1);
// m[0,0] == m[1,1] / aspect_ratio => aspect = m[1,1] / m[0,0]
- return {FieldOfView::from_radians(2.f * std::atan(1.f / f)), f / proj_matrix.at(0, 0)};
+ return {FieldOfView::from_radians(NumericType{2} * std::atan(NumericType{1} / f)),
+ f / proj_matrix.at(0, 0)};
}
[[nodiscard]]
static ViewAnglesType calc_view_angles_from_view_matrix(const Mat4X4Type& view_matrix) noexcept
{
- Vector3 forward_vector = {view_matrix[2, 0], view_matrix[2, 1], view_matrix[2, 2]};
+ Vector3 forward_vector = {view_matrix[2, 0], view_matrix[2, 1], view_matrix[2, 2]};
if constexpr (axes.inverted_forward)
forward_vector = -forward_vector;
return TraitClass::calc_look_at_angle({}, forward_vector);
}
[[nodiscard]]
- static Vector3 calc_origin_from_view_matrix(const Mat4X4Type& view_matrix) noexcept
+ static Vector3 calc_origin_from_view_matrix(const Mat4X4Type& view_matrix) noexcept
{
// The view matrix is R * T(-origin), so the last column stores t = -R * origin.
// Recovering origin: origin = -R^T * t
return {
- -(view_matrix[0, 0] * view_matrix[0, 3] + view_matrix[1, 0] * view_matrix[1, 3] + view_matrix[2, 0] * view_matrix[2, 3]),
- -(view_matrix[0, 1] * view_matrix[0, 3] + view_matrix[1, 1] * view_matrix[1, 3] + view_matrix[2, 1] * view_matrix[2, 3]),
- -(view_matrix[0, 2] * view_matrix[0, 3] + view_matrix[1, 2] * view_matrix[1, 3] + view_matrix[2, 2] * view_matrix[2, 3]),
+ -(view_matrix[0, 0] * view_matrix[0, 3] + view_matrix[1, 0] * view_matrix[1, 3]
+ + view_matrix[2, 0] * view_matrix[2, 3]),
+ -(view_matrix[0, 1] * view_matrix[0, 3] + view_matrix[1, 1] * view_matrix[1, 3]
+ + view_matrix[2, 1] * view_matrix[2, 3]),
+ -(view_matrix[0, 2] * view_matrix[0, 3] + view_matrix[1, 2] * view_matrix[1, 3]
+ + view_matrix[2, 2] * view_matrix[2, 3]),
};
}
- void look_at(const Vector3& target)
+ void look_at(const Vector3& target)
{
m_view_angles = TraitClass::calc_look_at_angle(m_origin, target);
m_view_projection_matrix = std::nullopt;
m_view_matrix = std::nullopt;
}
[[nodiscard]]
- ViewAnglesType calc_look_at_angles(const Vector3& look_to) const
+ ViewAnglesType calc_look_at_angles(const Vector3& look_to) const
{
return TraitClass::calc_look_at_angle(m_origin, look_to);
}
[[nodiscard]]
- Vector3 get_forward() const noexcept
+ Vector3 get_forward() const noexcept
{
const auto& view_matrix = get_view_matrix();
return {view_matrix[2, 0], view_matrix[2, 1], view_matrix[2, 2]};
}
[[nodiscard]]
- Vector3 get_right() const noexcept
+ Vector3 get_right() const noexcept
{
const auto& view_matrix = get_view_matrix();
return {view_matrix[0, 0], view_matrix[0, 1], view_matrix[0, 2]};
}
[[nodiscard]]
- Vector3 get_up() const noexcept
+ Vector3 get_up() const noexcept
{
const auto& view_matrix = get_view_matrix();
return {view_matrix[1, 0], view_matrix[1, 1], view_matrix[1, 2]};
}
[[nodiscard]]
- Vector3 get_abs_forward() const noexcept
+ Vector3 get_abs_forward() const noexcept
{
if constexpr (axes.inverted_forward)
return -get_forward();
@@ -171,7 +175,7 @@ namespace omath::projection
}
[[nodiscard]]
- Vector3 get_abs_right() const noexcept
+ Vector3 get_abs_right() const noexcept
{
if constexpr (axes.inverted_right)
return -get_right();
@@ -179,7 +183,7 @@ namespace omath::projection
}
[[nodiscard]]
- Vector3 get_abs_up() const noexcept
+ Vector3 get_abs_up() const noexcept
{
return get_up();
}
@@ -202,9 +206,8 @@ namespace omath::projection
[[nodiscard]] const Mat4X4Type& get_projection_matrix() const noexcept
{
if (!m_projection_matrix.has_value())
- m_projection_matrix = TraitClass::calc_projection_matrix(m_field_of_view, m_view_port,
- m_near_plane_distance, m_far_plane_distance,
- depth_range);
+ m_projection_matrix = TraitClass::calc_projection_matrix(
+ m_field_of_view, m_view_port, m_near_plane_distance, m_far_plane_distance, depth_range);
return m_projection_matrix.value();
}
@@ -216,14 +219,14 @@ namespace omath::projection
m_projection_matrix = std::nullopt;
}
- void set_near_plane(const float near_plane) noexcept
+ void set_near_plane(const NumericType near_plane) noexcept
{
m_near_plane_distance = near_plane;
m_view_projection_matrix = std::nullopt;
m_projection_matrix = std::nullopt;
}
- void set_far_plane(const float far_plane) noexcept
+ void set_far_plane(const NumericType far_plane) noexcept
{
m_far_plane_distance = far_plane;
m_view_projection_matrix = std::nullopt;
@@ -237,7 +240,7 @@ namespace omath::projection
m_view_matrix = std::nullopt;
}
- void set_origin(const Vector3& origin) noexcept
+ void set_origin(const Vector3& origin) noexcept
{
m_origin = origin;
m_view_projection_matrix = std::nullopt;
@@ -255,12 +258,12 @@ namespace omath::projection
return m_field_of_view;
}
- [[nodiscard]] const float& get_near_plane() const noexcept
+ [[nodiscard]] const NumericType& get_near_plane() const noexcept
{
return m_near_plane_distance;
}
- [[nodiscard]] const float& get_far_plane() const noexcept
+ [[nodiscard]] const NumericType& get_far_plane() const noexcept
{
return m_far_plane_distance;
}
@@ -270,14 +273,14 @@ namespace omath::projection
return m_view_angles;
}
- [[nodiscard]] const Vector3& get_origin() const noexcept
+ [[nodiscard]] const Vector3& get_origin() const noexcept
{
return m_origin;
}
template
- [[nodiscard]] std::expected