Clean up angle constants and conversions (#1135)

* Add angle conversion constants and macros

* Replace angle literals with hex instead of decimal
This commit is contained in:
LagoLunatic
2026-07-22 20:13:31 -04:00
committed by GitHub
parent bf372802ca
commit 96347ab502
85 changed files with 261 additions and 267 deletions
+21 -27
View File
@@ -3,6 +3,20 @@
#include "SSystem/SComponent/c_xyz.h"
#define RAD2DEG_CONSTANT (180.0f / M_PI) // 57.29577951f
#define DEG2RAD_CONSTANT (M_PI / 180.0f) // 0.017453292f
#define DEG2S_CONSTANT (0x8000 / 180.0f) // 182.04445f
#define S2DEG_CONSTANT (180.0f / 0x8000) // 0.005493164f
#define S2RAD_CONSTANT (M_PI / 0x8000) // 9.58738e-5f / 9.58738e-05f / 0.0000958738f
#define RAD2S_CONSTANT (0x8000 / M_PI) // 10430.378f
#define RAD2DEG(x) ((x) * RAD2DEG_CONSTANT)
#define DEG2RAD(x) ((x) * DEG2RAD_CONSTANT)
#define DEG2S(x) ((s16)((x) * DEG2S_CONSTANT))
#define S2DEG(x) ((x) * S2DEG_CONSTANT)
#define S2RAD(x) ((x) * S2RAD_CONSTANT)
#define RAD2S(x) ((x) * RAD2S_CONSTANT)
class cSAngle {
private:
s16 mAngle;
@@ -59,33 +73,13 @@ cSAngle operator+(short, const cSAngle&);
cSAngle operator-(short, const cSAngle&);
struct cAngle {
static f32 Radian_to_Degree(f32 rad) {
return rad * (180.0f / M_PI);
}
static f32 Degree_to_Radian(f32 deg) {
return deg * (M_PI / 180.0f);
}
static s16 Degree_to_SAngle(f32 deg) {
return deg * (65536.0f / 360.0f);
}
static f32 SAngle_to_Degree(s16 angle) {
return angle * (360.0f / 65536.0f);
}
static f32 SAngle_to_Radian(s16 angle) {
return angle * ((2.0f * M_PI) / 65536.0f);
}
static f32 SAngle_to_Normal(s16 angle) {
return angle * (2.0f / 65536.0f);
}
static s16 Radian_to_SAngle(f32 rad) {
return rad * (65536.0f / (2.0f * M_PI));
}
static f32 Radian_to_Degree(f32 rad) { return RAD2DEG(rad); }
static f32 Degree_to_Radian(f32 deg) { return DEG2RAD(deg); }
static s16 Degree_to_SAngle(f32 deg) { return DEG2S(deg); }
static f32 SAngle_to_Degree(s16 angle) { return S2DEG(angle); }
static f32 SAngle_to_Radian(s16 angle) { return S2RAD(angle); }
static s16 Radian_to_SAngle(f32 rad) { return RAD2S(rad); }
static f32 SAngle_to_Normal(s16 angle) { return angle * (1.0f / 0x8000); }
/* Converts Radian value into Degree value */
static f32 r2d(f32 r) { return Radian_to_Degree(r); }
+4 -3
View File
@@ -2,6 +2,7 @@
#define C_MATH_H
#include "JSystem/JMath/JMATrigonometric.h"
#include "SSystem/SComponent/c_angle.h"
s16 cM_rad2s(float rad);
u16 U_GetAtanTable(float, float);
@@ -40,7 +41,7 @@ inline f32 cM_ssin(s16 x) {
}
inline s16 cM_deg2s(f32 deg) {
return deg * 182.04445f;
return DEG2S(deg);
}
inline f32 cM_fcos(f32 x) {
@@ -52,11 +53,11 @@ inline f32 cM_fsin(f32 x) {
}
inline f32 cM_sht2d(f32 v) {
return v * 0.005493164f;
return S2DEG(v);
}
inline f32 cM_s2rad(s16 x) {
return x * 9.58738e-05f;
return S2RAD(x);
}
#endif /* C_MATH_H */