From 10f2dd8a86f61924e9dfa9a4a68bf27fb31f9ed6 Mon Sep 17 00:00:00 2001 From: Emmanuel AYME Date: Thu, 1 Jan 2026 19:15:10 +0100 Subject: [PATCH] Add Unreal Engine maths lib --- UEngine/UEMath.hpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 UEngine/UEMath.hpp diff --git a/UEngine/UEMath.hpp b/UEngine/UEMath.hpp new file mode 100644 index 0000000..0b13f12 --- /dev/null +++ b/UEngine/UEMath.hpp @@ -0,0 +1,40 @@ +#pragma once +#include + + + +namespace UEMath +{ + struct Vector + { + float X; + float Y; + float Z; + }; + + struct Rotator + { + float Pitch; // X + float Yaw; // Y + float Roll; // Z + }; + + /** + * @brief Converts a rotator (Pitch, Yaw) to a forward direction vector. + * Computes a normalized forward vector from the given FRotator, + * using Pitch and Yaw angles (in degrees). + * @param rotator Input rotation (degrees). + * @return Forward direction vector. + */ + static inline Vector RotatorToForwardVector(const Rotator& rotator) + { + constexpr float DEG_TO_RAD = 3.14159265358979323846f / 180.0f; + + const float cp = cosf(rotator.Pitch * DEG_TO_RAD); + const float sp = sinf(rotator.Pitch * DEG_TO_RAD); + const float cy = cosf(rotator.Yaw * DEG_TO_RAD); + const float sy = sinf(rotator.Yaw * DEG_TO_RAD); + + return Vector(cp * cy, cp * sy, sp); + } +} \ No newline at end of file