improved projectile prediction

This commit is contained in:
2024-05-07 02:12:17 +03:00
parent 503114e4b8
commit 1b59e254f4
5 changed files with 117 additions and 59 deletions

View File

@@ -5,34 +5,52 @@
#pragma once
#include <optional>
#include <vector>
#include <uml/Vector3.h>
namespace uml
{
class Vector3;
}
namespace uml::prediction
{
struct Projectile
{
Vector3 m_origin;
float m_velocity{};
float m_gravityMultiplier = 1.f;
};
struct Target
{
Vector3 m_origin;
Vector3 m_vecVelocity;
bool m_IsAirborne;
};
class ProjectilePredictor
{
public:
explicit ProjectilePredictor(float gravityValue,
float maxTimeToTravel = 3.f,
float timeStep = 0.1f);
[[nodiscard]]
static std::optional<Vector3> CalculateViewAngles(const Vector3& origin,
const Vector3& target,
const Vector3& targetVelocity,
float gravity,
float bulletSpeed,
float bulletGravity,
bool inAir);
std::optional<Vector3> PredictPointToAim(const Target& target,
const Projectile& projectile) const;
private:
const float m_gravity;
const float m_maxTravelTime;
const float m_timeStepSize;
[[nodiscard]]
static std::optional<float> CalculateAimPitch(const Vector3& origin,
const Vector3& target,
float bulletSpeed,
float bulletGravity);
[[nodiscard]] static float ProjectileTravelTime(float distance, float angle, float speed);
Vector3 LinearPrediction(const Target& target, float time) const;
[[nodiscard]]
std::optional<float>
MaybeCalculateProjectileLaunchPitchAngle(const Projectile& projectile,
const Vector3& targetPosition) const;
[[nodiscard]]
float ProjectileTravelTime(const Vector3& end, const Projectile& projectile,
const float angle) const;
};
};