2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-12-08 15:44:56 +00:00

Finish CSpacePirate implementation

This commit is contained in:
Jack Andersen
2018-12-12 21:39:16 -10:00
parent 14747e39e1
commit ec1cb75b25
37 changed files with 2337 additions and 503 deletions

View File

@@ -6,7 +6,7 @@ namespace urde {
CBodyStateCmdMgr::CBodyStateCmdMgr() {
x40_commandTable.push_back(&xb8_getup);
x40_commandTable.push_back(&xc4_step);
x40_commandTable.push_back(&xd4_);
x40_commandTable.push_back(&xd4_die);
x40_commandTable.push_back(&xdc_knockDown);
x40_commandTable.push_back(&xf4_knockBack);
x40_commandTable.push_back(&x10c_meleeAttack);
@@ -14,10 +14,10 @@ CBodyStateCmdMgr::CBodyStateCmdMgr() {
x40_commandTable.push_back(&x144_loopAttack);
x40_commandTable.push_back(&x154_loopReaction);
x40_commandTable.push_back(&x160_loopHitReaction);
x40_commandTable.push_back(&x16c_);
x40_commandTable.push_back(&x174_);
x40_commandTable.push_back(&x17c_);
x40_commandTable.push_back(&x184_);
x40_commandTable.push_back(&x16c_exitState);
x40_commandTable.push_back(&x174_leanFromCover);
x40_commandTable.push_back(&x17c_nextState);
x40_commandTable.push_back(&x184_maintainVelocity);
x40_commandTable.push_back(&x18c_generate);
x40_commandTable.push_back(&x1ac_hurled);
x40_commandTable.push_back(&x1d0_jump);
@@ -26,12 +26,12 @@ CBodyStateCmdMgr::CBodyStateCmdMgr() {
x40_commandTable.push_back(&x21c_scripted);
x40_commandTable.push_back(&x230_cover);
x40_commandTable.push_back(&x254_wallHang);
x40_commandTable.push_back(&x260_);
x40_commandTable.push_back(&x268_);
x40_commandTable.push_back(&x260_locomotion);
x40_commandTable.push_back(&x268_additiveIdle);
x40_commandTable.push_back(&x270_additiveAim);
x40_commandTable.push_back(&x278_additiveFlinch);
x40_commandTable.push_back(&x284_additiveReaction);
x40_commandTable.push_back(&x298_);
x40_commandTable.push_back(&x298_stopReaction);
}
void CBodyStateCmdMgr::DeliverCmd(const CBCLocomotionCmd& cmd) {

View File

@@ -315,7 +315,7 @@ class CBodyStateCmdMgr {
u32 xb4_deliveredCmdMask = 0;
CBCGetupCmd xb8_getup;
CBCStepCmd xc4_step;
CBodyStateCmd xd4_ = {EBodyStateCmd::Die};
CBodyStateCmd xd4_die = {EBodyStateCmd::Die};
CBCKnockDownCmd xdc_knockDown;
CBCKnockBackCmd xf4_knockBack;
CBCMeleeAttackCmd x10c_meleeAttack;
@@ -323,10 +323,10 @@ class CBodyStateCmdMgr {
CBCLoopAttackCmd x144_loopAttack;
CBCLoopReactionCmd x154_loopReaction;
CBCLoopHitReactionCmd x160_loopHitReaction;
CBodyStateCmd x16c_ = {EBodyStateCmd::ExitState};
CBodyStateCmd x174_ = {EBodyStateCmd::LeanFromCover};
CBodyStateCmd x17c_ = {EBodyStateCmd::NextState};
CBodyStateCmd x184_ = {EBodyStateCmd::MaintainVelocity};
CBodyStateCmd x16c_exitState = {EBodyStateCmd::ExitState};
CBodyStateCmd x174_leanFromCover = {EBodyStateCmd::LeanFromCover};
CBodyStateCmd x17c_nextState = {EBodyStateCmd::NextState};
CBodyStateCmd x184_maintainVelocity = {EBodyStateCmd::MaintainVelocity};
CBCGenerateCmd x18c_generate;
CBCHurledCmd x1ac_hurled;
CBCJumpCmd x1d0_jump;
@@ -335,12 +335,12 @@ class CBodyStateCmdMgr {
CBCScriptedCmd x21c_scripted;
CBCCoverCmd x230_cover;
CBCWallHangCmd x254_wallHang;
CBodyStateCmd x260_ = {EBodyStateCmd::Locomotion};
CBodyStateCmd x268_ = {EBodyStateCmd::AdditiveIdle};
CBodyStateCmd x260_locomotion = {EBodyStateCmd::Locomotion};
CBodyStateCmd x268_additiveIdle = {EBodyStateCmd::AdditiveIdle};
CBCAdditiveAimCmd x270_additiveAim;
CBCAdditiveFlinchCmd x278_additiveFlinch;
CBCAdditiveReactionCmd x284_additiveReaction;
CBodyStateCmd x298_ = {EBodyStateCmd::StopReaction};
CBodyStateCmd x298_stopReaction = {EBodyStateCmd::StopReaction};
void DeliverCmd(EBodyStateCmd cmd) { xb4_deliveredCmdMask |= (1 << int(cmd)); }
public:

View File

@@ -9,16 +9,15 @@
namespace urde {
CBoneTracking::CBoneTracking(const CAnimData& animData, std::string_view bone, float f1, float f2, bool b1)
CBoneTracking::CBoneTracking(const CAnimData& animData, std::string_view bone,
float maxTrackingAngle, float angSpeed, bool parentIk)
: x14_segId(animData.GetCharLayoutInfo().GetSegIdFromString(bone))
, x1c_(f1)
, x20_(f2)
, x36_24_active(false)
, x36_25_(false)
, x36_26_(b1)
, x36_27_(b1)
, x36_28_(b1)
, x36_29_(b1) {}
, x1c_maxTrackingAngle(maxTrackingAngle)
, x20_angSpeed(angSpeed)
, x36_26_noParent(parentIk)
, x36_27_noParentOrigin(parentIk)
, x36_28_noHorizontalAim(parentIk)
, x36_29_parentIk(parentIk) {}
void CBoneTracking::Update(float dt) { x18_time += dt; }
@@ -30,11 +29,71 @@ void CBoneTracking::PreRender(const CStateManager& mgr, CAnimData& animData, con
(bodyController.GetBodyStateInfo().ApplyHeadTracking() && patterned && patterned->ApplyBoneTracking()));
}
void CBoneTracking::PreRender(const CStateManager& mgr, CAnimData& animData, const zeus::CTransform& xf,
const zeus::CVector3f& vec, bool b) {
void CBoneTracking::PreRender(const CStateManager& mgr, CAnimData& animData, const zeus::CTransform& worldXf,
const zeus::CVector3f& localOffsetScale, bool tracking) {
if (x14_segId == 0)
return;
CHierarchyPoseBuilder& pb = animData.PoseBuilder();
TCastToConstPtr<CPatterned> targetAct = mgr.GetObjectById(x34_target);
if (x36_24_active && tracking && (targetAct || x24_targetPosition)) {
x36_25_hasTrackedRotation = true;
auto layoutInfo = pb.CharLayoutInfo();
CSegId bone;
if (x36_26_noParent)
bone = x14_segId;
else
bone = layoutInfo->GetRootNode()->GetBoneMap()[x14_segId].x0_parentId;
zeus::CTransform parentBoneXf;
pb.BuildTransform(bone, parentBoneXf);
zeus::CVector3f pos = parentBoneXf.origin;
if (x36_27_noParentOrigin && !x36_26_noParent) {
zeus::CTransform thisBoneXf;
pb.BuildTransform(x14_segId, thisBoneXf);
pos = thisBoneXf.origin;
}
parentBoneXf.origin = pos * localOffsetScale;
zeus::CTransform finalXf = worldXf * parentBoneXf;
zeus::CVector3f localDir = finalXf.transposeRotate(
(targetAct ? targetAct->GetAimPosition(mgr, 0.f) : *x24_targetPosition) - finalXf.origin).normalized();
if (x36_28_noHorizontalAim)
localDir = zeus::CVector3f(0.f, localDir.toVec2f().magnitude(), localDir.z());
if (x36_29_parentIk) {
float negElev = -parentBoneXf.basis[1].z();
zeus::CVector3f ikBase(0.f, std::sqrt(1.f - negElev * negElev), negElev);
float angle = zeus::CVector3f::getAngleDiff(ikBase, localDir);
angle = std::min(angle, x1c_maxTrackingAngle);
localDir = zeus::CVector3f::slerp(ikBase, localDir, angle);
} else {
float angle = zeus::CVector3f::getAngleDiff(zeus::CVector3f::skForward, localDir);
angle = std::min(angle, x1c_maxTrackingAngle);
localDir = zeus::CVector3f::slerp(zeus::CVector3f::skForward, localDir, angle);
}
float angle = zeus::CVector3f::getAngleDiff(x0_curRotation.transform(zeus::CVector3f::skForward), localDir);
float clampedAngle = std::min(angle, x18_time * x20_angSpeed);
if (clampedAngle > 1.0e-05f) {
x0_curRotation = zeus::CQuaternion::slerpShort(x0_curRotation,
zeus::CQuaternion::lookAt(zeus::CVector3f::skForward, zeus::CUnitVector3f(localDir), 2.f * M_PIF),
clampedAngle / angle);
}
pb.GetTreeMap()[x14_segId].x4_rotation = x0_curRotation;
animData.MarkPoseDirty();
} else if (x36_25_hasTrackedRotation) {
zeus::CQuaternion qb = pb.GetTreeMap()[x14_segId].x4_rotation;
float angle = zeus::CVector3f::getAngleDiff(x0_curRotation.transform(zeus::CVector3f::skForward),
qb.transform(zeus::CVector3f::skForward));
float maxAngDelta = x18_time * x20_angSpeed;
float clampedAngle = std::min(angle, maxAngDelta);
if (clampedAngle > 0.5f * maxAngDelta) {
x0_curRotation = zeus::CQuaternion::slerpShort(x0_curRotation, qb, clampedAngle / angle);
pb.GetTreeMap()[x14_segId].x4_rotation = x0_curRotation;
animData.MarkPoseDirty();
} else {
x36_25_hasTrackedRotation = false;
x0_curRotation = qb;
}
} else {
x0_curRotation = pb.GetTreeMap()[x14_segId].x4_rotation;
}
x18_time = 0.f;
}
@@ -42,5 +101,9 @@ void CBoneTracking::SetActive(bool) { x36_24_active = true; }
void CBoneTracking::SetTarget(TUniqueId target) { x34_target = target; }
void CBoneTracking::UnsetTarget() { x34_target = kInvalidUniqueId; }
void CBoneTracking::SetTargetPosition(const zeus::CVector3f& targetPos) { x24_targetPosition = targetPos; }
void CBoneTracking::SetNoHorizontalAim(bool b) { x36_28_noHorizontalAim = b; }
} // namespace urde

View File

@@ -12,28 +12,38 @@ class CAnimData;
class CStateManager;
class CBodyController;
class CBoneTracking {
zeus::CQuaternion x0_ = zeus::CQuaternion::skNoRotation;
zeus::CQuaternion x0_curRotation = zeus::CQuaternion::skNoRotation;
float x10_ = 0.f;
CSegId x14_segId;
float x18_time = 0.f;
float x1c_;
float x20_;
float x1c_maxTrackingAngle;
float x20_angSpeed;
std::experimental::optional<zeus::CVector3f> x24_targetPosition;
TUniqueId x34_target = kInvalidUniqueId;
bool x36_24_active : 1;
bool x36_25_ : 1;
bool x36_26_ : 1;
bool x36_27_ : 1;
bool x36_28_ : 1;
bool x36_29_ : 1;
union {
struct {
bool x36_24_active : 1;
bool x36_25_hasTrackedRotation : 1;
bool x36_26_noParent : 1;
bool x36_27_noParentOrigin : 1;
bool x36_28_noHorizontalAim : 1;
bool x36_29_parentIk : 1;
};
u32 _dummy = 0;
};
public:
CBoneTracking(const CAnimData&, std::string_view, float, float, bool);
CBoneTracking(const CAnimData& animData, std::string_view bone,
float maxTrackingAngle, float angSpeed, bool parentIk);
void Update(float dt);
void PreRender(const CStateManager&, CAnimData&, const zeus::CTransform&, const zeus::CVector3f&,
const CBodyController&);
void PreRender(const CStateManager&, CAnimData&, const zeus::CTransform&, const zeus::CVector3f&, bool);
void SetActive(bool);
void SetTarget(TUniqueId);
void SetTargetPosition(const zeus::CVector3f&);
void PreRender(const CStateManager& mgr, CAnimData& animData, const zeus::CTransform& xf,
const zeus::CVector3f& vec, const CBodyController& bodyController);
void PreRender(const CStateManager& mgr, CAnimData& animData, const zeus::CTransform& worldXf,
const zeus::CVector3f& localOffsetScale, bool tracking);
void SetActive(bool b);
void SetTarget(TUniqueId id);
void UnsetTarget();
void SetTargetPosition(const zeus::CVector3f& pos);
void SetNoHorizontalAim(bool b);
};
} // namespace urde

View File

@@ -76,11 +76,11 @@ enum class EJumpState { Invalid = -1, IntoJump, AmbushJump, Loop, OutOfJump, Wal
enum class EStepDirection { Invalid = -1, Forward = 0, Backward = 1, Left = 2, Right = 3, Up = 4, Down = 5 };
enum class EStepType { Normal = 0, Dodge = 1 };
enum class EStepType { Normal = 0, Dodge = 1, BreakDodge = 2, RollDodge = 3 };
enum class ESeverity { Invalid = -1, Zero = 0, One = 1 };
enum class ESeverity { Invalid = -1, Zero = 0, One = 1, Two = 2 };
enum class EGetupType { Invalid = -1 };
enum class EGetupType { Invalid = -1, Zero = 0 };
enum class ELoopState { Invalid = -1, Begin, Loop, End };
@@ -90,7 +90,7 @@ enum class EGenerateType { Invalid = -1, Zero, One, Two, Three, Four };
enum class ESlideType { Invalid = -1 };
enum class ETauntType { Invalid = -1 };
enum class ETauntType { Invalid = -1, Zero, One, Two };
enum class ECoverState { Invalid = -1, IntoCover, Cover, Lean, OutOfCover };