diff options
| author | robojumper <robojumper@gmail.com> | 2025-09-13 10:11:41 +0200 |
|---|---|---|
| committer | robojumper <robojumper@gmail.com> | 2025-11-18 16:59:03 +0100 |
| commit | fd4adf5f105e1790a9366b33a6cb7de6fd210266 (patch) | |
| tree | dd5bbfd60a7c56ce029f6ffdfbfed4d600a21fa7 /include | |
| parent | 532e06a35a7045e27cfc0de698a16b697ad80415 (diff) | |
Degree WIP
Diffstat (limited to 'include')
| -rw-r--r-- | include/c/c_math.h | 2 | ||||
| -rw-r--r-- | include/m/m_angle.h | 12 | ||||
| -rw-r--r-- | include/toBeSorted/deg_angle_util.h | 65 |
3 files changed, 77 insertions, 2 deletions
diff --git a/include/c/c_math.h b/include/c/c_math.h index ba284408..914eff24 100644 --- a/include/c/c_math.h +++ b/include/c/c_math.h @@ -8,6 +8,8 @@ namespace cM { s16 atan2s(f32, f32); +f32 atan2f(f32, f32); + void initRnd(s32); f32 rnd(); int rndInt(int max); diff --git a/include/m/m_angle.h b/include/m/m_angle.h index ab5e1997..393a047a 100644 --- a/include/m/m_angle.h +++ b/include/m/m_angle.h @@ -98,8 +98,12 @@ struct mAng { return rad * sRadToAng; } - static f32 ang2deg_c(f32 rad) { - return rad * sAngToDeg; + static f32 ang2deg_c(f32 ang) { + return ang * sAngToDeg; + } + + static f32 rad2deg_c(f32 rad) { + return rad * sRadToDeg; } static f32 rad2deg(f32 rad) { @@ -124,6 +128,10 @@ struct mAng { return rad * (65536.0f / (2.f * M_PI)); } + static f32 deg2rad_c(f32 deg) { + return deg * sDegToRad; + } + s16 mVal; private: diff --git a/include/toBeSorted/deg_angle_util.h b/include/toBeSorted/deg_angle_util.h new file mode 100644 index 00000000..cb2406a6 --- /dev/null +++ b/include/toBeSorted/deg_angle_util.h @@ -0,0 +1,65 @@ +#ifndef TOBESORTED_DEG_ANGLE_UTIL_H +#define TOBESORTED_DEG_ANGLE_UTIL_H + +#include "common.h" +#include "m/m_vec.h" + +struct dDegree { +public: + /** Wraps a degree angle so that value is within [-180.0f; 180.0f] */ + static f32 adjust(f32 value); + /** Canonicalizes a degree angle so that value is within [-180.0f; 180.0f) */ + static f32 canonicalize(f32 value); + + f32 rotate180F() const; + void rotate180(); + f32 abs() const; + + f32 sin() const; + f32 cos() const; + f32 tan() const; + f32 tan2() const; + f32 toRad() const; + s16 toIdx(); // can't be const... + + void Set(f32 v) { + value = adjust(v); + } + + f32 operator-(const dDegree &other) const { + return value - other.value; + } + + f32 operator+(const dDegree &other) const { + return value + other.value; + } + + dDegree() : value(0.0f) {} + dDegree(f32 value) : value(adjust(value)) {} + dDegree(const dDegree &other) : value(other.value) {} + + /* 0x0 */ f32 value; +}; + +struct dPolar { +public: + dPolar(f32 r, f32 u, f32 v); + dPolar(const mVec3_c &v); + + dPolar *canonicalize(); + + void Set(f32 r, f32 u, f32 v); + + void setCartesian(const mVec3_c &v); + mVec3_c toCartesian() const; + + f32 SetR(f32 r); + f32 SetU(f32 u); + f32 SetV(f32 v); + + /* 0x0 */ f32 R; + /* 0x4 */ dDegree U; + /* 0x8 */ dDegree V; +}; + +#endif |
