Skip to content

Commit

Permalink
Move fmodf, atan2f, sinf, and cosf to std:: namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
LagoLunatic committed Aug 8, 2024
1 parent 864847d commit 707fcec
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 39 deletions.
12 changes: 6 additions & 6 deletions src/JSystem/JStudio/JStudio/jstudio-math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ namespace math {

/* 8026E610-8026E778 .text getRotation_xyz__Q27JStudio4mathFPA4_ffff */
void getRotation_xyz(MtxP param_1, f32 x, f32 y, f32 z) {
f32 cosx = i_cosf(DEG_TO_RAD(x));
f32 sinx = i_sinf(DEG_TO_RAD(x));
f32 cosy = i_cosf(DEG_TO_RAD(y));
f32 siny = i_sinf(DEG_TO_RAD(y));
f32 cosz = i_cosf(DEG_TO_RAD(z));
f32 sinz = i_sinf(DEG_TO_RAD(z));
f32 cosx = std::cosf(DEG_TO_RAD(x));
f32 sinx = std::sinf(DEG_TO_RAD(x));
f32 cosy = std::cosf(DEG_TO_RAD(y));
f32 siny = std::sinf(DEG_TO_RAD(y));
f32 cosz = std::cosf(DEG_TO_RAD(z));
f32 sinz = std::sinf(DEG_TO_RAD(z));
f32 cosxcosz = cosx * cosz;
f32 cosxsinz = cosx * sinz;
f32 sinxcosz = sinx * cosz;
Expand Down
2 changes: 1 addition & 1 deletion src/JSystem/JUtility/JUTGamePad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ u32 JUTGamePad::CStick::update(s8 x_val, s8 y_val, EStickMode mode, EWhichStick
mAngle = -0x4000;
}
} else {
mAngle = 10430.379f * atan2f(mPosX, -mPosY);
mAngle = 10430.379f * std::atan2f(mPosX, -mPosY);
}
}

Expand Down
21 changes: 4 additions & 17 deletions src/PowerPC_EABI_Support/MSL/MSL_C/MSL_Common/Include/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ inline double fabs(double f) {

double floor(double);
double fmod(double, double);
inline float fmodf(float f1, float f2) {
return fmod(f1, f2);
}

double frexp(double, int*);
double ldexp(double, int);
Expand Down Expand Up @@ -85,27 +82,17 @@ extern inline double sqrt(double x) {
return HUGE_VALF;
}

inline float atan2f(float y, float x) {
return (float)atan2(y, x);
}

// these are duplicated due to sinf/cosf having a symbol, but
// still being used as inlines elsewhere
inline float i_sinf(float x) {
return sin(x);
}

inline float i_cosf(float x) {
return cos(x);
}

#ifdef __cplusplus
};


namespace std {
inline float fabsf(float f) { return fabs(f); }
inline float abs(float f) { return fabsf(f); }
inline float fmodf(float x, float y) { return fmod(x, y); }
inline float atan2f(float y, float x) { return (float)atan2(y, x); }
inline float sinf(float x) { return sin(x); }
inline float cosf(float x) { return cos(x); }
}; // namespace std
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/SSystem/SComponent/c_math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ float cM_rnd(void) {
r0 = (r0 * 0xAB) % 0x763D;
r1 = (r1 * 0xAC) % 0x7663;
r2 = (r2 * 0xAA) % 0x7673;
return std::fabsf(fmod(r0 / 30269.0f + r1 / 30307.0f + r2 / 30323.0f, 1.0));
return std::fabsf(std::fmodf(r0 / 30269.0f + r1 / 30307.0f + r2 / 30323.0f, 1.0));
}

/* 802463B0-802463E8 .text cM_rndF__Ff */
Expand Down
4 changes: 2 additions & 2 deletions src/d/d_com_inf_game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1045,8 +1045,8 @@ int dComIfGd_setShadow(u32 id, s8 param_2, J3DModel* pModel, cXyz* pPos, f32 par

int sid = dComIfGd_setRealShadow2(id, param_2, pModel, pPos, param_5, y - param_8, param_10);
if (sid == 0) {
cXyz i_pos(pPos->x, y, pPos->z);
dComIfGd_setSimpleShadow2(&i_pos, param_8, param_6, pFloorPoly, rotY, param_12, pTexObj);
cXyz pos(pPos->x, y, pPos->z);
dComIfGd_setSimpleShadow2(&pos, param_8, param_6, pFloorPoly, rotY, param_12, pTexObj);
}
return sid;
}
Expand Down
2 changes: 1 addition & 1 deletion src/d/d_drawlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ f32 cM_rnd_c::get() {
m0 = (m0 * 171) % 30269;
m4 = (m4 * 172) % 30307;
m8 = (m8 * 170) % 30323;
return std::fabsf(fmod((m0 / 30269.0f) + (m4 / 30307.0f) + (m8 / 30323.0f), 1.0f));
return std::fabsf(std::fmodf((m0 / 30269.0f) + (m4 / 30307.0f) + (m8 / 30323.0f), 1.0f));
}

f32 cM_rnd_c::getF(f32 m) {
Expand Down
6 changes: 3 additions & 3 deletions src/d/d_kankyo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,9 +583,9 @@ void dScnKy_env_light_c::setSunpos() {
var_f1 = g_env_light.mCurTime + 345.0f;
}

sp8.x = i_sinf(DEG_TO_RAD(var_f1)) * 80000.0f;
sp8.y = i_cosf(DEG_TO_RAD(var_f1)) * 80000.0f;
sp8.z = i_cosf(DEG_TO_RAD(var_f1)) * -48000.0f;
sp8.x = std::sinf(DEG_TO_RAD(var_f1)) * 80000.0f;
sp8.y = std::cosf(DEG_TO_RAD(var_f1)) * 80000.0f;
sp8.z = std::cosf(DEG_TO_RAD(var_f1)) * -48000.0f;

if (!dComIfGp_event_runCheck() || g_env_light.mInitAnimTimer != 0) {
mSunPos.x = camera_p->mLookat.mEye.x + sp8.x;
Expand Down
16 changes: 8 additions & 8 deletions src/d/d_kankyo_rain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1477,12 +1477,12 @@ void dKyr_drawSun(Mtx drawMtx, cXyz* pPos, GXColor& reg0, u8** pImg) {
dKyr_get_vectle_calc(&pCamera->mLookat.mEye, &pCamera->mLookat.mCenter, &camfwd);

f32 cam_distXZ = sqrtf(camfwd.x*camfwd.x + camfwd.z*camfwd.z);
f32 cam_theta = atan2f(camfwd.x, camfwd.z);
f32 cam_phi = atan2f(camfwd.y, cam_distXZ);
f32 cam_theta = std::atan2f(camfwd.x, camfwd.z);
f32 cam_phi = std::atan2f(camfwd.y, cam_distXZ);

f32 moon_distXZ = sqrtf(moonPos.x*moonPos.x + moonPos.z*moonPos.z);
f32 moon_theta = atan2f(moonPos.x, moonPos.z);
f32 moon_phi = atan2f(moonPos.y, moon_distXZ);
f32 moon_theta = std::atan2f(moonPos.x, moonPos.z);
f32 moon_phi = std::atan2f(moonPos.y, moon_distXZ);

f32 angle = 45.0f + (((moon_theta - cam_theta) / -8.0f) * moon_phi) * 360.0f;
MTXRotDeg(rotMtx, 'Z', angle);
Expand Down Expand Up @@ -1575,14 +1575,14 @@ void dKyr_drawSun(Mtx drawMtx, cXyz* pPos, GXColor& reg0, u8** pImg) {
snap_sunmoon_proc(&sunPos, 9);

f32 sun_distXZ = sqrtf(sunPos.x*sunPos.x + sunPos.z*sunPos.z);
f32 sun_theta = atan2f(sunPos.x, sunPos.z);
f32 sun_phi = atan2f(sunPos.y, sun_distXZ);
f32 sun_theta = std::atan2f(sunPos.x, sunPos.z);
f32 sun_phi = std::atan2f(sunPos.y, sun_distXZ);

dKyr_get_vectle_calc(&pCamera->mLookat.mEye, &pCamera->mLookat.mCenter, &camfwd);

f32 cam_distXZ = sqrtf(camfwd.x*camfwd.x + camfwd.z*camfwd.z);
f32 cam_theta = atan2f(camfwd.x, camfwd.z);
f32 cam_phi = atan2f(camfwd.y, cam_distXZ);
f32 cam_theta = std::atan2f(camfwd.x, camfwd.z);
f32 cam_phi = std::atan2f(camfwd.y, cam_distXZ);

MTXRotDeg(rotMtx, 'Z', -50.0f + (360.0f * ((sun_theta - cam_theta) / -8.0f)));
MTXConcat(camMtx, rotMtx, camMtx);
Expand Down

0 comments on commit 707fcec

Please sign in to comment.