2022-10-09 05:13:17 +00:00
|
|
|
#ifndef _CPHYSICSACTOR
|
|
|
|
#define _CPHYSICSACTOR
|
2022-09-18 05:55:13 +00:00
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
|
|
|
|
#include "MetroidPrime/CActor.hpp"
|
|
|
|
#include "MetroidPrime/CAxisAngle.hpp"
|
2022-10-05 17:24:06 +00:00
|
|
|
#include "MetroidPrime/CPhysicsState.hpp"
|
2022-09-18 05:55:13 +00:00
|
|
|
|
|
|
|
#include "Kyoto/Math/CAABox.hpp"
|
|
|
|
#include "Kyoto/Math/CMatrix3f.hpp"
|
|
|
|
#include "Kyoto/Math/CNUQuaternion.hpp"
|
|
|
|
#include "Kyoto/Math/CVector3f.hpp"
|
|
|
|
|
|
|
|
#include "Collision/CCollidableAABox.hpp"
|
|
|
|
|
|
|
|
#include "rstl/optional_object.hpp"
|
|
|
|
|
|
|
|
struct SMoverData {
|
|
|
|
CVector3f x0_velocity;
|
|
|
|
CAxisAngle xc_angularVelocity;
|
|
|
|
CVector3f x18_momentum;
|
|
|
|
CAxisAngle x24_;
|
2022-10-09 05:37:23 +00:00
|
|
|
float x30_mass;
|
2022-09-18 05:55:13 +00:00
|
|
|
|
2022-10-20 15:43:17 +00:00
|
|
|
SMoverData(float mass, const CVector3f& velocity = CVector3f::Zero(),
|
|
|
|
const CAxisAngle& angularVelocity = CAxisAngle::Identity(),
|
|
|
|
const CVector3f& momentum = CVector3f::Zero(),
|
|
|
|
const CAxisAngle& unk = CAxisAngle::Identity())
|
2022-09-18 05:55:13 +00:00
|
|
|
: x0_velocity(velocity)
|
|
|
|
, xc_angularVelocity(angularVelocity)
|
|
|
|
, x18_momentum(momentum)
|
|
|
|
, x24_(unk)
|
|
|
|
, x30_mass(mass) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
class CMotionState {
|
|
|
|
public:
|
2022-10-05 16:28:37 +00:00
|
|
|
CMotionState(const CVector3f& translation, const CNUQuaternion& orientation,
|
|
|
|
const CVector3f& velocity, const CAxisAngle& angularMomentum)
|
|
|
|
: x0_translation(translation)
|
|
|
|
, xc_orientation(orientation)
|
|
|
|
, x1c_velocity(velocity)
|
|
|
|
, x28_angularMomentum(angularMomentum) {}
|
2022-09-18 05:55:13 +00:00
|
|
|
|
2022-10-17 23:53:49 +00:00
|
|
|
const CVector3f& GetTranslation() const { return x0_translation; }
|
|
|
|
const CNUQuaternion& GetOrientation() const { return xc_orientation; }
|
|
|
|
const CVector3f& GetVelocity() const { return x1c_velocity; }
|
|
|
|
const CAxisAngle& GetAngularMomentum() const { return x28_angularMomentum; }
|
|
|
|
|
2022-09-18 05:55:13 +00:00
|
|
|
private:
|
|
|
|
CVector3f x0_translation;
|
|
|
|
CNUQuaternion xc_orientation;
|
|
|
|
CVector3f x1c_velocity;
|
|
|
|
CAxisAngle x28_angularMomentum;
|
|
|
|
};
|
|
|
|
CHECK_SIZEOF(CMotionState, 0x34)
|
|
|
|
|
|
|
|
class CCollisionInfoList;
|
|
|
|
|
|
|
|
class CPhysicsActor : public CActor {
|
2022-10-28 21:42:35 +00:00
|
|
|
static const float kGravityAccel;
|
2022-10-05 17:53:15 +00:00
|
|
|
|
2022-09-18 05:55:13 +00:00
|
|
|
public:
|
|
|
|
CPhysicsActor(TUniqueId uid, bool active, const rstl::string& name, const CEntityInfo& info,
|
|
|
|
const CTransform4f& xf, const CModelData& mData, const CMaterialList& matList,
|
|
|
|
const CAABox& aabb, const SMoverData& moverData, const CActorParameters& actParams,
|
2022-10-09 05:37:23 +00:00
|
|
|
float stepUp, float stepDown);
|
2022-09-18 05:55:13 +00:00
|
|
|
|
|
|
|
// CActor
|
2023-02-06 17:01:01 +00:00
|
|
|
~CPhysicsActor() override;
|
|
|
|
void Render(const CStateManager&) const override;
|
|
|
|
CVector3f GetOrbitPosition(const CStateManager& mgr) const override;
|
|
|
|
CVector3f GetAimPosition(const CStateManager& mgr, float val) const override;
|
2022-09-18 05:55:13 +00:00
|
|
|
|
|
|
|
// CPhysicsActor
|
|
|
|
virtual const CCollisionPrimitive* GetCollisionPrimitive() const;
|
|
|
|
virtual CTransform4f GetPrimitiveTransform() const;
|
2022-10-08 05:12:48 +00:00
|
|
|
virtual void CollidedWith(const TUniqueId& id, const CCollisionInfoList& list,
|
|
|
|
CStateManager& mgr);
|
2022-10-09 05:37:23 +00:00
|
|
|
virtual float GetStepDownHeight() const;
|
|
|
|
virtual float GetStepUpHeight() const;
|
|
|
|
virtual float GetWeight() const;
|
2022-10-05 22:50:12 +00:00
|
|
|
float GetMass() const { return xe8_mass; }
|
2022-10-05 16:28:37 +00:00
|
|
|
void SetMass(float mass);
|
2022-11-04 12:22:09 +00:00
|
|
|
void SetInertiaTensorScalar(float tensor);
|
2022-09-18 05:55:13 +00:00
|
|
|
|
2022-11-04 12:22:09 +00:00
|
|
|
const CAABox& GetBaseBoundingBox() const;
|
2022-09-18 05:55:13 +00:00
|
|
|
CAABox GetBoundingBox() const;
|
2022-11-04 12:22:09 +00:00
|
|
|
void SetBoundingBox(const CAABox& box);
|
|
|
|
CAABox GetMotionVolume(float dt) const;
|
2022-10-05 16:28:37 +00:00
|
|
|
|
|
|
|
void ApplyImpulseWR(const CVector3f& impulse, const CAxisAngle& angularImpulse);
|
2022-10-05 17:24:06 +00:00
|
|
|
void ApplyTorqueWR(const CVector3f& torque);
|
|
|
|
void ApplyForceWR(const CVector3f& force, const CAxisAngle& torque);
|
|
|
|
|
|
|
|
void ApplyImpulseOR(const CVector3f& impulse, const CAxisAngle& angularImpulse);
|
|
|
|
void ApplyForceOR(const CVector3f& impulse, const CAxisAngle& torque);
|
|
|
|
|
2022-09-19 04:19:46 +00:00
|
|
|
void MoveCollisionPrimitive(const CVector3f&);
|
2022-10-03 04:49:11 +00:00
|
|
|
void SetVelocityWR(const CVector3f&);
|
2022-10-02 10:13:35 +00:00
|
|
|
void SetAngularVelocityWR(const CAxisAngle& angVel);
|
2022-10-05 16:28:37 +00:00
|
|
|
void SetVelocityOR(const CVector3f& vel);
|
2022-10-03 11:55:03 +00:00
|
|
|
CAxisAngle GetAngularVelocityOR() const;
|
2022-10-05 16:28:37 +00:00
|
|
|
void SetAngularVelocityOR(const CAxisAngle& angleVel);
|
2022-10-03 04:49:11 +00:00
|
|
|
void ClearForcesAndTorques();
|
2022-10-05 22:50:12 +00:00
|
|
|
void ClearImpulses();
|
2022-10-05 16:28:37 +00:00
|
|
|
void ComputeDerivedQuantities();
|
2022-10-05 22:50:12 +00:00
|
|
|
void UseCollisionImpulses();
|
|
|
|
bool WillMove(const CStateManager& mgr);
|
2022-09-21 05:18:07 +00:00
|
|
|
void Stop();
|
|
|
|
|
2022-11-04 12:22:09 +00:00
|
|
|
CVector3f GetPrimitiveOffset() const;
|
2024-11-03 19:15:10 +00:00
|
|
|
const bool IsStandardCollider() const { return xf9_standardCollider; } // name and type?
|
|
|
|
void SetStandardCollider(const bool v) { xf9_standardCollider = v; } // name and type?
|
2022-10-05 17:53:15 +00:00
|
|
|
const CVector3f& GetConstantForceWR() const { return xfc_constantForce; }
|
|
|
|
void SetConstantForceWR(const CVector3f& force) { xfc_constantForce = force; }
|
|
|
|
const CAxisAngle& GetAngularMomentumWR() const { return x108_angularMomentum; }
|
2022-10-08 05:12:48 +00:00
|
|
|
void SetAngularMomentumWR(const CAxisAngle& angularMomentum) {
|
|
|
|
x108_angularMomentum = angularMomentum;
|
|
|
|
}
|
2024-09-28 19:43:23 +00:00
|
|
|
const CVector3f& GetVelocityWR() const { return x138_velocity; }
|
2022-10-05 17:53:15 +00:00
|
|
|
const CVector3f& GetMomentumWR() const { return x150_momentum; }
|
2022-10-06 08:40:00 +00:00
|
|
|
void SetMomentumWR(const CVector3f& momentum) { x150_momentum = momentum; }
|
2022-10-05 17:53:15 +00:00
|
|
|
const CVector3f& GetForceWR() const { return x15c_force; }
|
2022-10-06 08:40:00 +00:00
|
|
|
void SetForceWR(const CVector3f& force) { x15c_force = force; }
|
2022-10-05 17:53:15 +00:00
|
|
|
const CVector3f& GetImpulseWR() const { return x168_impulse; }
|
2022-10-06 08:40:00 +00:00
|
|
|
void SetImpulseWR(const CVector3f& impulse) { x168_impulse = impulse; }
|
2022-10-05 17:53:15 +00:00
|
|
|
const CAxisAngle& GetTorqueWR() const { return x174_torque; }
|
2022-10-06 08:40:00 +00:00
|
|
|
void SetTorqueWR(const CAxisAngle& torque) { x174_torque = torque; }
|
2022-10-05 17:53:15 +00:00
|
|
|
const CAxisAngle& GetAngularImpulseWR() const { return x180_angularImpulse; }
|
2022-10-08 05:12:48 +00:00
|
|
|
void SetAngularImpulseWR(const CAxisAngle& angularImpulse) {
|
|
|
|
x180_angularImpulse = angularImpulse;
|
|
|
|
}
|
2024-09-26 05:54:05 +00:00
|
|
|
void SetLastNonCollidingState(const CMotionState& state) { x1f4_lastNonCollidingState = state; }
|
2022-10-05 17:53:15 +00:00
|
|
|
|
2022-11-04 12:22:09 +00:00
|
|
|
float GetCoefficientOfRestitutionModifier() const;
|
|
|
|
void SetCoefficientOfRestitutionModifier(float modifier);
|
|
|
|
float GetCollisionAccuracyModifier() const;
|
|
|
|
void SetCollisionAccuracyModifier(float modifier);
|
|
|
|
float GetMaximumCollisionVelocity() const;
|
2024-09-26 05:54:05 +00:00
|
|
|
void SetMaxVelocityAfterCollision(float velocity);
|
2022-11-04 12:22:09 +00:00
|
|
|
|
2022-10-05 17:24:06 +00:00
|
|
|
CPhysicsState GetPhysicsState() const;
|
|
|
|
void SetPhysicsState(const CPhysicsState& state);
|
2022-09-21 05:18:07 +00:00
|
|
|
CMotionState GetMotionState() const;
|
|
|
|
void SetMotionState(const CMotionState& state);
|
2022-10-05 22:50:12 +00:00
|
|
|
CVector3f CalculateNewVelocityWR_UsingImpulses() const;
|
|
|
|
CMotionState PredictMotion(float dt) const;
|
|
|
|
CMotionState PredictAngularMotion(float dt) const;
|
|
|
|
CMotionState PredictLinearMotion(float dt) const;
|
|
|
|
CMotionState PredictMotion_Internal(float dt) const;
|
|
|
|
void AddMotionState(const CMotionState& state);
|
2022-09-18 05:55:13 +00:00
|
|
|
bool GetMovable() const { return xf8_24_movable; }
|
|
|
|
void SetMovable(bool v) { xf8_24_movable = v; }
|
|
|
|
|
2022-10-05 22:50:12 +00:00
|
|
|
void MoveToWR(const CVector3f&, float);
|
2022-10-06 08:40:00 +00:00
|
|
|
void MoveToInOneFrameWR(const CVector3f&, float);
|
|
|
|
CVector3f GetMoveToORImpulseWR(const CVector3f& impulse, float d) const;
|
2022-11-04 10:50:34 +00:00
|
|
|
CVector3f GetRotateToORAngularMomentumWR(const CQuaternion& q, float d) const;
|
2022-10-05 22:50:12 +00:00
|
|
|
void RotateToWR(const CQuaternion&, float);
|
2024-09-26 05:54:05 +00:00
|
|
|
|
2022-11-04 12:22:09 +00:00
|
|
|
void MoveInOneFrameOR(const CVector3f& trans, float d);
|
|
|
|
void RotateInOneFrameOR(const CQuaternion&, float);
|
2022-10-05 22:50:12 +00:00
|
|
|
|
2022-10-05 18:05:56 +00:00
|
|
|
void MoveToOR(const CVector3f&, float);
|
|
|
|
void RotateToOR(const CQuaternion&, float);
|
|
|
|
|
2022-11-04 12:22:09 +00:00
|
|
|
CVector3f GetTotalForceWR() const;
|
2024-11-03 19:15:10 +00:00
|
|
|
CVector3f GetConstantTotalForceWR() const { return x15c_force + x150_momentum; }
|
2022-10-05 22:50:12 +00:00
|
|
|
|
2022-10-28 21:42:35 +00:00
|
|
|
static float GravityConstant() { return kGravityAccel; }
|
2022-10-05 17:53:15 +00:00
|
|
|
|
2022-09-18 05:55:13 +00:00
|
|
|
private:
|
2022-10-09 05:37:23 +00:00
|
|
|
float xe8_mass;
|
|
|
|
float xec_massRecip;
|
|
|
|
float xf0_inertiaTensor;
|
|
|
|
float xf4_inertiaTensorRecip;
|
2022-09-18 05:55:13 +00:00
|
|
|
bool xf8_24_movable : 1;
|
|
|
|
bool xf8_25_angularEnabled : 1;
|
2024-09-28 19:43:23 +00:00
|
|
|
uchar xf9_standardCollider;
|
2022-09-18 05:55:13 +00:00
|
|
|
CVector3f xfc_constantForce;
|
|
|
|
CAxisAngle x108_angularMomentum;
|
|
|
|
CMatrix3f x114_;
|
|
|
|
CVector3f x138_velocity;
|
|
|
|
CAxisAngle x144_angularVelocity;
|
|
|
|
CVector3f x150_momentum;
|
|
|
|
CVector3f x15c_force;
|
|
|
|
CVector3f x168_impulse;
|
|
|
|
CAxisAngle x174_torque;
|
|
|
|
CAxisAngle x180_angularImpulse;
|
|
|
|
CVector3f x18c_moveImpulse;
|
|
|
|
CAxisAngle x198_moveAngularImpulse;
|
|
|
|
CAABox x1a4_baseBoundingBox;
|
|
|
|
CCollidableAABox x1c0_collisionPrimitive;
|
|
|
|
CVector3f x1e8_primitiveOffset;
|
|
|
|
CMotionState x1f4_lastNonCollidingState;
|
|
|
|
rstl::optional_object< CVector3f > x228_lastFloorPlaneNormal;
|
2022-10-09 05:37:23 +00:00
|
|
|
float x238_maximumCollisionVelocity;
|
|
|
|
float x23c_stepUpHeight;
|
|
|
|
float x240_stepDownHeight;
|
|
|
|
float x244_restitutionCoefModifier;
|
|
|
|
float x248_collisionAccuracyModifier;
|
2022-09-18 05:55:13 +00:00
|
|
|
uint x24c_numTicksStuck;
|
|
|
|
uint x250_numTicksPartialUpdate;
|
2022-10-05 16:28:37 +00:00
|
|
|
uint x254_;
|
2022-09-18 05:55:13 +00:00
|
|
|
};
|
|
|
|
CHECK_SIZEOF(CPhysicsActor, 0x258)
|
|
|
|
|
2022-10-09 05:13:17 +00:00
|
|
|
#endif // _CPHYSICSACTOR
|