Skip to content

Commit

Permalink
d_cam_param work
Browse files Browse the repository at this point in the history
  • Loading branch information
magcius committed Jul 13, 2024
1 parent 2a65dfd commit 3d8c73e
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 54 deletions.
2 changes: 1 addition & 1 deletion include/SSystem/SComponent/c_angle.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class cSAngle {
cSAngle(const cSAngle&);
cSAngle(s16);
cSAngle(float);
s16 Val() const { return this->mAngle; }
s16 Val() const { return mAngle; }
// void Set(s16 angle) { this->mAngle = angle; }
void Val(const cSAngle&);
void Val(s16);
Expand Down
69 changes: 50 additions & 19 deletions include/d/d_cam_param.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,38 @@

struct dCamera__Style {
/* 0x00 */ u32 m00;
/* 0x04 */ u8 m04[0x84 - 0x04];
/* 0x04 */ u32 m04;
/* 0x08 */ u32 m08;
/* 0x0C */ u32 m0C;
/* 0x10 */ u32 m10;
/* 0x14 */ u32 m14;
/* 0x18 */ u32 m18;
/* 0x1C */ f32 centerHeightBase;
/* 0x20 */ f32 centerHeightUpper;
/* 0x24 */ f32 centerHeightLower;
/* 0x28 */ f32 lockonCenterHeightMin;
/* 0x2C */ f32 lockonCenterHeightMax;
/* 0x30 */ u32 m30;
/* 0x34 */ u32 m34;
/* 0x38 */ u32 m38;
/* 0x3C */ f32 m3C;
/* 0x40 */ f32 m40;
/* 0x44 */ u32 m44;
/* 0x48 */ u32 m48;
/* 0x4C */ u32 m4C;
/* 0x50 */ f32 lockonLatitudeMin;
/* 0x54 */ f32 lockonLatitudeMax;
/* 0x58 */ u32 m58;
/* 0x5C */ u32 m5C;
/* 0x60 */ u32 m60;
/* 0x64 */ f32 lockonLongitudeMin;
/* 0x68 */ f32 lockonLongitudeMax;
/* 0x6C */ f32 fovyBase;
/* 0x70 */ f32 fovyUpper;
/* 0x74 */ f32 fovyLower;
/* 0x78 */ f32 lockonFovyMin;
/* 0x7C */ f32 lockonFovyMax;
/* 0x80 */ u16 flag;
}; // Size: 0x84

class dCstick_c {
Expand All @@ -19,7 +50,7 @@ class dCstick_c {
dCstick_c();
virtual ~dCstick_c() {}

void Shift(u32);
s32 Shift(u32);
};

class dCamBGChk_c {
Expand Down Expand Up @@ -111,8 +142,8 @@ class dCamSetup_c {
dCamSetup_c();
virtual ~dCamSetup_c();

void CheckLatitudeRange(s16*);
void FanBank();
bool CheckLatitudeRange(s16*);
f32 FanBank();

public:
/* 0x0D0 */ dCstick_c mCstick;
Expand All @@ -135,26 +166,26 @@ class dCamParam_c {
void Val(s32, int) {}
BOOL Change(s32);
s32 SearchStyle(u32);
void ratiof(f32, f32, f32, f32);
void DefaultRadius(f32*);
f32 ratiof(f32, f32, f32, f32);
BOOL DefaultRadius(f32*);
void RadiusRatio(f32);
void CenterHeight(f32);
void Fovy(f32);
void LockonLongitude(f32);
void LockonLatitude(f32);
void LockonFovy(f32);
void LockonCenterHeight(f32);
f32 CenterHeight(f32);
f32 Fovy(f32);
s16 LockonLongitude(f32);
s16 LockonLatitude(f32);
f32 LockonFovy(f32);
f32 LockonCenterHeight(f32);
};

class dCamMath {
public:
void rationalBezierRatio(f32, f32);
void customRBRatio(f32, f32);
void zoomFovy(f32, f32);
void xyzRotateX(cXyz&, cSAngle);
void xyzRotateY(cXyz&, cSAngle);
void xyzHorizontalDistance(cXyz&, cXyz&);
void xyzProjPosOnYZ(cSAngle, cXyz&, cXyz&);
static f32 rationalBezierRatio(f32, f32);
static f32 customRBRatio(f32, f32);
static f32 zoomFovy(f32, f32);
static cXyz xyzRotateX(cXyz&, cSAngle);
static cXyz xyzRotateY(cXyz&, cSAngle);
static f32 xyzHorizontalDistance(cXyz&, cXyz&);
static cXyz xyzProjPosOnYZ(cSAngle, cXyz&, cXyz&);
};

#endif /* D_CAM_PARAM_H */
150 changes: 116 additions & 34 deletions src/d/d_cam_param.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,84 @@
//

#include "d/d_cam_param.h"
#include "d/d_kankyo_wether.h"
#include "m_Do/m_Do_mtx.h"
#include "SSystem/SComponent/c_math.h"

/* 800AF384-800AF4F4 .text rationalBezierRatio__8dCamMathFff */
void dCamMath::rationalBezierRatio(f32, f32) {
f32 dCamMath::rationalBezierRatio(f32 x, f32 y) {
/* Nonmatching */
}

/* 800AF4F4-800AF544 .text customRBRatio__8dCamMathFff */
void dCamMath::customRBRatio(f32, f32) {
f32 dCamMath::customRBRatio(f32 x, f32 y) {
/* Nonmatching */
if (x > 0.7071068f) {
if (x < 0.0f) {
return -1.0f;
} else {
return 1.0f;
}
}

return rationalBezierRatio(x * 1.414214f, y);
}

/* 800AF544-800AF5A0 .text zoomFovy__8dCamMathFff */
void dCamMath::zoomFovy(f32, f32) {
/* Nonmatching */
f32 dCamMath::zoomFovy(f32 deg, f32 y) {
cDegree d(deg);
return cAngle::r2d(cM_atan2f(d.Sin(), d.Cos() * y));
}

/* 800AF5A0-800AF608 .text xyzRotateX__8dCamMathFR4cXyz7cSAngle */
void dCamMath::xyzRotateX(cXyz&, cSAngle) {
/* Nonmatching */
cXyz dCamMath::xyzRotateX(cXyz& vec, cSAngle angle) {
cXyz ret;
Mtx mtx;
cMtx_XrotS(mtx, angle.Val());
cMtx_multVec(mtx, &vec, &ret);
return ret;
}

/* 800AF608-800AF670 .text xyzRotateY__8dCamMathFR4cXyz7cSAngle */
void dCamMath::xyzRotateY(cXyz&, cSAngle) {
/* Nonmatching */
cXyz dCamMath::xyzRotateY(cXyz& vec, cSAngle angle) {
cXyz ret;
Mtx mtx;
cMtx_YrotS(mtx, angle.Val());
cMtx_multVec(mtx, &vec, &ret);
return ret;
}

/* 800AF670-800AF734 .text xyzHorizontalDistance__8dCamMathFR4cXyzR4cXyz */
void dCamMath::xyzHorizontalDistance(cXyz&, cXyz&) {
/* Nonmatching */
f32 dCamMath::xyzHorizontalDistance(cXyz& a, cXyz& b) {
f64 x = a.x - b.x;
f64 z = a.z - b.z;
f64 distSq = x*x + z*z;
return sqrt(distSq);
}

/* 800AF734-800AF810 .text xyzProjPosOnYZ__8dCamMathF7cSAngleR4cXyzR4cXyz */
void dCamMath::xyzProjPosOnYZ(cSAngle, cXyz&, cXyz&) {
cXyz dCamMath::xyzProjPosOnYZ(cSAngle angle, cXyz& a, cXyz& b) {
/* Nonmatching */
cXyz line;
cXyz rot;
line = b - a;
rot = xyzRotateY(line, -angle);
rot.x = 0.0f;
line = xyzRotateY(rot, angle);
return b + line;
}

/* 800AF810-800AF838 .text __ct__9dCstick_cFv */
dCstick_c::dCstick_c() {
/* Nonmatching */
m00 = 0.2f;
m04 = 0.95f;
m08 = 6;
}

/* 800AF838-800AF840 .text Shift__9dCstick_cFUl */
void dCstick_c::Shift(u32) {
/* Nonmatching */
s32 dCstick_c::Shift(u32) {
return 0;
}

/* 800AF840-800AF8F4 .text __ct__11dCamBGChk_cFv */
Expand All @@ -56,13 +90,12 @@ dCamBGChk_c::dCamBGChk_c() {
}

/* 800AF8F4-800AF930 .text __ct__11dCamParam_cFl */
dCamParam_c::dCamParam_c(s32) {
/* Nonmatching */
dCamParam_c::dCamParam_c(s32 styleIdx) {
Change(styleIdx);
}

/* 800AF930-800AF978 .text __dt__11dCamParam_cFv */
dCamParam_c::~dCamParam_c() {
/* Nonmatching */
}

/* 800AF978-800AF9BC .text Change__11dCamParam_cFl */
Expand Down Expand Up @@ -90,13 +123,40 @@ s32 dCamParam_c::SearchStyle(u32 r4) {
}

/* 800AFA04-800AFAA4 .text ratiof__11dCamParam_cFffff */
void dCamParam_c::ratiof(f32, f32, f32, f32) {
/* Nonmatching */
f32 dCamParam_c::ratiof(f32 t, f32 upper, f32 lower, f32 base) {
if (t == 0.0f)
return base;

f32 ret = base;
if (t < 0.0f) {
ret += (ret - lower) * dCamMath::customRBRatio(t, 0.25f);
} else {
ret += (upper - ret) * dCamMath::customRBRatio(t, 0.25f);
}
return ret;
}

/* 800AFAA4-800AFB00 .text DefaultRadius__11dCamParam_cFPf */
void dCamParam_c::DefaultRadius(f32*) {
BOOL dCamParam_c::DefaultRadius(f32* radius) {
/* Nonmatching */
f32 min, max;
if (mpStyle->m3C < mpStyle->m40) {
min = mpStyle->m3C;
max = mpStyle->m40;
} else {
min = mpStyle->m40;
max = mpStyle->m3C;
}

if (*radius > max) {
*radius = max;
return FALSE;
} else if (*radius < min) {
*radius = min;
return FALSE;
} else {
return TRUE;
}
}

/* 800AFB00-800AFB88 .text RadiusRatio__11dCamParam_cFf */
Expand All @@ -105,33 +165,42 @@ void dCamParam_c::RadiusRatio(f32) {
}

/* 800AFB88-800AFBB8 .text CenterHeight__11dCamParam_cFf */
void dCamParam_c::CenterHeight(f32) {
f32 dCamParam_c::CenterHeight(f32 t) {
return ratiof(t, mpStyle->centerHeightUpper, mpStyle->centerHeightLower, mpStyle->centerHeightBase);
/* Nonmatching */
}

/* 800AFBB8-800AFBE8 .text Fovy__11dCamParam_cFf */
void dCamParam_c::Fovy(f32) {
/* Nonmatching */
f32 dCamParam_c::Fovy(f32 t) {
return ratiof(t, mpStyle->fovyUpper, mpStyle->fovyLower, mpStyle->fovyBase);
}

/* 800AFBE8-800AFC74 .text LockonLongitude__11dCamParam_cFf */
void dCamParam_c::LockonLongitude(f32) {
/* Nonmatching */
s16 dCamParam_c::LockonLongitude(f32 t) {
cSAngle ret(mpStyle->lockonLongitudeMin);
ret += (cSAngle(mpStyle->lockonLongitudeMax) - ret) * t;
return ret.Val();
}

/* 800AFC74-800AFD00 .text LockonLatitude__11dCamParam_cFf */
void dCamParam_c::LockonLatitude(f32) {
/* Nonmatching */
s16 dCamParam_c::LockonLatitude(f32 t) {
cSAngle ret(mpStyle->lockonLatitudeMin);
ret += (cSAngle(mpStyle->lockonLatitudeMax) - ret) * t;
return ret.Val();
}

/* 800AFD00-800AFD20 .text LockonFovy__11dCamParam_cFf */
void dCamParam_c::LockonFovy(f32) {
/* Nonmatching */
f32 dCamParam_c::LockonFovy(f32 t) {
f32 ret = mpStyle->lockonFovyMin;
ret += t * (mpStyle->lockonFovyMax - ret);
return ret;
}

/* 800AFD20-800AFD40 .text LockonCenterHeight__11dCamParam_cFf */
void dCamParam_c::LockonCenterHeight(f32) {
/* Nonmatching */
f32 dCamParam_c::LockonCenterHeight(f32 t) {
f32 ret = mpStyle->lockonCenterHeightMin;
ret += t * (mpStyle->lockonCenterHeightMax - ret);
return ret;
}

/* 800AFD40-800AFEE0 .text __ct__11dCamSetup_cFv */
Expand All @@ -145,11 +214,24 @@ dCamSetup_c::~dCamSetup_c() {
}

/* 800AFF40-800AFFB0 .text CheckLatitudeRange__11dCamSetup_cFPs */
void dCamSetup_c::CheckLatitudeRange(s16*) {
/* Nonmatching */
bool dCamSetup_c::CheckLatitudeRange(s16* angle) {
s16 upper = cAngle::d2s(m060);
s16 lower = cAngle::d2s(m05C);

if (*angle > upper) {
*angle = upper;
return false;
}

if (*angle < lower) {
*angle = lower;
return false;
}

return true;
}

/* 800AFFB0-800B0004 .text FanBank__11dCamSetup_cFv */
void dCamSetup_c::FanBank() {
/* Nonmatching */
f32 dCamSetup_c::FanBank() {
return m080 + cM_rndFX(m084) * dKyw_get_wind_pow();
}

0 comments on commit 3d8c73e

Please sign in to comment.