mirror of https://github.com/PrimeDecomp/prime.git
Add CABSAim
This commit is contained in:
parent
271406f725
commit
393704d4ee
|
@ -3,8 +3,8 @@
|
||||||
.section .data
|
.section .data
|
||||||
.balign 8
|
.balign 8
|
||||||
|
|
||||||
.global lbl_803E5CA0
|
.global __vt__7CABSAim
|
||||||
lbl_803E5CA0:
|
__vt__7CABSAim:
|
||||||
# ROM: 0x3E2CA0
|
# ROM: 0x3E2CA0
|
||||||
.4byte 0
|
.4byte 0
|
||||||
.4byte 0
|
.4byte 0
|
||||||
|
@ -49,8 +49,8 @@ __dt__7CABSAimFv:
|
||||||
/* 801D9D24 001D6C84 93 E1 00 0C */ stw r31, 0xc(r1)
|
/* 801D9D24 001D6C84 93 E1 00 0C */ stw r31, 0xc(r1)
|
||||||
/* 801D9D28 001D6C88 7C 7F 1B 79 */ or. r31, r3, r3
|
/* 801D9D28 001D6C88 7C 7F 1B 79 */ or. r31, r3, r3
|
||||||
/* 801D9D2C 001D6C8C 41 82 00 30 */ beq lbl_801D9D5C
|
/* 801D9D2C 001D6C8C 41 82 00 30 */ beq lbl_801D9D5C
|
||||||
/* 801D9D30 001D6C90 3C 60 80 3E */ lis r3, lbl_803E5CA0@ha
|
/* 801D9D30 001D6C90 3C 60 80 3E */ lis r3, __vt__7CABSAim@ha
|
||||||
/* 801D9D34 001D6C94 38 03 5C A0 */ addi r0, r3, lbl_803E5CA0@l
|
/* 801D9D34 001D6C94 38 03 5C A0 */ addi r0, r3, __vt__7CABSAim@l
|
||||||
/* 801D9D38 001D6C98 90 1F 00 00 */ stw r0, 0(r31)
|
/* 801D9D38 001D6C98 90 1F 00 00 */ stw r0, 0(r31)
|
||||||
/* 801D9D3C 001D6C9C 41 82 00 10 */ beq lbl_801D9D4C
|
/* 801D9D3C 001D6C9C 41 82 00 10 */ beq lbl_801D9D4C
|
||||||
/* 801D9D40 001D6CA0 3C 60 80 3E */ lis r3, __vt__18CAdditiveBodyState@ha
|
/* 801D9D40 001D6CA0 3C 60 80 3E */ lis r3, __vt__18CAdditiveBodyState@ha
|
||||||
|
@ -560,11 +560,11 @@ lbl_801DA44C:
|
||||||
.global __ct__7CABSAimFv
|
.global __ct__7CABSAimFv
|
||||||
__ct__7CABSAimFv:
|
__ct__7CABSAimFv:
|
||||||
/* 801DA468 001D73C8 3C A0 80 3E */ lis r5, __vt__18CAdditiveBodyState@ha
|
/* 801DA468 001D73C8 3C A0 80 3E */ lis r5, __vt__18CAdditiveBodyState@ha
|
||||||
/* 801DA46C 001D73CC 3C 80 80 3E */ lis r4, lbl_803E5CA0@ha
|
/* 801DA46C 001D73CC 3C 80 80 3E */ lis r4, __vt__7CABSAim@ha
|
||||||
/* 801DA470 001D73D0 38 A5 13 50 */ addi r5, r5, __vt__18CAdditiveBodyState@l
|
/* 801DA470 001D73D0 38 A5 13 50 */ addi r5, r5, __vt__18CAdditiveBodyState@l
|
||||||
/* 801DA474 001D73D4 38 00 00 00 */ li r0, 0
|
/* 801DA474 001D73D4 38 00 00 00 */ li r0, 0
|
||||||
/* 801DA478 001D73D8 90 A3 00 00 */ stw r5, 0(r3)
|
/* 801DA478 001D73D8 90 A3 00 00 */ stw r5, 0(r3)
|
||||||
/* 801DA47C 001D73DC 38 84 5C A0 */ addi r4, r4, lbl_803E5CA0@l
|
/* 801DA47C 001D73DC 38 84 5C A0 */ addi r4, r4, __vt__7CABSAim@l
|
||||||
/* 801DA480 001D73E0 C0 02 AC B0 */ lfs f0, lbl_805AC9D0@sda21(r2)
|
/* 801DA480 001D73E0 C0 02 AC B0 */ lfs f0, lbl_805AC9D0@sda21(r2)
|
||||||
/* 801DA484 001D73E4 90 83 00 00 */ stw r4, 0(r3)
|
/* 801DA484 001D73E4 90 83 00 00 */ stw r4, 0(r3)
|
||||||
/* 801DA488 001D73E8 98 03 00 04 */ stb r0, 4(r3)
|
/* 801DA488 001D73E8 98 03 00 04 */ stb r0, 4(r3)
|
||||||
|
|
|
@ -293,7 +293,7 @@ LIBS = [
|
||||||
["MetroidPrime/ScriptObjects/CScriptSwitch", True],
|
["MetroidPrime/ScriptObjects/CScriptSwitch", True],
|
||||||
["MetroidPrime/BodyState/CABSIdle", True],
|
["MetroidPrime/BodyState/CABSIdle", True],
|
||||||
["MetroidPrime/BodyState/CABSFlinch", True],
|
["MetroidPrime/BodyState/CABSFlinch", True],
|
||||||
"MetroidPrime/BodyState/CABSAim",
|
["MetroidPrime/BodyState/CABSAim", False],
|
||||||
["MetroidPrime/ScriptObjects/CScriptPlayerStateChange", True],
|
["MetroidPrime/ScriptObjects/CScriptPlayerStateChange", True],
|
||||||
"MetroidPrime/Enemies/CThardus",
|
"MetroidPrime/Enemies/CThardus",
|
||||||
"MetroidPrime/CActorParticles",
|
"MetroidPrime/CActorParticles",
|
||||||
|
|
|
@ -4,6 +4,13 @@
|
||||||
#include "MetroidPrime/BodyState/CAdditiveBodyState.hpp"
|
#include "MetroidPrime/BodyState/CAdditiveBodyState.hpp"
|
||||||
|
|
||||||
class CABSAim : public CAdditiveBodyState {
|
class CABSAim : public CAdditiveBodyState {
|
||||||
|
public:
|
||||||
|
CABSAim();
|
||||||
|
void Start(CBodyController& bc, CStateManager& mgr) override;
|
||||||
|
pas::EAnimationState UpdateBody(float dt, CBodyController& bc, CStateManager& mgr) override;
|
||||||
|
void Shutdown(CBodyController& bc) override;
|
||||||
|
|
||||||
|
private:
|
||||||
bool x4_needsIdle;
|
bool x4_needsIdle;
|
||||||
int x8_anims[4];
|
int x8_anims[4];
|
||||||
float x18_angles[4];
|
float x18_angles[4];
|
||||||
|
@ -11,13 +18,7 @@ class CABSAim : public CAdditiveBodyState {
|
||||||
float x2c_hWeightVel;
|
float x2c_hWeightVel;
|
||||||
float x30_vWeight;
|
float x30_vWeight;
|
||||||
float x34_vWeightVel;
|
float x34_vWeightVel;
|
||||||
pas::EAnimationState GetBodyStateTransition(float dt, CBodyController& bc) const;
|
pas::EAnimationState GetBodyStateTransition(float dt, CBodyController& bc);
|
||||||
|
|
||||||
public:
|
|
||||||
CABSAim();
|
|
||||||
void Start(CBodyController& bc, CStateManager& mgr) override;
|
|
||||||
pas::EAnimationState UpdateBody(float dt, CBodyController& bc, CStateManager& mgr) override;
|
|
||||||
void Shutdown(CBodyController& bc) override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _CABSAIM
|
#endif // _CABSAIM
|
||||||
|
|
|
@ -407,6 +407,7 @@ public:
|
||||||
CBodyStateCmd* GetCmd(EBodyStateCmd cmd);
|
CBodyStateCmd* GetCmd(EBodyStateCmd cmd);
|
||||||
const CVector3f& GetMoveVector() const { return x0_move; }
|
const CVector3f& GetMoveVector() const { return x0_move; }
|
||||||
const CVector3f& GetTargetVector() const { return x18_target; }
|
const CVector3f& GetTargetVector() const { return x18_target; }
|
||||||
|
const CVector3f& GetAdditiveTargetVector() const { return x24_additiveTarget; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CVector3f x0_move;
|
CVector3f x0_move;
|
||||||
|
|
|
@ -119,6 +119,8 @@ public:
|
||||||
// GetAnimationManager__9CAnimDataFv
|
// GetAnimationManager__9CAnimDataFv
|
||||||
// SetPoseValid__9CAnimDataFb
|
// SetPoseValid__9CAnimDataFb
|
||||||
|
|
||||||
|
float GetAdditiveAnimationWeight(uint idx);
|
||||||
|
|
||||||
short GetDefaultAnimation() const { return x208_defaultAnim; }
|
short GetDefaultAnimation() const { return x208_defaultAnim; }
|
||||||
const CCharacterInfo& GetCharacterInfo() const { return xc_charInfo; }
|
const CCharacterInfo& GetCharacterInfo() const { return xc_charInfo; }
|
||||||
// GetCharLayoutInfo__9CAnimDataCFv
|
// GetCharLayoutInfo__9CAnimDataCFv
|
||||||
|
|
|
@ -47,7 +47,6 @@ typedef unsigned int _UINT32;
|
||||||
#define abs(n) __abs(n)
|
#define abs(n) __abs(n)
|
||||||
#define labs(n) __labs(n)
|
#define labs(n) __labs(n)
|
||||||
static inline double fabs(double x) { return __fabs(x); }
|
static inline double fabs(double x) { return __fabs(x); }
|
||||||
static inline float fabsf(float x) { return (float)fabs((double)x); }
|
|
||||||
#else
|
#else
|
||||||
static inline int abs(int n) {
|
static inline int abs(int n) {
|
||||||
int mask = n >> 31;
|
int mask = n >> 31;
|
||||||
|
@ -73,8 +72,10 @@ double cos(double x);
|
||||||
double atan(double x);
|
double atan(double x);
|
||||||
double atan2(double y, double x);
|
double atan2(double y, double x);
|
||||||
|
|
||||||
|
_MATH_INLINE float fabsf(float x) { return (float)fabs((double)x); }
|
||||||
_MATH_INLINE float sinf(float x) { return (float)sin((double)x); }
|
_MATH_INLINE float sinf(float x) { return (float)sin((double)x); }
|
||||||
_MATH_INLINE float cosf(float x) { return (float)cos((double)x); }
|
_MATH_INLINE float cosf(float x) { return (float)cos((double)x); }
|
||||||
|
_MATH_INLINE float atan2f(float y, float x) { return (float)atan2((double)y, (double)x); }
|
||||||
float tanf(float x);
|
float tanf(float x);
|
||||||
double acos(double x);
|
double acos(double x);
|
||||||
float acosf(float x);
|
float acosf(float x);
|
||||||
|
|
|
@ -0,0 +1,119 @@
|
||||||
|
#include "MetroidPrime/BodyState/CABSAim.hpp"
|
||||||
|
|
||||||
|
#include "MetroidPrime/BodyState/CBodyController.hpp"
|
||||||
|
#include "MetroidPrime/BodyState/CBodyStateCmdMgr.hpp"
|
||||||
|
#include "MetroidPrime/CActor.hpp"
|
||||||
|
#include "MetroidPrime/CAnimData.hpp"
|
||||||
|
#include "MetroidPrime/CStateManager.hpp"
|
||||||
|
|
||||||
|
#include "Kyoto/Animation/CPASAnimParmData.hpp"
|
||||||
|
#include "Kyoto/Animation/CPASDatabase.hpp"
|
||||||
|
#include "Kyoto/Math/CMath.hpp"
|
||||||
|
|
||||||
|
CABSAim::CABSAim()
|
||||||
|
: x4_needsIdle(false)
|
||||||
|
, x28_hWeight(0.f)
|
||||||
|
, x2c_hWeightVel(0.f)
|
||||||
|
, x30_vWeight(0.f)
|
||||||
|
, x34_vWeightVel(0.f) {}
|
||||||
|
|
||||||
|
void CABSAim::Start(CBodyController& bc, CStateManager& mgr) {
|
||||||
|
const CBCAdditiveAimCmd* cmd =
|
||||||
|
static_cast< const CBCAdditiveAimCmd* >(bc.CommandMgr().GetCmd(kBSC_AdditiveAim));
|
||||||
|
|
||||||
|
const CPASDatabase& db = bc.GetPASDatabase();
|
||||||
|
const CPASAnimState* aimState = db.GetAnimState(pas::kAS_AdditiveAim);
|
||||||
|
|
||||||
|
// Left, Right, Up, Down
|
||||||
|
for (int i = 0; i < 4; ++i) {
|
||||||
|
const CPASAnimParmData parms(pas::kAS_AdditiveAim, CPASAnimParm::FromEnum(i));
|
||||||
|
const rstl::pair< float, int > best =
|
||||||
|
bc.GetPASDatabase().FindBestAnimation(parms, *mgr.Random(), -1);
|
||||||
|
x8_anims[i] = best.second;
|
||||||
|
|
||||||
|
CPASAnimParm animParm(aimState->GetAnimParmData(x8_anims[i], 1));
|
||||||
|
x18_angles[i] = CMath::Deg2Rev(animParm.GetReal32Value());
|
||||||
|
}
|
||||||
|
|
||||||
|
CAnimData& animData = *bc.GetOwner().AnimationData();
|
||||||
|
x28_hWeight = -animData.GetAdditiveAnimationWeight(x8_anims[0]);
|
||||||
|
x28_hWeight += animData.GetAdditiveAnimationWeight(x8_anims[1]);
|
||||||
|
x30_vWeight = -animData.GetAdditiveAnimationWeight(x8_anims[3]);
|
||||||
|
x30_vWeight += animData.GetAdditiveAnimationWeight(x8_anims[2]);
|
||||||
|
|
||||||
|
x4_needsIdle = false;
|
||||||
|
if (bc.CommandMgr().GetCmd(kBSC_AdditiveIdle))
|
||||||
|
x4_needsIdle = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline float GetVecAngle(const CVector3f& target) {
|
||||||
|
return atan2f(target.GetZ(),
|
||||||
|
CMath::SqrtF(target.GetY() * target.GetY() + target.GetX() * target.GetX()));
|
||||||
|
}
|
||||||
|
|
||||||
|
pas::EAnimationState CABSAim::UpdateBody(float dt, CBodyController& bc, CStateManager& mgr) {
|
||||||
|
const pas::EAnimationState st = GetBodyStateTransition(dt, bc);
|
||||||
|
if (st == pas::kAS_Invalid) {
|
||||||
|
CVector3f target = bc.CommandMgr().GetAdditiveTargetVector();
|
||||||
|
if (target.CanBeNormalized()) {
|
||||||
|
float hAngle =
|
||||||
|
CMath::Clamp(-x18_angles[0], atan2f(target.GetX(), target.GetY()), x18_angles[1]);
|
||||||
|
hAngle = hAngle * 0.63661975f;
|
||||||
|
hAngle = (hAngle - x28_hWeight) * 0.25f / dt;
|
||||||
|
hAngle = CMath::Clamp(-3.f, hAngle, 3.f);
|
||||||
|
x2c_hWeightVel += dt * CMath::Clamp(-10.f, (hAngle - x2c_hWeightVel) / dt, 10.f);
|
||||||
|
|
||||||
|
float vAngle = CMath::Clamp(-x18_angles[3], GetVecAngle(target), x18_angles[2]);
|
||||||
|
vAngle = vAngle * 0.63661975f;
|
||||||
|
vAngle = (vAngle - x30_vWeight) * 0.25f / dt;
|
||||||
|
vAngle = CMath::Clamp(-3.f, vAngle, 3.f);
|
||||||
|
x34_vWeightVel += dt * CMath::Clamp(-10.f, (vAngle - x34_vWeightVel) / dt, 10.f);
|
||||||
|
|
||||||
|
float newHWeight = dt * x2c_hWeightVel + x28_hWeight;
|
||||||
|
float newVWeight = dt * x34_vWeightVel + x30_vWeight;
|
||||||
|
CAnimData& animData = *bc.GetOwner().AnimationData();
|
||||||
|
|
||||||
|
if (newHWeight != x28_hWeight) {
|
||||||
|
float absWeight = fabsf(newHWeight);
|
||||||
|
if (fabsf(x28_hWeight) > 0.f && (x28_hWeight * newHWeight) <= 0.f)
|
||||||
|
animData.DelAdditiveAnimation(x8_anims[x28_hWeight < 0.f ? 0 : 1]);
|
||||||
|
if (absWeight > 0.f)
|
||||||
|
animData.AddAdditiveAnimation(x8_anims[newHWeight < 0.f ? 0 : 1], absWeight, false,
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newVWeight != x30_vWeight) {
|
||||||
|
float absWeight = fabsf(newVWeight);
|
||||||
|
if (fabsf(x30_vWeight) > 0.f && x30_vWeight * newVWeight <= 0.f)
|
||||||
|
animData.DelAdditiveAnimation(x8_anims[x30_vWeight > 0.f ? 2 : 3]);
|
||||||
|
if (absWeight > 0.f)
|
||||||
|
animData.AddAdditiveAnimation(x8_anims[newVWeight > 0.f ? 2 : 3], absWeight, false,
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
|
||||||
|
x28_hWeight = newHWeight;
|
||||||
|
x30_vWeight = newVWeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return st;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CABSAim::Shutdown(CBodyController& bc) {
|
||||||
|
CAnimData& animData = *bc.GetOwner().AnimationData();
|
||||||
|
|
||||||
|
if (x28_hWeight != 0.f)
|
||||||
|
animData.DelAdditiveAnimation(x8_anims[x28_hWeight < 0.f ? 0 : 1]);
|
||||||
|
if (x30_vWeight != 0.f)
|
||||||
|
animData.DelAdditiveAnimation(x8_anims[x30_vWeight > 0.f ? 2 : 3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
pas::EAnimationState CABSAim::GetBodyStateTransition(float dt, CBodyController& bc) {
|
||||||
|
CBodyStateCmdMgr& cmdMgr = bc.CommandMgr();
|
||||||
|
if (cmdMgr.GetCmd(kBSC_AdditiveReaction))
|
||||||
|
return pas::kAS_AdditiveReaction;
|
||||||
|
if (cmdMgr.GetCmd(kBSC_AdditiveFlinch))
|
||||||
|
return pas::kAS_AdditiveFlinch;
|
||||||
|
if (cmdMgr.GetCmd(kBSC_AdditiveIdle) || x4_needsIdle)
|
||||||
|
return pas::kAS_AdditiveIdle;
|
||||||
|
return pas::kAS_Invalid;
|
||||||
|
}
|
Loading…
Reference in New Issue