d_a_obj_tumble_weed mostly done (#88)

* mostly done

* Update d_t_tumble_weed.cpp

* remove cM::calcTimer

* just regswap on adjustSpeed

* Create inlines for angle between vectors

* name data symbols

---------

Co-authored-by: robojumper <robojumper@gmail.com>
This commit is contained in:
Elijah Thomas
2024-11-06 16:36:17 -05:00
committed by GitHub
parent f509c053e5
commit c235e32d95
34 changed files with 804 additions and 214 deletions
+2 -5
View File
@@ -12,11 +12,8 @@ f32 rndF(f32 max);
f32 rndFX(f32 amp);
template <typename T>
T calcTimer(T *value) {
if (*(T *)value != 0) {
*value = *value - 1;
}
return *value;
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
+1 -1
View File
@@ -179,7 +179,7 @@ public:
/* vt 0x284 */ virtual bool isUsingBugnet() const;
/* vt 0x288 */ virtual const mVec3_c &getBugNetPos() const;
/* vt 0x28C */ virtual void isUsingBugnet1();
/* vt 0x290 */ virtual void bugNetCollectTreasure();
/* vt 0x290 */ virtual void bugNetCollectTreasure(u32 itemId);
/* vt 0x294 */ virtual void somethingSwitchDials();
/* vt 0x298 */ virtual void vt_0x298();
/* vt 0x29C */ virtual void getDieLargeDamageDir();
+9 -1
View File
@@ -4,6 +4,7 @@
#include "d/a/d_a_base.h"
#include "d/col/c/c_cc_d.h"
#include "d/col/c/c_m3d_g_aab.h"
#include "egg/math/eggMath.h"
#include "m/m3d/m_shadow.h"
#include "m/m3d/m_smdl.h"
#include "m/m_angle.h"
@@ -11,7 +12,6 @@
#include "m/m_vec.h"
#include "m/types_m.h"
// Size: 0xA8
struct ActorCarryStruct {
/* 0x00 */ fLiNdBa_c actorLink;
@@ -89,6 +89,14 @@ public:
return angle;
}
f32 getVelocityMag() const {
return fabsf(nw4r::math::VEC3LenSq(velocity));
}
bool isStopped() const {
return getVelocityMag() <= EGG::Math<f32>::epsilon();
}
// could be their own thing?
/* 8002de40 */ static void *getOarcFile(const char *oarcName, const char *fileName);
/* 8002de60 */ static void *getOarcSubEntry(const char *oarcName, const char *fileName);
+73 -3
View File
@@ -1,20 +1,90 @@
#ifndef D_A_OBJ_TUMBLE_WEED_H
#define D_A_OBJ_TUMBLE_WEED_H
#include "common.h"
#include "d/a/obj/d_a_obj_base.h"
#include "d/col/bg/d_bg_s_acch.h"
#include "d/col/cc/d_cc_d.h"
#include "d/d_shadow.h"
#include "m/m3d/m_smdl.h"
#include "m/m_mtx.h"
#include "m/m_quat.h"
#include "m/m_vec.h"
#include "nw4r/g3d/g3d_resfile.h"
#include "s/s_State.hpp"
#include "s/s_StateMgr.hpp"
#include "toBeSorted/dowsing_target.h"
#include "toBeSorted/time_area_mgr.h"
class dAcOTumbleWeed_c : public dAcObjBase_c {
public:
dAcOTumbleWeed_c() : mStateMgr(*this, sStateID::null) {}
dAcOTumbleWeed_c() : mDowsingTarget(this, DowsingTarget::SLOT_NONE), mStateMgr(*this, sStateID::null) {}
virtual ~dAcOTumbleWeed_c() {}
virtual int doDelete() override;
virtual int draw() override;
virtual bool createHeap() override;
virtual int actorCreate() override;
virtual int actorPostCreate() override;
virtual int actorExecute() override;
bool checkCollect();
bool checkBreak();
void doBreak();
void adjustTimeScale();
void adjustTumble(const mVec3_c &dir);
void calcWind();
mVec3_c getPosition() const;
void calcMatrix();
void adjustAngle();
void adjustSpeed();
void tumbleBounceMaybe();
void setWind(const mVec3_c &);
bool checkSlope();
bool fn_475_E40() const;
bool checkInvalidGround() const;
// Look at `isStopped` in dAcObjBase. This may be a diff inline
f32 getWindMag() const {
return fabsf(nw4r::math::VEC3LenSq(mWind));
}
bool isWindStop() const {
return getWindMag() <= EGG::Math<f32>::epsilon();
}
STATE_FUNC_DECLARE(dAcOTumbleWeed_c, Wait);
STATE_FUNC_DECLARE(dAcOTumbleWeed_c, Slope);
private:
/* 0x??? */ STATE_MGR_DECLARE(dAcOTumbleWeed_c);
/* 0x330 */ nw4r::g3d::ResFile mResFile;
/* 0x334 */ m3d::smdl_c mMdl;
/* 0x350 */ dShadowCircle_c mShdw;
/* 0x358 */ dCcD_Sph mSph;
/* 0x4A8 */ dBgS_AcchCir mAcchCir;
/* 0x504 */ dBgS_ObjAcch mObjAcch;
/* 0x8B4 */ DowsingTarget mDowsingTarget;
/* 0x8D4 */ STATE_MGR_DECLARE(dAcOTumbleWeed_c);
/* 0x910 */ mQuat_c mField_0x910;
/* 0x920 */ TimeAreaStruct mTimeArea;
/* 0x92C */ mMtx_c mShadowMtx;
/* 0x95C */ mVec3_c mWind;
/* 0x968 */ mVec3_c mField_0x968;
/* 0x974 */ f32 mField_0x974;
/* 0x978 */ f32 mField_0x978;
/* 0x97C */ f32 mField_0x97C;
/* 0x980 */ f32 mField_0x980;
/* 0x984 */ f32 mSpeedTarget;
/* 0x988 */ u16 mTumbleTimer;
/* 0x98A */ u8 mWindTimer;
/* 0x98B */ u8 mField_0x98B;
/* 0x98C */ u8 mField_0x98C;
/* 0x98D */ bool mbOnGround;
static dCcD_SrcSph sSphSrc;
};
#endif
+12
View File
@@ -27,6 +27,18 @@ enum dBgPc_ECode {
/* 0x80000000 */ CODE_UNUSED_8000_0000 = 0x80000000,
};
enum dBgPc_Attribute {
POLY_ATTR_NORMAL = 0,
POLY_ATTR_SLOPE = 1,
POLY_ATTR_LAVA = 7,
POLY_ATTR_SAND_SHALLOW = 9,
POLY_ATTR_SAND_MED = 10,
POLY_ATTR_SAND_DEEP_INSTANT = 11,
POLY_ATTR_WATER = 12,
POLY_ATTR_DAMAGE = 13,
POLY_ATTR_SLOPE_RUN = 15,
POLY_ATTR_SAND_DEEP_SLOW = 16,
};
class dBgPc {
public:
void setCode(sBgPc &);
+4
View File
@@ -488,6 +488,10 @@ public:
return mFlags & GROUND_HIT;
}
dBgS_GndChk &GetGnd() {
return mGnd;
}
public:
/* 0x040 */ u32 mFlags;
/* 0x044 */ mVec3_c *mpPos;
+37 -3
View File
@@ -308,6 +308,10 @@ public:
dAcObjBase_c *GetAc() {
return mpActor;
}
const mVec3_c &GetCcMove() const {
return mCcMove;
}
};
struct cCcD_SrcGObjTgInfo {
@@ -323,6 +327,36 @@ struct cCcD_SrcGObjTg {
/* 0x0E */ u16 mField_0x0E;
};
enum cCcD_AtType_e {
/* 0x 0000 0001 */ AT_TYPE_0x1 = (1 << 0),
/* 0x 0000 0002 */ AT_TYPE_0x2 = (1 << 1),
/* 0x 0000 0004 */ AT_TYPE_0x4 = (1 << 2),
/* 0x 0000 0008 */ AT_TYPE_0x8 = (1 << 3),
/* 0x 0000 0010 */ AT_TYPE_0x10 = (1 << 4),
/* 0x 0000 0020 */ AT_TYPE_0x20 = (1 << 5),
/* 0x 0000 0040 */ AT_TYPE_0x40 = (1 << 6),
/* 0x 0000 0080 */ AT_TYPE_0x80 = (1 << 7),
/* 0x 0000 0100 */ AT_TYPE_0x100 = (1 << 8),
/* 0x 0000 0200 */ AT_TYPE_0x200 = (1 << 9),
/* 0x 0000 0400 */ AT_TYPE_0x400 = (1 << 10),
/* 0x 0000 0800 */ AT_TYPE_0x800 = (1 << 11),
/* 0x 0000 1000 */ AT_TYPE_0x1000 = (1 << 12),
/* 0x 0000 2000 */ AT_TYPE_0x2000 = (1 << 13),
/* 0x 0000 4000 */ AT_TYPE_0x4000 = (1 << 14),
/* 0x 0000 8000 */ AT_TYPE_0x8000 = (1 << 15),
/* 0x 0001 0000 */ AT_TYPE_0x10000 = (1 << 16),
/* 0x 0002 0000 */ AT_TYPE_0x20000 = (1 << 17),
/* 0x 0004 0000 */ AT_TYPE_0x40000 = (1 << 18),
/* 0x 0008 0000 */ AT_TYPE_0x80000 = (1 << 19),
/* 0x 0010 0000 */ AT_TYPE_0x100000 = (1 << 20),
/* 0x 0020 0000 */ AT_TYPE_0x200000 = (1 << 21),
/* 0x 0040 0000 */ AT_TYPE_0x400000 = (1 << 22),
/* 0x 0080 0000 */ AT_TYPE_0x800000 = (1 << 23),
/* 0x 0100 0000 */ AT_TYPE_BUGNET = (1 << 24),
/* 0x 0200 0000 */ AT_TYPE_0x2000000 = (1 << 25),
/* 0x 0400 0000 */ AT_TYPE_0x4000000 = (1 << 26),
/* 0x 0800 0000 */ AT_TYPE_0x8000000 = (1 << 27),
};
enum cCcD_AtModifiers_e {
/* 0x 0000 0001 */ AT_MOD_FIRE = (1 << 0),
/* 0x 0000 0002 */ AT_MOD_0x2 = (1 << 1),
@@ -758,13 +792,13 @@ public:
}
bool ChkTgHit() {
return mTg.MskSPrm(1) != 0 && mTg.GetActor() != nullptr;
return mTg.MskRPrm(1) != 0 && mTg.GetActor() != nullptr;
}
bool ChkAtHit() {
return mAt.MskSPrm(1) != 0 && mAt.GetActor() != nullptr;
return mAt.MskRPrm(1) != 0 && mAt.GetActor() != nullptr;
}
bool ChkCoHit() {
return mCo.MskSPrm(1) != 0 && mCo.GetActor() != nullptr;
return mCo.MskRPrm(1) != 0 && mCo.GetActor() != nullptr;
}
dAcObjBase_c *GetAc() {
+2 -2
View File
@@ -57,8 +57,8 @@ public:
return EGG::Math<f32>::sqrt(mNormal.x * mNormal.x + mNormal.z * mNormal.z);
}
mAng GetAngleY() const {
return cM::atan2s(mNormal.x, mNormal.z);
s32 GetAngleY() const {
return mAng(cM::atan2s(mNormal.x, mNormal.z));
}
};
+4
View File
@@ -16,6 +16,10 @@ public:
void SetR(f32);
void SetC(f32, f32, f32);
void SetC(const mVec3_c &p) {
SetC(&p);
}
f32 GetYDist(f32) const;
bool Cross(const cM3dGTri *, f32 *, mVec3_c *);
void Clamp(const mVec3_c &, mVec3_c &) const;
+2 -4
View File
@@ -1,10 +1,9 @@
#ifndef D_T_TUMBLE_WEED_H
#define D_T_TUMBLE_WEED_H
#include "d/a/obj/d_a_obj_tumble_weed.h"
#include "d/t/d_tg.h"
#include "f/f_list_nd.h"
#include "s/s_State.hpp"
#include "s/s_StateMgr.hpp"
class dTgTumbleWeed_c : public dTg_c {
public:
@@ -29,8 +28,7 @@ private:
u16 tumbleweedTimer;
u16 padding;
u16 windTimer;
// TODO dAcObjTumbleWeed
dAcRef_c<dAcBase_c> childTumbleweed;
dAcRef_c<dAcOTumbleWeed_c> childTumbleweed;
u16 someField;
};
+21 -30
View File
@@ -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<f32>::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;
};
+8 -3
View File
@@ -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);
}
@@ -96,6 +95,12 @@ struct Vector3f : public nw4r::math::VEC3 {
multScalar(1.0f / f);
}
f32 angle(const Vector3f &v) const {
f32 a = dot(v);
f32 b = cross(v).length();
return EGG::Math<f32>::abs(EGG::Math<f32>::atan2(b, a));
}
// dot__Q23EGG8Vector3fCFRCQ23EGG8Vector3f
f32 dot(const Vector3f &v) const {
return x * v.x + y * v.y + z * v.z;
+44 -1
View File
@@ -3,6 +3,8 @@
#include "c/c_math.h"
#include "common.h"
#include "m/m_vec.h"
#include "math.h"
#include "nw4r/math/math_triangular.h"
struct mAng {
@@ -13,6 +15,9 @@ struct mAng {
static mAng atan2s(f32 a, f32 b) {
return mAng(cM::atan2s(a, b));
}
static mAng fromVec(const mVec3_c &other) {
return mAng(cM::atan2s(other.x, other.z));
}
operator s16() const {
return mVal;
@@ -47,15 +52,53 @@ struct mAng {
s16 mVal;
f32 degree() const {
return (360.0f / 65536.0f) * mVal;
}
static mAng fromDeg(f32 deg) {
return deg * sDegToAng;
}
static s16 angle(const mVec3_c &a, const mVec3_c &b) {
f32 rads = a.angle(b);
return fromRad(rads);
}
f32 radian() const {
return ((2.f * M_PI) / 65536.0f) * mVal;
}
static s16 fromRad(f32 rad) {
return rad * sRadToAng;
}
static f32 rad2deg(f32 rad) {
return rad * (360.f / (2.f * M_PI));
}
static f32 deg2rad(f32 deg) {
return deg * ((2.f * M_PI) / 360.f);
}
static s16 deg2short(f32 deg) {
return deg * (65536.0f / 360.0f);
}
static f32 short2deg(s16 angle) {
return (360.0f / 65536.0f) * angle;
}
static f32 short2rad(s16 angle) {
return ((2.f * M_PI) / 65536.0f) * angle;
}
static f32 short2norm(s16 angle) {
return 3.0517578E-5f * angle;
}
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;
+13
View File
@@ -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 @@ public:
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;
};
+6
View File
@@ -8,6 +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) {
v = rhs.v;
w = rhs.w;
return *this;
}
void fn_802F2780(const mQuat_c &other);
};
+7 -6
View File
@@ -3,9 +3,11 @@
#include "c/c_math.h"
#include "common.h"
#include "egg/math/eggMath.h"
#include "egg/math/eggVector.h"
#include "m/m_angle.h"
#include "nw4r/math/math_types.h"
#include "nw4r/types_nw4r.h"
#include "rvl/MTX/vec.h"
class mAng;
@@ -217,17 +219,16 @@ public:
void rotY(const mAng &angle);
// ???
s32 getAngleY() const {
return mAng(cM::atan2s(x, z));
}
void CopyTo(nw4r::math::VEC3 *p) {
p->x = x;
p->y = y;
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;
+8
View File
@@ -22,6 +22,14 @@ void addCalcScaled(float *value, float stepSize, float maxStep);
int absDiff(short a1, short a2);
BOOL chaseUC(u8 *value, u8 target, u8 stepSize);
template <typename T>
T calcTimer(T *val) {
if (*val != 0) {
*val -= 1;
}
return *val;
}
} // namespace sLib
#endif