Add Unreal Engine maths lib

This commit is contained in:
2026-01-01 19:15:10 +01:00
parent f00e133c5c
commit 10f2dd8a86

40
UEngine/UEMath.hpp Normal file
View File

@@ -0,0 +1,40 @@
#pragma once
#include <cmath>
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);
}
}