❗ NormalizeAngle is fine ?
Code:
#include "Math.h"
#include <iostream>
CMath Math;
Vector3 CMath::NormalizeAngle(const Vector3 Angle1) {
Vector3 Angle = Angle1;
if (!std::isfinite(Angle.x)) {
Angle.x = 0;
}
if (!std::isfinite(Angle.y)) {
Angle.y = 0;
}
while (Angle.y < -180.0f)
Angle.y += 360.0f;
while (Angle.y > 180.0f)
Angle.y -= 360.0f;
if (Angle.x > 89.0f)
Angle.x = 89.0f;
if (Angle.x < -89.0f)
Angle.x = -89.0f;
Angle.z = 0;
return Angle;
}
Vector3 CMath::SmoothAngle(const Vector3 Angle1, const Vector3 Angle2, float Smooth) {
Vector3 Delta = { Angle2.x - Angle1.x, Angle2.y - Angle1.y, 0 };
Delta = NormalizeAngle(Delta);
Delta.x = (Delta.x / Smooth) + Angle1.x;
Delta.y = (Delta.y / Smooth) + Angle1.y;
return Delta;
}
float CMath::FOV(const Vector3 Angle1, const Vector3 Angle2) {
Vector3 Delta = { Angle1.x - Angle2.x, Angle1.y - Angle2.y, 0 };
Delta = NormalizeAngle(Delta);
return sqrt((Delta.x * Delta.x) + (Delta.y * Delta.y));
}

