diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 55c14069..4ffd8a8c 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -45930,7 +45930,7 @@ lbl_8057CD8C = .sdata2:0x8057CD8C; // type:object size:0x4 data:float sHalfCircleDeg__4mAng = .sdata2:0x8057CD90; // type:object size:0x4 data:float sAngToDeg__4mAng = .sdata2:0x8057CD94; // type:object size:0x4 data:float sAngToRad__4mAng = .sdata2:0x8057CD98; // type:object size:0x4 data:float -NotSure__4mAng = .sdata2:0x8057CD9C; // type:object size:0x4 data:float +sAngToNorm__4mAng = .sdata2:0x8057CD9C; // type:object size:0x4 data:float sDegToRad__4mAng = .sdata2:0x8057CDA0; // type:object size:0x4 data:float sDegToAng__4mAng = .sdata2:0x8057CDA4; // type:object size:0x4 data:float sRadToAng__4mAng = .sdata2:0x8057CDA8; // type:object size:0x4 data:float diff --git a/include/c/c_math.h b/include/c/c_math.h index 5bb3504b..8b95bf71 100644 --- a/include/c/c_math.h +++ b/include/c/c_math.h @@ -11,6 +11,11 @@ int rndInt(int max); f32 rndF(f32 max); f32 rndFX(f32 amp); +template +inline T minMaxLimit(T val, T min, T max) { + return (T)((T)val < (T)min ? (T)min : ((T)val > (T)max ? (T)max : (T)val)); +} + } // namespace cM #endif diff --git a/include/d/col/bg/d_bg_s_acch.h b/include/d/col/bg/d_bg_s_acch.h index 15b6325d..d24402f3 100644 --- a/include/d/col/bg/d_bg_s_acch.h +++ b/include/d/col/bg/d_bg_s_acch.h @@ -488,6 +488,10 @@ class dBgS_Acch : public cBgS_Chk, public dBgS_Chk { return mFlags & GROUND_HIT; } + dBgS_GndChk &GetGnd() { + return mGnd; + } + public: /* 0x040 */ u32 mFlags; /* 0x044 */ mVec3_c *mpPos; diff --git a/include/egg/math/eggMath.h b/include/egg/math/eggMath.h index 330b0be2..ddab706a 100644 --- a/include/egg/math/eggMath.h +++ b/include/egg/math/eggMath.h @@ -39,10 +39,6 @@ class Math { return (T)0; } - static T clamp(T x, T low, T high) { - return (x < low ? low : (x > high ? high : x)); - } - static T sqrt(T); static T sin(T); static T cos(T); diff --git a/include/egg/math/eggQuat.h b/include/egg/math/eggQuat.h index c7642e79..df67e10d 100644 --- a/include/egg/math/eggQuat.h +++ b/include/egg/math/eggQuat.h @@ -4,31 +4,32 @@ #include "common.h" #include "egg/math/eggVector.h" - namespace EGG { -struct Quatf : public Vector3f { +struct Quatf { Quatf() {} - Quatf(f32 f, Vector3f v) : w(f), Vector3f(v) {} - Quatf(f32 f, f32 x, f32 y, f32 z) : w(f), Vector3f(Vector3f(x, y, z)) {} + Quatf(f32 f, const Vector3f &v) : w(f), v(v) {} + Quatf(f32 f, f32 x, f32 y, f32 z) : w(f), v(Vector3f(x, y, z)) {} ~Quatf() {} friend Quatf operator*(const Quatf &q, const Vector3f &vec) { - Vector3f crossed = q.cross(vec); + Vector3f crossed = q.v.cross(vec); Vector3f scaled = vec * q.w; - Quatf ret = Quatf(-q.Vector3f::dot(vec), crossed + scaled); + Quatf ret = Quatf(-q.v.dot(vec), crossed + scaled); return ret; } - // TODO: Implement - friend Quatf operator*(const Quatf &u, const Quatf &v) { - Vector3f cross = u.cross(v); - Vector3f v_mul_w = u.w * v; - Vector3f u_mul_w = v.w * v; - Vector3f added_2 = u_mul_w + (cross + v_mul_w); - Quatf out = Quatf(u.w * v.w - u.Vector3f::dot(v), added_2); - return out; - }; + friend Quatf operator*(const Quatf &lhs, const Quatf &rhs) { + Vector3f cross = lhs.v.cross(rhs.v); + + Vector3f scaledRhs = lhs.w * rhs.v; + Vector3f tmp0 = cross + scaledRhs; + + Vector3f scaledLhs = rhs.w * lhs.v; + Vector3f tmp1 = tmp0 + scaledLhs; + + return Quatf(lhs.w * rhs.w - lhs.v.dot(rhs.v), tmp1); + } /* 8049b390 */ void set(f32 fw, f32 fx, f32 fy, f32 fz); /* */ void set(f32 f, const Vector3f &vec); @@ -47,27 +48,17 @@ struct Quatf : public Vector3f { /* */ void makeVectorRotationLimit(Vector3f &, Vector3f &, f32); /* 8049bbb0 */ void makeVectorRotation(Vector3f &, Vector3f &); - f32 dot(const Quatf &q) const { - return w * w + q.x * q.x + q.y * q.y + q.z * q.z; - } - f32 length() const { - return Math::sqrt(dot(*this)); - } void multScalar(f32 s) { w *= s; - x *= s; - y *= s; - z *= s; + v.x *= s; + v.y *= s; + v.z *= s; } void setUnit() { set(1.0f, 0.0f, 0.0f, 0.0f); } - // union { - // Vector3f v; - // struct { - // f32 x, y, z; - // }; - // }; + + Vector3f v; f32 w; }; diff --git a/include/egg/math/eggVector.h b/include/egg/math/eggVector.h index c54e6f0d..069394b0 100644 --- a/include/egg/math/eggVector.h +++ b/include/egg/math/eggVector.h @@ -5,7 +5,6 @@ #include "egg/math/eggMath.h" #include "nw4r/math.h" - namespace EGG { struct Vector3f : public nw4r::math::VEC3 { @@ -28,11 +27,11 @@ struct Vector3f : public nw4r::math::VEC3 { } friend Vector3f operator*(f32 f, const Vector3f &v) { - return v.operator*(f); + return Vector3f(v.x * f, v.y * f, v.z * f); } // __pl__Q23EGG8Vector3fCFRCQ23EGG8Vector3f - Vector3f operator+(const Vector3f &v) { + Vector3f operator+(const Vector3f &v) const { return Vector3f(x + v.x, y + v.y, z + v.z); } diff --git a/include/m/m_angle.h b/include/m/m_angle.h index e2af98c5..e92c0d40 100644 --- a/include/m/m_angle.h +++ b/include/m/m_angle.h @@ -4,6 +4,7 @@ #include "c/c_math.h" #include "common.h" #include "m/m_vec.h" +#include "math.h" #include "nw4r/math/math_triangular.h" struct mAng { @@ -51,41 +52,48 @@ struct mAng { s16 mVal; + f32 degree() const { + return (360.0f / 65536.0f) * mVal; + } + static mAng fromDeg(f32 deg) { return deg * sDegToAng; } - static mAng fromRad(f32 rad) { + f32 radian() const { + return ((2.f * M_PI) / 65536.0f) * mVal; + } + static s16 fromRad(f32 rad) { return rad * sRadToAng; } - static f32 Radian_to_Degree(f32 rad) { - return rad * 57.2957763671875f; + static f32 rad2deg(f32 rad) { + return rad * (360.f / (2.f * M_PI)); } - static f32 Degree_to_Radian(f32 deg) { - return deg * 0.017453292f; + static f32 deg2rad(f32 deg) { + return deg * ((2.f * M_PI) / 360.f); } - static s16 Degree_to_SAngle(f32 deg) { - return deg * 182.04444885253906f; + static s16 deg2short(f32 deg) { + return deg * (65536.0f / 360.0f); } - static f32 SAngle_to_Degree(s16 angle) { + static f32 short2deg(s16 angle) { return (360.0f / 65536.0f) * angle; } - static f32 SAngle_to_Radian(s16 angle) { - return 9.58738E-5f * angle; + static f32 short2rad(s16 angle) { + return ((2.f * M_PI) / 65536.0f) * angle; } - static f32 SAngle_to_Normal(s16 angle) { + static f32 short2norm(s16 angle) { return 3.0517578E-5f * angle; } - static s16 Radian_to_SAngle(f32 rad) { - return rad * 10430.378f; + static s16 rad2short(f32 rad) { + return rad * (65536.0f / (2.f * M_PI)); } private: static const f32 sHalfCircleDeg; static const f32 sAngToDeg; static const f32 sAngToRad; - static const f32 NotSure; + static const f32 sAngToNorm; static const f32 sDegToRad; static const f32 sDegToAng; static const f32 sRadToAng; diff --git a/include/m/m_mtx.h b/include/m/m_mtx.h index dd4cdf57..e3dabf65 100644 --- a/include/m/m_mtx.h +++ b/include/m/m_mtx.h @@ -8,6 +8,7 @@ #include "m/m_angle.h" #include "m/m_vec.h" #include "nw4r/types_nw4r.h" +#include "rvl/MTX/mtx.h" class mMtx_c : public EGG::Matrix34f { typedef f32 (*MtxRef)[4]; @@ -63,6 +64,18 @@ class mMtx_c : public EGG::Matrix34f { void rot(int, int); // does some werrd operation to rotate the matrix bool quatRelated(); + void trans(const mVec3_c &v) { + PSMTXTrans(*this, v.x, v.y, v.z); + } + void trans(f32 x, f32 y, f32 z) { + PSMTXTrans(*this, x, y, z); + } + + mMtx_c &operator+=(const mMtx_c &rhs) { + PSMTXConcat(*this, rhs, *this); + return *this; + } + public: static mMtx_c Identity; }; diff --git a/include/m/m_quat.h b/include/m/m_quat.h index 22355011..cf845858 100644 --- a/include/m/m_quat.h +++ b/include/m/m_quat.h @@ -8,11 +8,12 @@ class mQuat_c : public EGG::Quatf { public: mQuat_c() {} mQuat_c(f32 x, f32 y, f32 z, f32 w) : EGG::Quatf(w, x, y, z) {} - mQuat_c &operator=(const EGG::Quatf &rhs) { - *(EGG::Quatf *)this = rhs; + v = rhs.v; + w = rhs.w; return *this; } + void fn_802F2780(const mQuat_c &other); }; diff --git a/include/m/m_vec.h b/include/m/m_vec.h index 943d1de3..4e21dafc 100644 --- a/include/m/m_vec.h +++ b/include/m/m_vec.h @@ -9,7 +9,6 @@ #include "nw4r/types_nw4r.h" #include "rvl/MTX/vec.h" - class mAng; class mVec3_c : public EGG::Vector3f { @@ -226,6 +225,10 @@ class mVec3_c : public EGG::Vector3f { p->z = z; } + s16 ang() const { + return cM::atan2s(x * x, z * z); + } + static mVec3_c Zero; static mVec3_c Ex; static mVec3_c Ey; diff --git a/src/REL/d/a/obj/d_a_obj_tumble_weed.cpp b/src/REL/d/a/obj/d_a_obj_tumble_weed.cpp index ad811331..2c621019 100644 --- a/src/REL/d/a/obj/d_a_obj_tumble_weed.cpp +++ b/src/REL/d/a/obj/d_a_obj_tumble_weed.cpp @@ -5,11 +5,13 @@ #include "d/a/d_a_player.h" #include "d/a/obj/d_a_obj_base.h" #include "d/col/bg/d_bg_s.h" +#include "d/col/bg/d_bg_s_gnd_chk.h" #include "d/col/c/c_cc_d.h" #include "d/col/c/c_m3d_g_pla.h" #include "d/col/cc/d_cc_d.h" #include "d/col/cc/d_cc_s.h" #include "egg/math/eggMath.h" +#include "egg/math/eggQuat.h" #include "f/f_base.h" #include "m/m_angle.h" #include "m/m_mtx.h" @@ -252,7 +254,7 @@ bool dAcOTumbleWeed_c::checkSlope() { const f32 b = mVec3_c::Ey.cross(pla.mNormal).length(); mAng ang = mAng::fromRad(EGG::Math::abs(EGG::Math::atan2(b, a))); - return sLib::absDiff(ang, 0) > 182; + return sLib::absDiff(ang, 0) > mAng::deg2short(1); } bool dAcOTumbleWeed_c::checkCollect() { @@ -277,34 +279,29 @@ void dAcOTumbleWeed_c::doBreak() { } void dAcOTumbleWeed_c::calcMatrix() { - mMtx_c mtx0, mtx1, mtx2; - mQuat_c q0, q1, q2, q3; if (mField_0x98B) { - // Im not even trying - f32 vel_mag = PSVECMag(velocity); - mAng a0 = vel_mag * 182.0f * 0.2f; - mAng a1 = angle.y - rotation.y; - mAng a2 = vel_mag * (mField_0x978 + 200.f); + f32 f1 = mAng(vel_mag * (mField_0x978 + 200.f)).radian(); + f32 f2 = mAng(vel_mag * 182.0f * 0.2f).radian(); + f32 f0 = mAng(angle.y - rotation.y).radian(); - f32 f0 = mAng::SAngle_to_Radian(a1); - f32 f1 = mAng::SAngle_to_Radian(a2); - f32 f2 = mAng::SAngle_to_Radian(a0); + mQuat_c q0, q1, q2, q3; q1.setAxisRotation(mVec3_c::Ey, f0); q0.setAxisRotation(mVec3_c::Ey, -f0); q3.setAxisRotation(mVec3_c::Ex, f1); q2.setAxisRotation(mVec3_c::Ey, f2); - mField_0x910 = mField_0x910 * q0 * q2 * q1 * q3; + mField_0x910 = q1 * q3 * q2 * q0 * mField_0x910; } + + mMtx_c mtx0, mtx1, mtx2; mShadowMtx.copyFrom(mWorldMtx); - mVec3_c pos = getPosition() - position; - PSMTXTrans(mtx1, pos.x, pos.y, pos.z); - PSMTXConcat(mShadowMtx, mtx2, mShadowMtx); + mtx1.trans(getPosition() - position); + mShadowMtx += mtx1; mtx0.fromQuat(mField_0x910); - PSMTXTrans(mtx1, 0.f, 40.f, 0.f); - PSMTXConcat(mWorldMtx, mtx0, mWorldMtx); - PSMTXConcat(mWorldMtx, mtx2, mWorldMtx); + mtx2.trans(0.f, 40.f, 0.f); + mWorldMtx += mtx2; + mWorldMtx += mtx0; } void dAcOTumbleWeed_c::adjustAngle() { @@ -317,21 +314,34 @@ void dAcOTumbleWeed_c::adjustAngle() { void dAcOTumbleWeed_c::adjustSpeed() { cM3dGPla pla; - const f32 a = mVec3_c::Ey.dot(pla.mNormal); - const f32 b = mVec3_c::Ey.cross(pla.mNormal).length(); + // BUG + // the ground angle calculation happens before retrieving the grounds normal + // this is probably hard to notice due to the little effect it has. + // Effect: + // Tumbleweed slows to the target much quicker than intended + // Tumbleweed speeds to the target + 5.0f much quicker than intended - mAng ang = mAng::fromRad(EGG::Math::abs(EGG::Math::atan2(b, a))); + f32 dot = mVec3_c::Ey.dot(pla.GetN()); + f32 cross = mVec3_c::Ey.cross(pla.GetN()).length(); + + f32 angF = EGG::Math::atan2(cross, dot); + mAng gndAngle = mAng::fromRad(EGG::Math::abs(angF)); dBgS::GetInstance()->GetTriPla(mObjAcch.mGnd, &pla); - f32 tmp2 = nw4r::math::CosIdx(ang) * 0.5f; - if (ang < 182 || sLib::absDiff(cM::atan2s(pla.mNormal.x, pla.mNormal.z), angle.y) > 0x4000) { - sLib::chase(&forwardSpeed, mSpeedTarget, tmp2); - } else { - f32 min = forwardSpeed + tmp2; - f32 max = mSpeedTarget + 5.0f; - f32 val = mSpeedTarget; - forwardSpeed = EGG::Math::clamp(val, min, max); + f32 speedStep = 0.5f; + f32 step = gndAngle.cos() * speedStep; + + // Flat Ground or not in the direction of the slope + // Slows down + if (gndAngle < mAng::deg2short(1) || + sLib::absDiff(cM::atan2s(pla.GetN().x, pla.GetN().z), GetAngle().y) > mAng::deg2short(90)) { + sLib::chase(&forwardSpeed, mSpeedTarget, step); + } + // Sloped Ground and in the direction of the slope + // Speeds up + else { + forwardSpeed = cM::minMaxLimit(forwardSpeed + step, mSpeedTarget, mSpeedTarget + 5.0f); } } @@ -395,3 +405,7 @@ mVec3_c dAcOTumbleWeed_c::getPosition() const { PSMTXMultVecSR(mtx, mVec3_c::Ey, vec); return position + vec * 40.f; } + +void float_ordering2() { + const f32 arr[] = {30.f, 0.07f, 20.f, -10000.f, 5.f}; +} diff --git a/src/egg/math/eggMatrix.cpp b/src/egg/math/eggMatrix.cpp index dd171848..93108411 100644 --- a/src/egg/math/eggMatrix.cpp +++ b/src/egg/math/eggMatrix.cpp @@ -126,15 +126,15 @@ void Matrix34f::makeST(const Vector3f &s, const Vector3f &t) { } void Matrix34f::makeSQT(const Vector3f &s, const Quatf &q, const Vector3f &t) { - f32 yy = 2.0f * q.y * q.y; - f32 zz = 2.0f * q.z * q.z; - f32 xx = 2.0f * q.x * q.x; - f32 xy = 2.0f * q.x * q.y; - f32 xz = 2.0f * q.x * q.z; - f32 yz = 2.0f * q.y * q.z; - f32 wz = 2.0f * q.w * q.z; - f32 wx = 2.0f * q.w * q.x; - f32 wy = 2.0f * q.w * q.y; + f32 yy = 2.0f * q.v.y * q.v.y; + f32 zz = 2.0f * q.v.z * q.v.z; + f32 xx = 2.0f * q.v.x * q.v.x; + f32 xy = 2.0f * q.v.x * q.v.y; + f32 xz = 2.0f * q.v.x * q.v.z; + f32 yz = 2.0f * q.v.y * q.v.z; + f32 wz = 2.0f * q.w * q.v.z; + f32 wx = 2.0f * q.w * q.v.x; + f32 wy = 2.0f * q.w * q.v.y; m[0][0] = s.x * (1.0f - yy - zz); m[0][1] = s.y * (xy - wz); @@ -154,15 +154,15 @@ void Matrix34f::makeSQT(const Vector3f &s, const Quatf &q, const Vector3f &t) { } void Matrix34f::makeQT(const Quatf &q, const Vector3f &t) { - f32 yy = 2.0f * q.y * q.y; - f32 zz = 2.0f * q.z * q.z; - f32 xx = 2.0f * q.x * q.x; - f32 xy = 2.0f * q.x * q.y; - f32 xz = 2.0f * q.x * q.z; - f32 yz = 2.0f * q.y * q.z; - f32 wz = 2.0f * q.w * q.z; - f32 wx = 2.0f * q.w * q.x; - f32 wy = 2.0f * q.w * q.y; + f32 yy = 2.0f * q.v.y * q.v.y; + f32 zz = 2.0f * q.v.z * q.v.z; + f32 xx = 2.0f * q.v.x * q.v.x; + f32 xy = 2.0f * q.v.x * q.v.y; + f32 xz = 2.0f * q.v.x * q.v.z; + f32 yz = 2.0f * q.v.y * q.v.z; + f32 wz = 2.0f * q.w * q.v.z; + f32 wx = 2.0f * q.w * q.v.x; + f32 wy = 2.0f * q.w * q.v.y; m[0][0] = 1.0f - yy - zz; m[0][1] = xy - wz; @@ -182,15 +182,15 @@ void Matrix34f::makeQT(const Quatf &q, const Vector3f &t) { } void Matrix34f::makeQ(const Quatf &q) { - f32 yy = 2.0f * q.y * q.y; - f32 zz = 2.0f * q.z * q.z; - f32 xx = 2.0f * q.x * q.x; - f32 xy = 2.0f * q.x * q.y; - f32 xz = 2.0f * q.x * q.z; - f32 yz = 2.0f * q.y * q.z; - f32 wz = 2.0f * q.w * q.z; - f32 wx = 2.0f * q.w * q.x; - f32 wy = 2.0f * q.w * q.y; + f32 yy = 2.0f * q.v.y * q.v.y; + f32 zz = 2.0f * q.v.z * q.v.z; + f32 xx = 2.0f * q.v.x * q.v.x; + f32 xy = 2.0f * q.v.x * q.v.y; + f32 xz = 2.0f * q.v.x * q.v.z; + f32 yz = 2.0f * q.v.y * q.v.z; + f32 wz = 2.0f * q.w * q.v.z; + f32 wx = 2.0f * q.w * q.v.x; + f32 wy = 2.0f * q.w * q.v.y; m[0][0] = 1.0f - yy - zz; m[0][1] = xy - wz; @@ -240,17 +240,17 @@ void Matrix34f::makeT(const Vector3f &t) { } void Matrix34f::fromQuat(const Quatf &q) { - m[0][0] = 1.0f - (2 * q.y * q.y) - (2.0f * q.z * q.z); - m[0][1] = (2.0f * q.x * q.y) - (2.0f * q.w * q.z); - m[0][2] = (2.0f * q.x * q.z) + (2.0f * q.w * q.y); + m[0][0] = 1.0f - (2 * q.v.y * q.v.y) - (2.0f * q.v.z * q.v.z); + m[0][1] = (2.0f * q.v.x * q.v.y) - (2.0f * q.w * q.v.z); + m[0][2] = (2.0f * q.v.x * q.v.z) + (2.0f * q.w * q.v.y); - m[1][0] = (2.0f * q.x * q.y) + (2.0f * q.w * q.z); - m[1][1] = 1.0f - (2.0f * q.x * q.x) - (2.0f * q.z * q.z); - m[1][2] = (2.0f * q.y * q.z) - (2.0f * q.w * q.x); + m[1][0] = (2.0f * q.v.x * q.v.y) + (2.0f * q.w * q.v.z); + m[1][1] = 1.0f - (2.0f * q.v.x * q.v.x) - (2.0f * q.v.z * q.v.z); + m[1][2] = (2.0f * q.v.y * q.v.z) - (2.0f * q.w * q.v.x); - m[2][0] = (2.0f * q.x * q.z) - (2.0f * q.w * q.y); - m[2][1] = (2.0f * q.y * q.z) + (2.0f * q.w * q.x); - m[2][2] = 1.0f - (2.0f * q.x * q.x) - (2.0f * q.y * q.y); + m[2][0] = (2.0f * q.v.x * q.v.z) - (2.0f * q.w * q.v.y); + m[2][1] = (2.0f * q.v.y * q.v.z) + (2.0f * q.w * q.v.x); + m[2][2] = 1.0f - (2.0f * q.v.x * q.v.x) - (2.0f * q.v.y * q.v.y); m[2][3] = 0.0f; m[1][3] = 0.0f; @@ -298,38 +298,38 @@ void Matrix34f::toQuat(Quatf &q) const { switch (tempMax) { case 0: q.w = Math::sqrt(temp0); - q.x = (0.25f / q.w) * (m[2][1] - m[1][2]); - q.y = (0.25f / q.w) * (m[0][2] - m[2][0]); - q.z = (0.25f / q.w) * (m[1][0] - m[0][1]); + q.v.x = (0.25f / q.w) * (m[2][1] - m[1][2]); + q.v.y = (0.25f / q.w) * (m[0][2] - m[2][0]); + q.v.z = (0.25f / q.w) * (m[1][0] - m[0][1]); break; case 1: - q.x = Math::sqrt(temp1); - q.w = (0.25f / q.x) * (m[2][1] - m[1][2]); - q.y = (0.25f / q.x) * (m[0][1] + m[1][0]); - q.z = (0.25f / q.x) * (m[0][2] + m[2][0]); + q.v.x = Math::sqrt(temp1); + q.w = (0.25f / q.v.x) * (m[2][1] - m[1][2]); + q.v.y = (0.25f / q.v.x) * (m[0][1] + m[1][0]); + q.v.z = (0.25f / q.v.x) * (m[0][2] + m[2][0]); break; case 2: - q.y = Math::sqrt(temp2); - q.w = (0.25f / q.y) * (m[0][2] - m[2][0]); - q.z = (0.25f / q.y) * (m[1][2] + m[2][1]); - q.x = (0.25f / q.y) * (m[1][0] + m[0][1]); + q.v.y = Math::sqrt(temp2); + q.w = (0.25f / q.v.y) * (m[0][2] - m[2][0]); + q.v.z = (0.25f / q.v.y) * (m[1][2] + m[2][1]); + q.v.x = (0.25f / q.v.y) * (m[1][0] + m[0][1]); break; case 3: - q.z = Math::sqrt(temp3); - q.w = (0.25f / q.z) * (m[1][0] - m[0][1]); - q.x = (0.25f / q.z) * (m[2][0] + m[0][2]); - q.y = (0.25f / q.z) * (m[2][1] + m[1][2]); + q.v.z = Math::sqrt(temp3); + q.w = (0.25f / q.v.z) * (m[1][0] - m[0][1]); + q.v.x = (0.25f / q.v.z) * (m[2][0] + m[0][2]); + q.v.y = (0.25f / q.v.z) * (m[2][1] + m[1][2]); break; default: break; } if (q.w < 0.0f) { q.w = -q.w; - q.x = -q.x; - q.y = -q.y; - q.z = -q.z; + q.v.x = -q.v.x; + q.v.y = -q.v.y; + q.v.z = -q.v.z; } - q.multScalar(Math::inv(q.length())); + q.multScalar(Math::inv(Math::sqrt(q.w * q.w + q.v.dot(q.v)))); } void Matrix34f::slerpTo(const Matrix34f &m2, Matrix34f &out, f32 t) const { diff --git a/src/egg/math/eggQuat.cpp b/src/egg/math/eggQuat.cpp index 0a735a78..0ccb90b1 100644 --- a/src/egg/math/eggQuat.cpp +++ b/src/egg/math/eggQuat.cpp @@ -5,9 +5,9 @@ namespace EGG { /* 8049b390 */ void Quatf::set(f32 fw, f32 fx, f32 fy, f32 fz) { w = fw; - x = fx; - y = fy; - z = fz; + v.x = fx; + v.y = fy; + v.z = fz; } void Quatf::set(f32 fw, const Vector3f &vec) { @@ -30,9 +30,9 @@ void Quatf::setRPY(const EGG::Vector3f &rpy) { const f32 sy_cp = sy * cp; w = (cy_cp * cr) + (sy_sp * sr); - x = (cy_cp * sr) - (sy_sp * cr); - y = (cy_sp * cr) + (sy_cp * sr); - z = (sy_cp * cr) - (cy_sp * sr); + v.x = (cy_cp * sr) - (sy_sp * cr); + v.y = (cy_sp * cr) + (sy_cp * sr); + v.z = (sy_cp * cr) - (cy_sp * sr); } /* NOT IN SS */ @@ -84,7 +84,7 @@ void Quatf::setAxisRotation(const Vector3f &axis, f32 rot) { /* 8049b450 */ f32 Quatf::norm() { - return w * w + Vector3f::dot(*this); + return w * w + v.dot(v); } /* 8049b480 */ @@ -99,7 +99,7 @@ void Quatf::normalise() { Quatf Quatf::conjugate() { Quatf q; q.w = w; - (Vector3f &)q = -1.0f * *this; + q.v = -1.0f * v; return q; } @@ -109,7 +109,7 @@ Vector3f Quatf::rotateVector(const Vector3f &vec) { conj = conjugate(); mult = *this * vec; mult = mult * conj; - return (mult); + return (mult.v); } // /* NOT IN SS */ @@ -122,7 +122,7 @@ Vector3f Quatf::rotateVector(const Vector3f &vec) { /* 8049b800 */ void Quatf::slerpTo(const Quatf &q2, f32 t, Quatf &out) const { - f32 dot = x * q2.x + y * q2.y + z * q2.z + w * q2.w; + f32 dot = v.x * q2.v.x + v.y * q2.v.y + v.z * q2.v.z + w * q2.w; if (dot > 1.0f) { dot = 1.0f; @@ -156,9 +156,9 @@ void Quatf::slerpTo(const Quatf &q2, f32 t, Quatf &out) const { b = -b; } - out.x = a * x + b * q2.x; - out.y = a * y + b * q2.y; - out.z = a * z + b * q2.z; + out.v.x = a * v.x + b * q2.v.x; + out.v.y = a * v.y + b * q2.v.y; + out.v.z = a * v.z + b * q2.v.z; out.w = a * w + b * q2.w; } @@ -166,7 +166,7 @@ void Quatf::slerpTo(const Quatf &q2, f32 t, Quatf &out) const { void Quatf::limitSlerpTo(const Quatf &q2, f32 t, f32 t2, Quatf &out) const { t2 *= 0.5f; - f32 dot = x * q2.x + y * q2.y + z * q2.z + w * q2.w; + f32 dot = v.x * q2.v.x + v.y * q2.v.y + v.z * q2.v.z + w * q2.w; if (dot > 1.0f) { dot = 1.0f; @@ -204,9 +204,9 @@ void Quatf::limitSlerpTo(const Quatf &q2, f32 t, f32 t2, Quatf &out) const { b = -b; } - out.x = a * x + b * q2.x; - out.y = a * y + b * q2.y; - out.z = a * z + b * q2.z; + out.v.x = a * v.x + b * q2.v.x; + out.v.y = a * v.y + b * q2.v.y; + out.v.z = a * v.z + b * q2.v.z; out.w = a * w + b * q2.w; } diff --git a/src/m/m3d/m_shadow.cpp b/src/m/m3d/m_shadow.cpp index 01e3d932..a5a0b010 100644 --- a/src/m/m3d/m_shadow.cpp +++ b/src/m/m3d/m_shadow.cpp @@ -488,7 +488,7 @@ bool mShadowChild_c::addMdl(scnLeaf_c &mdl, const mQuat_c &quat) { // TODO this copy is a bit weird (reads members in a different order) mQuat_c q = quat; - PSMTXMultVec(mtx.m, q, q); + PSMTXMultVec(mtx.m, q.v, q.v); if (mNumLeaves == 0) { mQuat = q; @@ -501,7 +501,7 @@ bool mShadowChild_c::addMdl(scnLeaf_c &mdl, const mQuat_c &quat) { bool mShadowChild_c::setGeom(const GXTexObj *texObj, const mMtx_c &mtx, const mQuat_c &quat) { mQuat = quat; - PSMTXMultVec(mtx.m, mQuat, mQuat); + PSMTXMultVec(mtx.m, mQuat.v, mQuat.v); if (texObj == nullptr) { mTexObj = *mShadow_c::sTexObj; } else { diff --git a/src/m/m_angle.cpp b/src/m/m_angle.cpp index 77319d48..fe53b0c1 100644 --- a/src/m/m_angle.cpp +++ b/src/m/m_angle.cpp @@ -8,7 +8,7 @@ mAng3_c mAng3_c::Zero = mAng3_c(0, 0, 0); const f32 mAng::sHalfCircleDeg = 360.0f / 2; const f32 mAng::sAngToDeg = 360.0f / (1 << 16); const f32 mAng::sAngToRad = 2 * M_PI / (1 << 16); -const f32 mAng::NotSure = 2.0f / (1 << 16); +const f32 mAng::sAngToNorm = 2.0f / (1 << 16); const f32 mAng::sDegToRad = M_PI / 180.0f; const f32 mAng::sDegToAng = (1 << 16) / 360.0f; const f32 mAng::sRadToAng = (1 << 16) / (2 * M_PI);