diff --git a/include/omath/projectile_prediction/engine_traits/source_engine_trait.hpp b/include/omath/projectile_prediction/engine_traits/source_engine_trait.hpp index 367e93c..1d4b113 100644 --- a/include/omath/projectile_prediction/engine_traits/source_engine_trait.hpp +++ b/include/omath/projectile_prediction/engine_traits/source_engine_trait.hpp @@ -37,13 +37,13 @@ namespace omath::projectile_prediction::traits return projectile_position.distance_to(target_position) <= tolerance; } [[nodiscard]] - static float calc_vector_2d_distance(const Vector3& delta) + static float calc_vector_2d_distance(const Vector3& delta) noexcept { return std::sqrt(delta.x * delta.x + delta.y * delta.y); } [[nodiscard]] - constexpr static float get_vector_height_coordinate(const Vector3& vec) + constexpr static float get_vector_height_coordinate(const Vector3& vec) noexcept { return vec.z; } @@ -51,12 +51,22 @@ namespace omath::projectile_prediction::traits [[nodiscard]] static Vector3 calc_viewpoint_from_angles(const Projectile& projectile, Vector3 predicted_target_position, - const std::optional projectile_pitch) + 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 + { + const auto distance = origin.distance_to(view_to); + const auto delta = view_to - origin; + + return angles::radians_to_degrees(std::asin(delta.z / distance)); + } }; } // namespace omath::projectile_prediction::traits \ No newline at end of file diff --git a/include/omath/projectile_prediction/proj_pred_engine_legacy.hpp b/include/omath/projectile_prediction/proj_pred_engine_legacy.hpp index f463f84..667954f 100644 --- a/include/omath/projectile_prediction/proj_pred_engine_legacy.hpp +++ b/include/omath/projectile_prediction/proj_pred_engine_legacy.hpp @@ -73,6 +73,11 @@ namespace omath::projectile_prediction const Vector3& target_position) const noexcept { const auto bullet_gravity = m_gravity_constant * projectile.m_gravity_scale; + + if (bullet_gravity == 0.f) + return EngineTrait::calc_direct_pitch_angle(projectile.m_origin, target_position); + + const auto delta = target_position - projectile.m_origin; const auto distance2d = EngineTrait::calc_vector_2d_distance(delta);