Get/SetPhysicsState fixes

This commit is contained in:
Phillip Stephens 2022-10-05 10:53:15 -07:00
parent 248a703cb4
commit 75909783bc
4 changed files with 24 additions and 7 deletions

View File

@ -265,7 +265,10 @@ public:
void SetRotation(const CQuaternion& rot) { void SetRotation(const CQuaternion& rot) {
SetTransform(rot.BuildTransform4f(GetTranslation())); SetTransform(rot.BuildTransform4f(GetTranslation()));
} }
CVector3f GetTranslation() const { return x34_transform.GetTranslation(); } const CQuaternion& GetRotation() const {
return CQuaternion::FromMatrix(GetTransform());
}
const CVector3f& GetTranslation() const { return x34_transform.GetTranslation(); }
void SetTranslation(const CVector3f& vec); void SetTranslation(const CVector3f& vec);
CTransform4f GetLocatorTransform(const rstl::string& segName) const; CTransform4f GetLocatorTransform(const rstl::string& segName) const;
CTransform4f GetScaledLocatorTransform(const rstl::string& segName) const; CTransform4f GetScaledLocatorTransform(const rstl::string& segName) const;

View File

@ -52,6 +52,8 @@ CHECK_SIZEOF(CMotionState, 0x34)
class CCollisionInfoList; class CCollisionInfoList;
class CPhysicsActor : public CActor { class CPhysicsActor : public CActor {
static const float skGravityConstant;
public: public:
CPhysicsActor(TUniqueId uid, bool active, const rstl::string& name, const CEntityInfo& info, CPhysicsActor(TUniqueId uid, bool active, const rstl::string& name, const CEntityInfo& info,
const CTransform4f& xf, const CModelData& mData, const CMaterialList& matList, const CTransform4f& xf, const CModelData& mData, const CMaterialList& matList,
@ -91,6 +93,15 @@ public:
void ComputeDerivedQuantities(); void ComputeDerivedQuantities();
void Stop(); void Stop();
const CVector3f& GetConstantForceWR() const { return xfc_constantForce; }
void SetConstantForceWR(const CVector3f& force) { xfc_constantForce = force; }
const CAxisAngle& GetAngularMomentumWR() const { return x108_angularMomentum; }
const CVector3f& GetMomentumWR() const { return x150_momentum; }
const CVector3f& GetForceWR() const { return x15c_force; }
const CVector3f& GetImpulseWR() const { return x168_impulse; }
const CAxisAngle& GetTorqueWR() const { return x174_torque; }
const CAxisAngle& GetAngularImpulseWR() const { return x180_angularImpulse; }
CPhysicsState GetPhysicsState() const; CPhysicsState GetPhysicsState() const;
void SetPhysicsState(const CPhysicsState& state); void SetPhysicsState(const CPhysicsState& state);
CMotionState GetMotionState() const; CMotionState GetMotionState() const;
@ -100,6 +111,8 @@ public:
bool GetMovable() const { return xf8_24_movable; } bool GetMovable() const { return xf8_24_movable; }
void SetMovable(bool v) { xf8_24_movable = v; } void SetMovable(bool v) { xf8_24_movable = v; }
static float GetGravityConstant() { return skGravityConstant; }
private: private:
f32 xe8_mass; f32 xe8_mass;
f32 xec_massRecip; f32 xec_massRecip;

View File

@ -14,7 +14,7 @@ public:
const CAxisAngle& torque, const CAxisAngle& angularImpulse); const CAxisAngle& torque, const CAxisAngle& angularImpulse);
CVector3f GetTranslation() const { return x0_translation; } CVector3f GetTranslation() const { return x0_translation; }
CQuaternion GetOrientationWR() const { return xc_orientation; } const CQuaternion& GetOrientationWR() const { return xc_orientation; }
CVector3f GetConstantForceWR() const { return x1c_constantForce; } CVector3f GetConstantForceWR() const { return x1c_constantForce; }
CAxisAngle GetAngularMomentumWR() const { return x28_angularMomentum; } CAxisAngle GetAngularMomentumWR() const { return x28_angularMomentum; }
CVector3f GetMomentumWR() const { return x34_momentum; } CVector3f GetMomentumWR() const { return x34_momentum; }

View File

@ -1,5 +1,7 @@
#include "MetroidPrime/CPhysicsActor.hpp" #include "MetroidPrime/CPhysicsActor.hpp"
const float CPhysicsActor::skGravityConstant = 9.81f * 2.5f;
CPhysicsActor::CPhysicsActor(TUniqueId uid, bool active, const rstl::string& name, CPhysicsActor::CPhysicsActor(TUniqueId uid, bool active, const rstl::string& name,
const CEntityInfo& info, const CTransform4f& xf, const CEntityInfo& info, const CTransform4f& xf,
const CModelData& mData, const CMaterialList& matList, const CModelData& mData, const CMaterialList& matList,
@ -80,15 +82,14 @@ void CPhysicsActor::ComputeDerivedQuantities() {
} }
CPhysicsState CPhysicsActor::GetPhysicsState() const { CPhysicsState CPhysicsActor::GetPhysicsState() const {
CQuaternion quat(CQuaternion::FromMatrix(x34_transform)); return CPhysicsState(GetTranslation(), GetRotation(), GetConstantForceWR(),
return CPhysicsState(GetTranslation(), quat, xfc_constantForce, x108_angularMomentum, GetAngularMomentumWR(), GetMomentumWR(), GetForceWR(), GetImpulseWR(),
x150_momentum, x15c_force, x168_impulse, x174_torque, x180_angularImpulse); GetTorqueWR(), GetAngularImpulseWR());
} }
void CPhysicsActor::SetPhysicsState(const CPhysicsState& state) { void CPhysicsActor::SetPhysicsState(const CPhysicsState& state) {
SetTranslation(state.GetTranslation()); SetTranslation(state.GetTranslation());
CQuaternion quat(state.GetOrientationWR()); CQuaternion quat = state.GetOrientationWR();
SetTransform(quat.BuildTransform4f(GetTranslation())); SetTransform(quat.BuildTransform4f(GetTranslation()));
xfc_constantForce = state.GetConstantForceWR(); xfc_constantForce = state.GetConstantForceWR();
x108_angularMomentum = state.GetAngularMomentumWR(); x108_angularMomentum = state.GetAngularMomentumWR();