mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 07:03:25 +00:00
refactored projectile prediction
This commit is contained in:
@@ -1,58 +0,0 @@
|
||||
//
|
||||
// Created by vlad on 11/6/23.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include <optional>
|
||||
#include <uml/Vector3.h>
|
||||
|
||||
|
||||
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]]
|
||||
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]]
|
||||
Vector3 LinearPrediction(const Target& target, float time) const;
|
||||
|
||||
[[nodiscard]]
|
||||
std::optional<float>
|
||||
MaybeCalculateProjectileLaunchPitchAngle(const Projectile& projectile,
|
||||
const Vector3& targetPosition) const;
|
||||
|
||||
[[nodiscard]]
|
||||
std::optional<float> ProjectileTravelTime(const Vector3& end,
|
||||
const Projectile& projectile,
|
||||
float angle) const;
|
||||
|
||||
[[nodiscard]]
|
||||
bool IsTargetWasHit(const Vector3& end, const Projectile& projectile, float angle, float time) const;
|
||||
};
|
||||
|
||||
};
|
||||
@@ -57,7 +57,7 @@ namespace uml
|
||||
{
|
||||
return *reinterpret_cast<type*>(this);
|
||||
}
|
||||
[[nodiscard]] static Vector3 CreateVelocity(const Vector3& angles, float length);
|
||||
[[nodiscard]] static Vector3 CreateVelocity(float pitch, float yaw, float speed);
|
||||
[[nodiscard]] float Sum() const;
|
||||
[[nodiscard]] float Sum2D() const;
|
||||
[[nodiscard]] Vector3 ViewAngleTo(const Vector3& other) const;
|
||||
|
||||
@@ -6,6 +6,6 @@
|
||||
|
||||
namespace uml::angles
|
||||
{
|
||||
[[nodiscard]] float RadToDeg(float rads);
|
||||
[[nodiscard]] float DegToRad(float degrees);
|
||||
[[nodiscard]] float RadiansToDegrees(float rads);
|
||||
[[nodiscard]] float DegreesToRadians(float degrees);
|
||||
}
|
||||
37
include/uml/prediction/Engine.h
Normal file
37
include/uml/prediction/Engine.h
Normal file
@@ -0,0 +1,37 @@
|
||||
//
|
||||
// Created by Vlad on 6/9/2024.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
#include "uml/Vector3.h"
|
||||
#include "uml/prediction/Projectile.h"
|
||||
#include "uml/prediction/Target.h"
|
||||
|
||||
|
||||
namespace uml::prediction
|
||||
{
|
||||
class Engine
|
||||
{
|
||||
public:
|
||||
explicit Engine(float gravityConstant, float simulationTimeStep, float maximumSimulationTime);
|
||||
|
||||
[[nodiscard]]
|
||||
std::optional<Vector3> MaybeCalculateAimPoint(const Projectile& projectile, const Target& target) const;
|
||||
|
||||
private:
|
||||
const float m_gravityConstant;
|
||||
const float m_simulationTimeStep;
|
||||
const float m_maximumSimulationTime;
|
||||
|
||||
[[nodiscard]]
|
||||
std::optional<float> MaybeCalculateProjectileLaunchPitchAngle(const Projectile& projectile,
|
||||
const Vector3& targetPosition) const;
|
||||
|
||||
|
||||
[[nodiscard]]
|
||||
bool IsProjectileReachedTarget(const Vector3& targetPosition, const Projectile& projectile, float pitch, float time) const;
|
||||
|
||||
};
|
||||
}
|
||||
25
include/uml/prediction/Projectile.h
Normal file
25
include/uml/prediction/Projectile.h
Normal file
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// Created by Vlad on 6/9/2024.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include "uml/Vector3.h"
|
||||
|
||||
|
||||
namespace uml::prediction
|
||||
{
|
||||
class Projectile final
|
||||
{
|
||||
public:
|
||||
|
||||
[[nodiscard]]
|
||||
Vector3 CalculateVelocity(float pitch, float yaw) const;
|
||||
|
||||
[[nodiscard]]
|
||||
Vector3 PredictPosition(float pitch, float yaw, float time, float gravity) const;
|
||||
|
||||
Vector3 m_origin;
|
||||
float m_launchSpeed{};
|
||||
float m_gravityScale{};
|
||||
};
|
||||
}
|
||||
22
include/uml/prediction/Target.h
Normal file
22
include/uml/prediction/Target.h
Normal file
@@ -0,0 +1,22 @@
|
||||
//
|
||||
// Created by Vlad on 6/9/2024.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include "uml/Vector3.h"
|
||||
|
||||
|
||||
namespace uml::prediction
|
||||
{
|
||||
class Target final
|
||||
{
|
||||
public:
|
||||
|
||||
[[nodiscard]]
|
||||
Vector3 PredictPosition(float time, float gravity) const;
|
||||
|
||||
Vector3 m_origin;
|
||||
Vector3 m_velocity;
|
||||
bool m_isAirborne{};
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user