40 lines
980 B
C++
40 lines
980 B
C++
|
|
#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);
|
||
|
|
}
|
||
|
|
}
|