mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 07:03:25 +00:00
improved projectile prediction
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user