Merge pull request #267 from robojumper/degree

Degree WIP
This commit is contained in:
robojumper
2025-11-22 15:39:27 +01:00
committed by GitHub
7 changed files with 260 additions and 23 deletions
+2
View File
@@ -8,6 +8,8 @@
namespace cM {
s16 atan2s(f32, f32);
f32 atan2f(f32, f32);
void initRnd(s32);
f32 rnd();
int rndInt(int max);
+10 -2
View File
@@ -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:
+65
View File
@@ -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