mirror of https://github.com/zeldaret/botw.git
ksys/phys: Start adding RigidBodyMotion
This commit is contained in:
parent
fa2c98ddd5
commit
97938cc48e
|
@ -82960,7 +82960,7 @@ Address,Quality,Size,Name
|
|||
0x0000007100f8c4e4,U,000092,
|
||||
0x0000007100f8c540,U,000008,
|
||||
0x0000007100f8c548,U,000140,
|
||||
0x0000007100f8c5d4,O,000492,_ZN4ksys4phys9RigidBodyC1EjjP12hkpRigidBodyRKN4sead14SafeStringBaseIcEEPNS4_4HeapEb
|
||||
0x0000007100f8c5d4,O,000492,_ZN4ksys4phys9RigidBodyC1ENS1_4TypeEjP12hkpRigidBodyRKN4sead14SafeStringBaseIcEEPNS5_4HeapEb
|
||||
0x0000007100f8c7c0,U,000160,RigidBody::dtor
|
||||
0x0000007100f8c860,U,000160,
|
||||
0x0000007100f8c900,U,000168,RigidBody::dtorDelete
|
||||
|
@ -82968,7 +82968,7 @@ Address,Quality,Size,Name
|
|||
0x0000007100f8ca50,U,000584,phys::RigidBody::initMotionAccessor
|
||||
0x0000007100f8cc98,U,000172,phys::RigidBody::x
|
||||
0x0000007100f8cd44,U,000552,phys::RigidBody::initMotion
|
||||
0x0000007100f8cf6c,O,000052,_ZNK4ksys4phys9RigidBody7getNameEv
|
||||
0x0000007100f8cf6c,O,000052,_ZNK4ksys4phys9RigidBody13getHkBodyNameEv
|
||||
0x0000007100f8cfa0,U,000424,phys::RigidBody::x_0
|
||||
0x0000007100f8d148,O,000144,_ZN4ksys4phys9RigidBody13setMotionFlagENS1_10MotionFlagE
|
||||
0x0000007100f8d1d8,O,000032,_ZNK4ksys4phys9RigidBody8isActiveEv
|
||||
|
@ -83358,60 +83358,60 @@ Address,Quality,Size,Name
|
|||
0x0000007100fa195c,U,000008,
|
||||
0x0000007100fa1964,U,000288,
|
||||
0x0000007100fa1a84,U,000092,
|
||||
0x0000007100fa1ae0,U,000188,MotionAccessor1::ctor
|
||||
0x0000007100fa1b9c,U,000072,phys::RigidBodyMotion::dtor
|
||||
0x0000007100fa1be4,U,000080,phys::RigidBodyMotion::dtorDelete
|
||||
0x0000007100fa1c34,U,000172,phys::RigidBodyMotion::m21_init
|
||||
0x0000007100fa1ce0,U,000496,phys::RigidBodyMotion::m2_setTransform
|
||||
0x0000007100fa1ed0,U,000288,phys::RigidBodyMotion::m3_setPosition
|
||||
0x0000007100fa1ff0,U,000076,phys::RigidBodyMotion::m4_getPosition
|
||||
0x0000007100fa203c,U,000092,phys::RigidBodyMotion::m5_getRotation
|
||||
0x0000007100fa2098,U,000168,phys::RigidBodyMotion::getTransform
|
||||
0x0000007100fa2140,U,000124,phys::RigidBodyMotion::setCenter
|
||||
0x0000007100fa21bc,U,000024,phys::RigidBodyMotion::getCenter
|
||||
0x0000007100fa21d4,U,000220,phys::RigidBodyMotion::setLinearVel
|
||||
0x0000007100fa22b0,U,000172,phys::RigidBodyMotion::setLinearVel_0
|
||||
0x0000007100fa235c,U,000076,phys::RigidBodyMotion::getLinearVel
|
||||
0x0000007100fa23a8,U,000220,phys::RigidBodyMotion::setAngularVel
|
||||
0x0000007100fa2484,U,000172,phys::RigidBodyMotion::setAngularVel_0
|
||||
0x0000007100fa2530,U,000076,phys::RigidBodyMotion::getAngularVel
|
||||
0x0000007100fa257c,U,000060,phys::RigidBodyMotion::setMaxLinearVel
|
||||
0x0000007100fa25b8,U,000060,phys::RigidBodyMotion::getMaxLinearVel
|
||||
0x0000007100fa25f4,U,000060,phys::RigidBodyMotion::setMaxAngularVel
|
||||
0x0000007100fa2630,U,000060,phys::RigidBodyMotion::getMaxAngularVel
|
||||
0x0000007100fa266c,U,000272,
|
||||
0x0000007100fa277c,U,000308,
|
||||
0x0000007100fa28b0,U,000460,
|
||||
0x0000007100fa2a7c,U,000168,
|
||||
0x0000007100fa2b24,U,000028,
|
||||
0x0000007100fa2b40,U,000040,
|
||||
0x0000007100fa2b68,U,000776,
|
||||
0x0000007100fa2e70,U,000040,
|
||||
0x0000007100fa2e98,U,000420,
|
||||
0x0000007100fa303c,U,000112,
|
||||
0x0000007100fa30ac,U,000176,
|
||||
0x0000007100fa315c,U,000040,
|
||||
0x0000007100fa3184,U,000176,
|
||||
0x0000007100fa3234,U,000040,
|
||||
0x0000007100fa325c,U,000132,
|
||||
0x0000007100fa32e0,U,000036,phys::RigidBodyMotion::setTimeFactor
|
||||
0x0000007100fa3304,U,000020,phys::RigidBodyMotion::getTimeFactor
|
||||
0x0000007100fa3318,U,000068,phys::RigidBodyMotion::getRotation
|
||||
0x0000007100fa335c,U,000396,
|
||||
0x0000007100fa34e8,U,000392,
|
||||
0x0000007100fa3670,U,000404,
|
||||
0x0000007100fa3804,U,000188,
|
||||
0x0000007100fa38c0,U,000156,
|
||||
0x0000007100fa395c,U,000164,
|
||||
0x0000007100fa3a00,U,000124,
|
||||
0x0000007100fa3a7c,U,000520,phys::RigidBodyMotion::m25
|
||||
0x0000007100fa3c84,U,000204,phys::MotionAccessor1::rtti1
|
||||
0x0000007100fa3d50,U,000092,phys::MotionAccessor1::rtti2
|
||||
0x0000007100fa3dac,U,000020,phys::RigidBodyMotion::m26
|
||||
0x0000007100fa3dc0,U,000088,
|
||||
0x0000007100fa1ae0,O,000188,_ZN4ksys4phys15RigidBodyMotionC1EPNS0_9RigidBodyE
|
||||
0x0000007100fa1b9c,O,000072,_ZN4ksys4phys15RigidBodyMotionD1Ev
|
||||
0x0000007100fa1be4,O,000080,_ZN4ksys4phys15RigidBodyMotionD0Ev
|
||||
0x0000007100fa1c34,O,000172,_ZN4ksys4phys15RigidBodyMotion4initERKNS0_22RigidBodyInstanceParamEPN4sead4HeapE
|
||||
0x0000007100fa1ce0,O,000496,_ZN4ksys4phys15RigidBodyMotion12setTransformERKN4sead8Matrix34IfEEb
|
||||
0x0000007100fa1ed0,O,000288,_ZN4ksys4phys15RigidBodyMotion11setPositionERKN4sead7Vector3IfEEb
|
||||
0x0000007100fa1ff0,O,000076,_ZN4ksys4phys15RigidBodyMotion11getPositionEPN4sead7Vector3IfEE
|
||||
0x0000007100fa203c,O,000092,_ZN4ksys4phys15RigidBodyMotion11getRotationEPN4sead4QuatIfEE
|
||||
0x0000007100fa2098,O,000168,_ZN4ksys4phys15RigidBodyMotion12getTransformEPN4sead8Matrix34IfEE
|
||||
0x0000007100fa2140,O,000124,_ZN4ksys4phys15RigidBodyMotion22setCenterOfMassInLocalERKN4sead7Vector3IfEE
|
||||
0x0000007100fa21bc,O,000024,_ZN4ksys4phys15RigidBodyMotion22getCenterOfMassInLocalEPN4sead7Vector3IfEE
|
||||
0x0000007100fa21d4,O,000220,_ZN4ksys4phys15RigidBodyMotion17setLinearVelocityERKN4sead7Vector3IfEEf
|
||||
0x0000007100fa22b0,O,000172,_ZN4ksys4phys15RigidBodyMotion17setLinearVelocityERK10hkVector4ff
|
||||
0x0000007100fa235c,O,000076,_ZN4ksys4phys15RigidBodyMotion17getLinearVelocityEPN4sead7Vector3IfEE
|
||||
0x0000007100fa23a8,O,000220,_ZN4ksys4phys15RigidBodyMotion18setAngularVelocityERKN4sead7Vector3IfEEf
|
||||
0x0000007100fa2484,O,000172,_ZN4ksys4phys15RigidBodyMotion18setAngularVelocityERK10hkVector4ff
|
||||
0x0000007100fa2530,O,000076,_ZN4ksys4phys15RigidBodyMotion18getAngularVelocityEPN4sead7Vector3IfEE
|
||||
0x0000007100fa257c,O,000060,_ZN4ksys4phys15RigidBodyMotion20setMaxLinearVelocityEf
|
||||
0x0000007100fa25b8,O,000060,_ZN4ksys4phys15RigidBodyMotion20getMaxLinearVelocityEv
|
||||
0x0000007100fa25f4,O,000060,_ZN4ksys4phys15RigidBodyMotion21setMaxAngularVelocityEf
|
||||
0x0000007100fa2630,O,000060,_ZN4ksys4phys15RigidBodyMotion21getMaxAngularVelocityEv
|
||||
0x0000007100fa266c,O,000272,_ZN4ksys4phys15RigidBodyMotion18applyLinearImpulseERKN4sead7Vector3IfEE
|
||||
0x0000007100fa277c,O,000308,_ZN4ksys4phys15RigidBodyMotion19applyAngularImpulseERKN4sead7Vector3IfEE
|
||||
0x0000007100fa28b0,O,000460,_ZN4ksys4phys15RigidBodyMotion17applyPointImpulseERKN4sead7Vector3IfEES6_
|
||||
0x0000007100fa2a7c,O,000168,_ZN4ksys4phys15RigidBodyMotion7setMassEf
|
||||
0x0000007100fa2b24,O,000028,_ZNK4ksys4phys15RigidBodyMotion7getMassEv
|
||||
0x0000007100fa2b40,O,000040,_ZNK4ksys4phys15RigidBodyMotion10getMassInvEv
|
||||
0x0000007100fa2b68,U,000776,phys::RigidBodyMotion::setInertiaLocal
|
||||
0x0000007100fa2e70,O,000040,_ZNK4ksys4phys15RigidBodyMotion16getGravityFactorEv
|
||||
0x0000007100fa2e98,O,000420,_ZN4ksys4phys15RigidBodyMotion32updateRigidBodyMotionExceptStateEv
|
||||
0x0000007100fa303c,O,000112,_ZNK4ksys4phys15RigidBodyMotion15getInertiaLocalEPN4sead7Vector3IfEE
|
||||
0x0000007100fa30ac,O,000176,_ZN4ksys4phys15RigidBodyMotion16setLinearDampingEf
|
||||
0x0000007100fa315c,O,000040,_ZNK4ksys4phys15RigidBodyMotion16getLinearDampingEv
|
||||
0x0000007100fa3184,O,000176,_ZN4ksys4phys15RigidBodyMotion17setAngularDampingEf
|
||||
0x0000007100fa3234,O,000040,_ZNK4ksys4phys15RigidBodyMotion17getAngularDampingEv
|
||||
0x0000007100fa325c,O,000132,_ZN4ksys4phys15RigidBodyMotion16setGravityFactorEf
|
||||
0x0000007100fa32e0,O,000036,_ZN4ksys4phys15RigidBodyMotion13setTimeFactorEf
|
||||
0x0000007100fa3304,O,000020,_ZN4ksys4phys15RigidBodyMotion13getTimeFactorEv
|
||||
0x0000007100fa3318,O,000068,_ZN4ksys4phys15RigidBodyMotion11getRotationEP13hkQuaternionf
|
||||
0x0000007100fa335c,O,000396,_ZN4ksys4phys15RigidBodyMotion18processUpdateFlagsEv
|
||||
0x0000007100fa34e8,O,000392,_ZN4ksys4phys15RigidBodyMotion38updateRigidBodyMotionExceptStateAndVelEv
|
||||
0x0000007100fa3670,O,000404,_ZN4ksys4phys15RigidBodyMotion16registerAccessorEPNS0_20RigidBodyMotionProxyE
|
||||
0x0000007100fa3804,O,000188,_ZN4ksys4phys15RigidBodyMotion18deregisterAccessorEPNS0_20RigidBodyMotionProxyE
|
||||
0x0000007100fa38c0,O,000156,_ZN4ksys4phys15RigidBodyMotion22deregisterAllAccessorsEv
|
||||
0x0000007100fa395c,O,000164,_ZN4ksys4phys15RigidBodyMotion30copyTransformToAllLinkedBodiesEv
|
||||
0x0000007100fa3a00,O,000124,_ZN4ksys4phys15RigidBodyMotion27copyMotionToAllLinkedBodiesEv
|
||||
0x0000007100fa3a7c,O,000520,_ZN4ksys4phys15RigidBodyMotion6freezeEbbb
|
||||
0x0000007100fa3c84,O,000204,_ZNK4ksys4phys15RigidBodyMotion27checkDerivedRuntimeTypeInfoEPKN4sead15RuntimeTypeInfo9InterfaceE
|
||||
0x0000007100fa3d50,O,000092,_ZNK4ksys4phys15RigidBodyMotion18getRuntimeTypeInfoEv
|
||||
0x0000007100fa3dac,O,000020,_ZN4ksys4phys15RigidBodyMotion16resetFrozenStateEv
|
||||
0x0000007100fa3dc0,O,000088,_ZN16hkpMaxSizeMotionD0Ev
|
||||
0x0000007100fa3e18,O,000220,_ZN4ksys4phys20RigidBodyMotionProxyC1EPNS0_9RigidBodyE
|
||||
0x0000007100fa3ef4,U,000152,phys::RigidBodyMotionProxy::dtor
|
||||
0x0000007100fa3f8c,U,000144,
|
||||
0x0000007100fa3f8c,U,000144,phys::RigidBodyMotionProxy::resetLinkedRigidBody
|
||||
0x0000007100fa401c,U,000036,phys::RigidBodyMotionProxy::dtorDelete
|
||||
0x0000007100fa4040,O,000032,_ZN4ksys4phys20RigidBodyMotionProxy4initERKNS0_22RigidBodyInstanceParamEPN4sead4HeapE
|
||||
0x0000007100fa4060,O,000332,_ZN4ksys4phys20RigidBodyMotionProxy12setTransformERKN4sead8Matrix34IfEEb
|
||||
|
@ -105332,7 +105332,7 @@ Address,Quality,Size,Name
|
|||
0x00000071016116fc,U,000072,
|
||||
0x0000007101611744,U,000096,
|
||||
0x00000071016117a4,U,000280,
|
||||
0x00000071016118bc,U,000208,
|
||||
0x00000071016118bc,U,000208,hkpRigidBody::updateCachedShapeInfo
|
||||
0x000000710161198c,L,000436,createDynamicRigidMotion
|
||||
0x0000007101611b40,L,001160,hkpRigidBody::hkpRigidBody
|
||||
0x0000007101611fc8,L,000172,hkpRigidBody::enableDeactivation
|
||||
|
|
Can't render this file because it is too large.
|
|
@ -26,8 +26,8 @@ public:
|
|||
bool hasMotionFlagDisabled(RigidBody::MotionFlag flag) const;
|
||||
void disableMotionFlag(RigidBody::MotionFlag flag);
|
||||
|
||||
virtual void setTransform(const sead::Matrix34f& mtx, bool notify) = 0;
|
||||
virtual void setPosition(const sead::Vector3f& position, bool notify) = 0;
|
||||
virtual void setTransform(const sead::Matrix34f& mtx, bool propagate_to_linked_motions) = 0;
|
||||
virtual void setPosition(const sead::Vector3f& position, bool propagate_to_linked_motions) = 0;
|
||||
virtual void getPosition(sead::Vector3f* position) = 0;
|
||||
virtual void getRotation(sead::Quatf* rotation) = 0;
|
||||
virtual void getTransform(sead::Matrix34f* mtx) = 0;
|
||||
|
@ -53,8 +53,12 @@ public:
|
|||
virtual void getRotation(hkQuaternionf* quat) = 0;
|
||||
virtual void setTimeFactor(float factor) = 0;
|
||||
virtual float getTimeFactor() = 0;
|
||||
virtual void m25(bool a, bool b, bool c) = 0;
|
||||
virtual void m26() = 0;
|
||||
|
||||
virtual void freeze(bool freeze, bool preserve_velocities, bool preserve_max_impulse) = 0;
|
||||
virtual void resetFrozenState() = 0;
|
||||
|
||||
RigidBody* getBody() const { return mBody; }
|
||||
hkpRigidBody* getHkBody() const { return mBody->getHkBody(); }
|
||||
|
||||
protected:
|
||||
RigidBody* mBody = nullptr;
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
|
||||
namespace ksys::phys {
|
||||
|
||||
RigidBody::RigidBody(u32 a, u32 mass_scaling, hkpRigidBody* hk_body, const sead::SafeString& name,
|
||||
sead::Heap* heap, bool a7)
|
||||
: mCS(heap), mHkBody(hk_body), mRigidBodyAccessor(hk_body), _b4(a) {
|
||||
RigidBody::RigidBody(Type type, u32 mass_scaling, hkpRigidBody* hk_body,
|
||||
const sead::SafeString& name, sead::Heap* heap, bool a7)
|
||||
: mCS(heap), mHkBody(hk_body), mRigidBodyAccessor(hk_body), mType(type) {
|
||||
if (!name.isEmpty()) {
|
||||
mHkBody->setName(name.cstr());
|
||||
}
|
||||
|
@ -20,13 +20,13 @@ RigidBody::RigidBody(u32 a, u32 mass_scaling, hkpRigidBody* hk_body, const sead:
|
|||
mHkBody->m_responseModifierFlags |= hkpResponseModifier::Flags::MASS_SCALING;
|
||||
}
|
||||
|
||||
mFlags.change(Flag::_80, _b4 == 5);
|
||||
mFlags.change(Flag::IsCharacterController, isCharacterControllerType());
|
||||
mFlags.change(Flag::MassScaling, mass_scaling == 1);
|
||||
mFlags.change(Flag::_10, a7);
|
||||
mFlags.set(Flag::_100);
|
||||
}
|
||||
|
||||
sead::SafeString RigidBody::getName() const {
|
||||
sead::SafeString RigidBody::getHkBodyName() const {
|
||||
const char* name = mHkBody->getName();
|
||||
if (!name)
|
||||
return sead::SafeString::cEmptyString;
|
||||
|
|
|
@ -28,6 +28,16 @@ public:
|
|||
class RigidBody : public sead::IDisposer, public RigidBase {
|
||||
SEAD_RTTI_BASE(RigidBody)
|
||||
public:
|
||||
enum class Type {
|
||||
_0 = 0,
|
||||
_1 = 1,
|
||||
_2 = 2,
|
||||
TerrainHeightField = 3,
|
||||
_4 = 4,
|
||||
CharacterController = 5,
|
||||
TeraMesh = 6,
|
||||
};
|
||||
|
||||
enum class Flag {
|
||||
MassScaling = 1 << 0,
|
||||
_2 = 1 << 1,
|
||||
|
@ -36,8 +46,19 @@ public:
|
|||
_10 = 1 << 4,
|
||||
_20 = 1 << 5,
|
||||
_40 = 1 << 6,
|
||||
_80 = 1 << 7,
|
||||
IsCharacterController = 1 << 7,
|
||||
_100 = 1 << 8,
|
||||
_200 = 1 << 9,
|
||||
_400 = 1 << 10,
|
||||
_800 = 1 << 11,
|
||||
_1000 = 1 << 12,
|
||||
_2000 = 1 << 13,
|
||||
_4000 = 1 << 14,
|
||||
_8000 = 1 << 15,
|
||||
_10000 = 1 << 16,
|
||||
_20000 = 1 << 17,
|
||||
_40000 = 1 << 18,
|
||||
_80000 = 1 << 19,
|
||||
};
|
||||
|
||||
enum class MotionFlag {
|
||||
|
@ -53,9 +74,17 @@ public:
|
|||
_200 = 1 << 9,
|
||||
_400 = 1 << 10,
|
||||
_800 = 1 << 11,
|
||||
_1000 = 1 << 12,
|
||||
_2000 = 1 << 13,
|
||||
_4000 = 1 << 14,
|
||||
_8000 = 1 << 15,
|
||||
_10000 = 1 << 16,
|
||||
_20000 = 1 << 17,
|
||||
_40000 = 1 << 18,
|
||||
_80000 = 1 << 19,
|
||||
};
|
||||
|
||||
RigidBody(u32 a, u32 mass_scaling, hkpRigidBody* hk_body, const sead::SafeString& name,
|
||||
RigidBody(Type type, u32 mass_scaling, hkpRigidBody* hk_body, const sead::SafeString& name,
|
||||
sead::Heap* heap, bool a7);
|
||||
~RigidBody() override;
|
||||
|
||||
|
@ -71,16 +100,17 @@ public:
|
|||
virtual void m11();
|
||||
virtual void m12();
|
||||
virtual void m13();
|
||||
virtual void m14();
|
||||
virtual const char* getName();
|
||||
|
||||
// 0x0000007100f8ca50
|
||||
bool initMotionAccessor(sead::Heap* heap);
|
||||
// 0x0000007100f8cc98
|
||||
void initMotionAndAccessor();
|
||||
// 0x0000007100f8cd44
|
||||
void initMotion();
|
||||
void initMotion(hkpMotion* motion, MotionType motion_type,
|
||||
const RigidBodyInstanceParam& params);
|
||||
|
||||
sead::SafeString getName() const;
|
||||
sead::SafeString getHkBodyName() const;
|
||||
|
||||
// 0x0000007100f8cfa0
|
||||
void x_0();
|
||||
|
@ -151,12 +181,62 @@ public:
|
|||
void sub_7100F8FA44(ContactLayer, u32);
|
||||
hkpMotion* getMotion() const;
|
||||
|
||||
// 0x0000007100f9004c
|
||||
void getTransform(sead::Matrix34f* mtx) const;
|
||||
// 0x0000007100f8fb08
|
||||
void setTransform(const sead::Matrix34f& mtx, bool propagate_to_linked_motions);
|
||||
|
||||
// 0x0000007100f8ec3c
|
||||
bool setLinearVelocity(const sead::Vector3f& velocity, float epsilon);
|
||||
// 0x0000007100f9118c
|
||||
void getLinearVelocity(sead::Vector3f* velocity) const;
|
||||
// 0x0000007100f911ac
|
||||
sead::Vector3f getLinearVelocity() const;
|
||||
|
||||
// 0x0000007100f8ed74
|
||||
bool setAngularVelocity(const sead::Vector3f& velocity, float epsilon);
|
||||
// 0x0000007100f911f8
|
||||
void getAngularVelocity(sead::Vector3f* velocity) const;
|
||||
// 0x0000007100f91218
|
||||
sead::Vector3f getAngularVelocity() const;
|
||||
|
||||
// 0x0000007100f93348
|
||||
void setMass(float mass);
|
||||
// 0x0000007100f933fc
|
||||
float getMass() const;
|
||||
// 0x0000007100f93498
|
||||
float getMassInv() const;
|
||||
|
||||
// 0x0000007100f93534
|
||||
void setInertiaLocal(const sead::Vector3f& inertia);
|
||||
// 0x0000007100f935dc
|
||||
void getInertiaLocal(sead::Vector3f* inertia) const;
|
||||
// 0x0000007100f9368c
|
||||
sead::Vector3f getInertiaLocal() const;
|
||||
|
||||
// 0x0000007100f93750
|
||||
void setLinearDamping(float value);
|
||||
// 0x0000007100f93804
|
||||
float getLinearDamping() const;
|
||||
// 0x0000007100f938a0
|
||||
void setAngularDamping(float value);
|
||||
// 0x0000007100f93954
|
||||
float getAngularDamping() const;
|
||||
// 0x0000007100f939f0
|
||||
void setGravityFactor(float value);
|
||||
// 0x0000007100f93a9c
|
||||
float getGravityFactor() const;
|
||||
|
||||
bool isMassScaling() const { return mFlags.isOn(Flag::MassScaling); }
|
||||
bool hasFlag(Flag flag) const { return mFlags.isOn(flag); }
|
||||
const auto& getMotionFlags() const { return mMotionFlags; }
|
||||
void resetMotionFlagDirect(const MotionFlag flag) { mMotionFlags.reset(flag); }
|
||||
|
||||
hkpRigidBody* getHkBody() const { return mHkBody; }
|
||||
|
||||
Type getType() const { return mType; }
|
||||
bool isCharacterControllerType() const { return mType == Type::CharacterController; }
|
||||
|
||||
private:
|
||||
sead::CriticalSection mCS;
|
||||
sead::TypedBitFlag<Flag, sead::Atomic<u32>> mFlags{};
|
||||
|
@ -169,7 +249,7 @@ private:
|
|||
u16 _98 = 0;
|
||||
RigidBodyAccessor mRigidBodyAccessor;
|
||||
f32 _b0 = 1.0f;
|
||||
u32 _b4 = 0;
|
||||
Type mType{};
|
||||
MotionAccessor* mMotionAccessor = nullptr;
|
||||
u16 _c0 = 0;
|
||||
u16 _c2 = 0;
|
||||
|
|
|
@ -1 +1,601 @@
|
|||
#include "KingSystem/Physics/RigidBody/physRigidBodyMotion.h"
|
||||
#include <Havok/Physics2012/Dynamics/Entity/hkpRigidBody.h>
|
||||
#include <Havok/Physics2012/Dynamics/Motion/Rigid/hkpKeyframedRigidMotion.h>
|
||||
#include <Havok/Physics2012/Dynamics/Motion/hkpMotion.h>
|
||||
#include <basis/seadTypes.h>
|
||||
#include <prim/seadSafeString.h>
|
||||
#include <prim/seadScopedLock.h>
|
||||
#include "KingSystem/Physics/RigidBody/physRigidBodyMotionProxy.h"
|
||||
#include "KingSystem/Physics/physConversions.h"
|
||||
#include "KingSystem/Utils/Debug.h"
|
||||
|
||||
namespace ksys::phys {
|
||||
|
||||
static float sImpulseEpsilon = 1e-05;
|
||||
static float sMaxImpulse = 1700.0;
|
||||
|
||||
RigidBodyMotion::RigidBodyMotion(RigidBody* body) : MotionAccessor(body) {}
|
||||
|
||||
RigidBodyMotion::~RigidBodyMotion() {
|
||||
if (mMotion) {
|
||||
delete[] reinterpret_cast<u8*>(mMotion);
|
||||
mMotion = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool RigidBodyMotion::init(const RigidBodyInstanceParam& params, sead::Heap* heap) {
|
||||
auto* motion_storage = new (heap, alignof(hkpMaxSizeMotion)) u8[sizeof(hkpMaxSizeMotion)];
|
||||
mMotion = new (motion_storage) hkpMaxSizeMotion;
|
||||
mBody->initMotion(mMotion, MotionType::Dynamic, params);
|
||||
mMaxImpulse = params.max_impulse;
|
||||
mColImpulseScale = params.col_impulse_scale;
|
||||
mFrictionScale = params.friction_scale;
|
||||
mRestitutionScale = params.restitution_scale;
|
||||
mWaterBuoyancyScale = params.water_buoyancy_scale;
|
||||
mWaterFlowEffectiveRate = params.water_flow_effective_rate;
|
||||
mMagneMassScalingFactor = params.magne_mass_scaling_factor;
|
||||
return true;
|
||||
}
|
||||
|
||||
void RigidBodyMotion::setTransform(const sead::Matrix34f& mtx, bool propagate_to_linked_motions) {
|
||||
hkTransformf transform;
|
||||
toHkTransform(&transform, mtx);
|
||||
mMotion->setTransform(transform);
|
||||
|
||||
if (mBody->isFlag8Set()) {
|
||||
setMotionFlag(RigidBody::MotionFlag::_20);
|
||||
} else {
|
||||
getHkBody()->getMotion()->setTransform(transform);
|
||||
}
|
||||
|
||||
if (propagate_to_linked_motions) {
|
||||
for (int i = 0, n = mLinkedAccessors.size(); i < n; ++i) {
|
||||
auto* accessor = mLinkedAccessors[i];
|
||||
accessor->setTransformMaybe(mtx);
|
||||
accessor->setLinearVelocity(sead::Vector3f::zero, sead::Mathf::epsilon());
|
||||
accessor->setAngularVelocity(sead::Vector3f::zero, sead::Mathf::epsilon());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RigidBodyMotion::setPosition(const sead::Vector3f& position,
|
||||
bool propagate_to_linked_motions) {
|
||||
auto* motion = getMotionDependingOnFlag(RigidBody::MotionFlag::_20);
|
||||
const auto hk_position = toHkVec4(position);
|
||||
const auto& hk_rotate = motion->getRotation();
|
||||
|
||||
mMotion->setPositionAndRotation(hk_position, hk_rotate);
|
||||
|
||||
if (mBody->isFlag8Set()) {
|
||||
setMotionFlag(RigidBody::MotionFlag::_20);
|
||||
} else {
|
||||
getHkBody()->getMotion()->setPositionAndRotation(hk_position, hk_rotate);
|
||||
}
|
||||
|
||||
if (propagate_to_linked_motions) {
|
||||
for (int i = 0, n = mLinkedAccessors.size(); i < n; ++i) {
|
||||
auto* accessor = mLinkedAccessors[i];
|
||||
accessor->setTransformMaybe(hk_position, hk_rotate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RigidBodyMotion::getPosition(sead::Vector3f* position) {
|
||||
auto* motion = getMotionDependingOnFlag(RigidBody::MotionFlag::_20);
|
||||
const auto hk_position = motion->getPosition();
|
||||
storeToVec3(position, hk_position);
|
||||
}
|
||||
|
||||
void RigidBodyMotion::getRotation(sead::Quatf* rotation) {
|
||||
auto* motion = getMotionDependingOnFlag(RigidBody::MotionFlag::_20);
|
||||
toQuat(rotation, motion->getRotation());
|
||||
}
|
||||
|
||||
void RigidBodyMotion::getTransform(sead::Matrix34f* mtx) {
|
||||
auto* motion = getMotionDependingOnFlag(RigidBody::MotionFlag::_20);
|
||||
setMtxRotation(mtx, motion->getTransform().getRotation());
|
||||
setMtxTranslation(mtx, motion->getTransform().getTranslation());
|
||||
}
|
||||
|
||||
void RigidBodyMotion::setCenterOfMassInLocal(const sead::Vector3f& center) {
|
||||
const auto hk_center = toHkVec4(center);
|
||||
mMotion->setCenterOfMassInLocal(hk_center);
|
||||
|
||||
if (mBody->isFlag8Set())
|
||||
setMotionFlag(RigidBody::MotionFlag::_800);
|
||||
else
|
||||
getHkBody()->setCenterOfMassLocal(hk_center);
|
||||
}
|
||||
|
||||
void RigidBodyMotion::getCenterOfMassInLocal(sead::Vector3f* center) {
|
||||
const auto hk_center = mMotion->getCenterOfMassLocal();
|
||||
storeToVec3(center, hk_center);
|
||||
}
|
||||
|
||||
bool RigidBodyMotion::setLinearVelocity(const sead::Vector3f& velocity, float epsilon) {
|
||||
sead::Vector3f current_vel;
|
||||
getLinearVelocity(¤t_vel);
|
||||
if (current_vel.equals(velocity, epsilon))
|
||||
return false;
|
||||
|
||||
mMotion->setLinearVelocity(toHkVec4(velocity));
|
||||
setMotionFlag(RigidBody::MotionFlag::_40);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RigidBodyMotion::setLinearVelocity(const hkVector4f& velocity, float epsilon) {
|
||||
auto* motion = getMotionDependingOnFlag(RigidBody::MotionFlag::_40);
|
||||
if (velocity.allEqual<3>(motion->getLinearVelocity(), epsilon))
|
||||
return false;
|
||||
|
||||
mMotion->setLinearVelocity(velocity);
|
||||
setMotionFlag(RigidBody::MotionFlag::_40);
|
||||
return true;
|
||||
}
|
||||
|
||||
void RigidBodyMotion::getLinearVelocity(sead::Vector3f* velocity) {
|
||||
auto* motion = getMotionDependingOnFlag(RigidBody::MotionFlag::_40);
|
||||
const auto hk_vel = motion->getLinearVelocity();
|
||||
storeToVec3(velocity, hk_vel);
|
||||
}
|
||||
|
||||
bool RigidBodyMotion::setAngularVelocity(const sead::Vector3f& velocity, float epsilon) {
|
||||
sead::Vector3f current_vel;
|
||||
getAngularVelocity(¤t_vel);
|
||||
if (current_vel.equals(velocity, epsilon))
|
||||
return false;
|
||||
|
||||
mMotion->setAngularVelocity(toHkVec4(velocity));
|
||||
setMotionFlag(RigidBody::MotionFlag::_80);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RigidBodyMotion::setAngularVelocity(const hkVector4f& velocity, float epsilon) {
|
||||
auto* motion = getMotionDependingOnFlag(RigidBody::MotionFlag::_80);
|
||||
if (velocity.allEqual<3>(motion->getAngularVelocity(), epsilon))
|
||||
return false;
|
||||
|
||||
mMotion->setAngularVelocity(velocity);
|
||||
setMotionFlag(RigidBody::MotionFlag::_80);
|
||||
return true;
|
||||
}
|
||||
|
||||
void RigidBodyMotion::getAngularVelocity(sead::Vector3f* velocity) {
|
||||
auto* motion = getMotionDependingOnFlag(RigidBody::MotionFlag::_80);
|
||||
const auto hk_vel = motion->getAngularVelocity();
|
||||
storeToVec3(velocity, hk_vel);
|
||||
}
|
||||
|
||||
void RigidBodyMotion::setMaxLinearVelocity(float max) {
|
||||
mMotion->getMotionState()->m_maxLinearVelocity = max;
|
||||
setMotionFlag(RigidBody::MotionFlag::_100);
|
||||
}
|
||||
|
||||
float RigidBodyMotion::getMaxLinearVelocity() {
|
||||
return mMotion->getMotionState()->m_maxLinearVelocity;
|
||||
}
|
||||
|
||||
void RigidBodyMotion::setMaxAngularVelocity(float max) {
|
||||
mMotion->getMotionState()->m_maxAngularVelocity = max;
|
||||
setMotionFlag(RigidBody::MotionFlag::_100);
|
||||
}
|
||||
|
||||
float RigidBodyMotion::getMaxAngularVelocity() {
|
||||
return mMotion->getMotionState()->m_maxAngularVelocity;
|
||||
}
|
||||
|
||||
bool RigidBodyMotion::applyLinearImpulse(const sead::Vector3f& impulse) {
|
||||
if (getMotionType() != MotionType::Dynamic)
|
||||
return false;
|
||||
|
||||
if (!mMotion)
|
||||
return false;
|
||||
|
||||
if (impulse.equals(sead::Vector3f::zero, sImpulseEpsilon))
|
||||
return false;
|
||||
|
||||
if (hasMotionFlagDisabled(RigidBody::MotionFlag::_40)) {
|
||||
mMotion->setLinearVelocity(getRigidBodyMotion()->getLinearVelocity());
|
||||
}
|
||||
|
||||
mMotion->applyLinearImpulse(toHkVec4(impulse));
|
||||
setMotionFlag(RigidBody::MotionFlag::_40);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RigidBodyMotion::applyAngularImpulse(const sead::Vector3f& impulse) {
|
||||
if (getMotionType() != MotionType::Dynamic)
|
||||
return false;
|
||||
|
||||
if (!mMotion)
|
||||
return false;
|
||||
|
||||
if (impulse.equals(sead::Vector3f::zero, sImpulseEpsilon))
|
||||
return false;
|
||||
|
||||
if (hasMotionFlagDisabled(RigidBody::MotionFlag::_20)) {
|
||||
auto& rotation = mMotion->getMotionState()->getSweptTransform().m_rotation1;
|
||||
rotation = getRigidBodyMotion()->getRotation();
|
||||
}
|
||||
|
||||
if (hasMotionFlagDisabled(RigidBody::MotionFlag::_80)) {
|
||||
mMotion->setAngularVelocity(getRigidBodyMotion()->getAngularVelocity());
|
||||
}
|
||||
|
||||
mMotion->applyAngularImpulse(toHkVec4(impulse));
|
||||
setMotionFlag(RigidBody::MotionFlag::_80);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RigidBodyMotion::applyPointImpulse(const sead::Vector3f& impulse,
|
||||
const sead::Vector3f& point) {
|
||||
if (getMotionType() != MotionType::Dynamic)
|
||||
return false;
|
||||
|
||||
if (!mMotion)
|
||||
return false;
|
||||
|
||||
if (impulse.equals(sead::Vector3f::zero, sImpulseEpsilon))
|
||||
return false;
|
||||
|
||||
if (hasMotionFlagDisabled(RigidBody::MotionFlag::_20)) {
|
||||
auto* state = mMotion->getMotionState();
|
||||
auto* body_state = getRigidBodyMotion()->getMotionState();
|
||||
|
||||
if (hasMotionFlagDisabled(RigidBody::MotionFlag::_800)) {
|
||||
state->getSweptTransform().m_centerOfMass1 =
|
||||
body_state->getSweptTransform().m_centerOfMass1;
|
||||
}
|
||||
|
||||
state->getTransform() = body_state->getTransform();
|
||||
}
|
||||
|
||||
if (hasMotionFlagDisabled(RigidBody::MotionFlag::_40)) {
|
||||
mMotion->setLinearVelocity(getRigidBodyMotion()->getLinearVelocity());
|
||||
}
|
||||
|
||||
if (hasMotionFlagDisabled(RigidBody::MotionFlag::_80)) {
|
||||
mMotion->setAngularVelocity(getRigidBodyMotion()->getAngularVelocity());
|
||||
}
|
||||
|
||||
mMotion->applyPointImpulse(toHkVec4(impulse), toHkVec4(point));
|
||||
setMotionFlag(RigidBody::MotionFlag::_40);
|
||||
setMotionFlag(RigidBody::MotionFlag::_80);
|
||||
return true;
|
||||
}
|
||||
|
||||
void RigidBodyMotion::setMass(float mass) {
|
||||
if (bodyHasFlag80000()) {
|
||||
mMass = mass;
|
||||
return;
|
||||
}
|
||||
|
||||
mMotion->setMass(mass);
|
||||
if (mBody->isFlag8Set())
|
||||
setMotionFlag(RigidBody::MotionFlag::_400);
|
||||
else if (mBody->getMotionType() == MotionType::Dynamic)
|
||||
getHkBody()->getMotion()->setMass(mass);
|
||||
}
|
||||
|
||||
float RigidBodyMotion::getMass() const {
|
||||
if (bodyHasFlag80000())
|
||||
return mMass;
|
||||
|
||||
return mMotion->getMass();
|
||||
}
|
||||
|
||||
float RigidBodyMotion::getMassInv() const {
|
||||
if (bodyHasFlag80000())
|
||||
return 1.0f / mMass;
|
||||
|
||||
return mMotion->getMassInv();
|
||||
}
|
||||
|
||||
void RigidBodyMotion::getInertiaLocal(sead::Vector3f* inertia) const {
|
||||
if (bodyHasFlag80000()) {
|
||||
inertia->e = mInertiaLocal.e;
|
||||
return;
|
||||
}
|
||||
|
||||
hkMatrix3f hk_inertia;
|
||||
mMotion->getInertiaLocal(hk_inertia);
|
||||
inertia->x = hk_inertia.getColumn(0).getX();
|
||||
inertia->y = hk_inertia.getColumn(1).getY();
|
||||
inertia->z = hk_inertia.getColumn(2).getZ();
|
||||
}
|
||||
|
||||
void RigidBodyMotion::setLinearDamping(float value) {
|
||||
if (bodyHasFlag80000()) {
|
||||
mLinearDamping = value;
|
||||
return;
|
||||
}
|
||||
|
||||
mMotion->setLinearDamping(value);
|
||||
if (mBody->isFlag8Set())
|
||||
setMotionFlag(RigidBody::MotionFlag::_2000);
|
||||
else if (mBody->getMotionType() == MotionType::Dynamic)
|
||||
getHkBody()->setLinearDamping(getTimeFactor() * value);
|
||||
}
|
||||
|
||||
float RigidBodyMotion::getLinearDamping() const {
|
||||
if (bodyHasFlag80000())
|
||||
return mLinearDamping;
|
||||
|
||||
return mMotion->getLinearDamping();
|
||||
}
|
||||
|
||||
void RigidBodyMotion::setAngularDamping(float value) {
|
||||
if (bodyHasFlag80000()) {
|
||||
mAngularDamping = value;
|
||||
return;
|
||||
}
|
||||
|
||||
mMotion->setAngularDamping(value);
|
||||
if (mBody->isFlag8Set())
|
||||
setMotionFlag(RigidBody::MotionFlag::_2000);
|
||||
else if (mBody->getMotionType() == MotionType::Dynamic)
|
||||
getHkBody()->setAngularDamping(getTimeFactor() * value);
|
||||
}
|
||||
|
||||
float RigidBodyMotion::getAngularDamping() const {
|
||||
if (bodyHasFlag80000())
|
||||
return mAngularDamping;
|
||||
|
||||
return mMotion->getAngularDamping();
|
||||
}
|
||||
|
||||
void RigidBodyMotion::setGravityFactor(float value) {
|
||||
if (bodyHasFlag80000()) {
|
||||
mGravityFactor = value;
|
||||
return;
|
||||
}
|
||||
|
||||
mMotion->setGravityFactor(value);
|
||||
if (mBody->isFlag8Set())
|
||||
setMotionFlag(RigidBody::MotionFlag::_2000);
|
||||
else if (mBody->getMotionType() == MotionType::Dynamic)
|
||||
getHkBody()->setGravityFactor(value);
|
||||
}
|
||||
|
||||
float RigidBodyMotion::getGravityFactor() const {
|
||||
if (bodyHasFlag80000())
|
||||
return mGravityFactor;
|
||||
|
||||
return mMotion->getGravityFactor();
|
||||
}
|
||||
|
||||
void RigidBodyMotion::setTimeFactor(float factor) {
|
||||
mMotion->setTimeFactor(factor);
|
||||
setMotionFlag(RigidBody::MotionFlag::_100);
|
||||
}
|
||||
|
||||
float RigidBodyMotion::getTimeFactor() {
|
||||
return mMotion->getTimeFactor();
|
||||
}
|
||||
|
||||
void RigidBodyMotion::getRotation(hkQuaternionf* quat) {
|
||||
auto* motion = getMotionDependingOnFlag(RigidBody::MotionFlag::_20);
|
||||
*quat = motion->getRotation();
|
||||
}
|
||||
|
||||
void RigidBodyMotion::processUpdateFlags() {
|
||||
auto* body = getHkBody();
|
||||
auto* body_motion = body->getMotion();
|
||||
|
||||
if (hasMotionFlagSet(RigidBody::MotionFlag::_400)) {
|
||||
body_motion->setMassInv(mMotion->getMassInv());
|
||||
disableMotionFlag(RigidBody::MotionFlag::_400);
|
||||
}
|
||||
|
||||
if (hasMotionFlagSet(RigidBody::MotionFlag::_1000)) {
|
||||
if (!mBody->isCharacterControllerType()) {
|
||||
hkMatrix3 inertia;
|
||||
mMotion->getInertiaInvLocal(inertia);
|
||||
body_motion->setInertiaInvLocal(inertia);
|
||||
}
|
||||
disableMotionFlag(RigidBody::MotionFlag::_1000);
|
||||
}
|
||||
|
||||
if (hasMotionFlagSet(RigidBody::MotionFlag::_2000)) {
|
||||
if (mBody->hasFlag(RigidBody::Flag::_20000)) {
|
||||
body->setLinearDamping(1.0);
|
||||
body->setAngularDamping(1.0);
|
||||
body->setGravityFactor(0.0);
|
||||
} else {
|
||||
body->setLinearDamping(mMotion->getLinearDamping());
|
||||
body->setAngularDamping(mMotion->getAngularDamping());
|
||||
body->setGravityFactor(mMotion->getGravityFactor());
|
||||
}
|
||||
disableMotionFlag(RigidBody::MotionFlag::_2000);
|
||||
}
|
||||
|
||||
if (hasMotionFlagSet(RigidBody::MotionFlag::_200)) {
|
||||
updateRigidBodyMotionExceptState();
|
||||
disableMotionFlag(RigidBody::MotionFlag::_200);
|
||||
}
|
||||
}
|
||||
|
||||
void RigidBodyMotion::updateRigidBodyMotionExceptState() {
|
||||
// Copy everything from our hkpMotion to the rigid body's internal motion
|
||||
// except the hkMotionState data.
|
||||
const hkMotionState state = *getHkBody()->getMotion()->getMotionState();
|
||||
|
||||
// This is technically undefined behaviour because hkpMaxSizeMotion is not trivially
|
||||
// copyable and it is also a dynamic class.
|
||||
// However, the copy should work fine considering both the destination and the source
|
||||
// are hkpMaxSizeMotion objects.
|
||||
std::memcpy(static_cast<void*>(getHkBody()->getMotion()), static_cast<const void*>(mMotion),
|
||||
sizeof(hkpMaxSizeMotion));
|
||||
|
||||
*getHkBody()->getMotion()->getMotionState() = state;
|
||||
|
||||
// Fix up pointers and invalidate cached info.
|
||||
switch (mBody->getMotionType()) {
|
||||
case MotionType::Dynamic:
|
||||
getHkBody()->setQualityType(mBody->hasFlag(RigidBody::Flag::IsCharacterController) ?
|
||||
HK_COLLIDABLE_QUALITY_BULLET :
|
||||
HK_COLLIDABLE_QUALITY_DEBRIS);
|
||||
break;
|
||||
case MotionType::Fixed:
|
||||
getHkBody()->setQualityType(hkpCollidableQualityType::HK_COLLIDABLE_QUALITY_FIXED);
|
||||
break;
|
||||
case MotionType::Keyframed:
|
||||
getHkBody()->setQualityType(
|
||||
hkpCollidableQualityType::HK_COLLIDABLE_QUALITY_KEYFRAMED_REPORTING);
|
||||
break;
|
||||
case MotionType::Unknown:
|
||||
case MotionType::Invalid:
|
||||
break;
|
||||
}
|
||||
|
||||
getHkBody()->getCollidableRw()->setMotionState(getHkBody()->getMotion()->getMotionState());
|
||||
|
||||
hkVector4f extent_out;
|
||||
if (auto* shape = getHkBody()->getCollidable()->getShape())
|
||||
getHkBody()->updateCachedShapeInfo(shape, extent_out);
|
||||
}
|
||||
|
||||
void RigidBodyMotion::updateRigidBodyMotionExceptStateAndVel() {
|
||||
// See updateRigidBodyMotionExceptState() for explanations.
|
||||
const hkMotionState state = *getHkBody()->getMotion()->getMotionState();
|
||||
const auto linear_vel = getHkBody()->getMotion()->getLinearVelocity();
|
||||
const auto angular_vel = getHkBody()->getMotion()->getAngularVelocity();
|
||||
const auto deactivation_counter = getHkBody()->getMotion()->m_deactivationIntegrateCounter;
|
||||
|
||||
std::memcpy(static_cast<void*>(getHkBody()->getMotion()), static_cast<const void*>(mMotion),
|
||||
sizeof(hkpMaxSizeMotion));
|
||||
|
||||
*getHkBody()->getMotion()->getMotionState() = state;
|
||||
getHkBody()->getMotion()->m_linearVelocity = linear_vel;
|
||||
getHkBody()->getMotion()->m_angularVelocity = angular_vel;
|
||||
getHkBody()->setQualityType(mBody->hasFlag(RigidBody::Flag::IsCharacterController) ?
|
||||
HK_COLLIDABLE_QUALITY_BULLET :
|
||||
HK_COLLIDABLE_QUALITY_DEBRIS);
|
||||
getHkBody()->getMotion()->m_deactivationIntegrateCounter = deactivation_counter;
|
||||
}
|
||||
|
||||
bool RigidBodyMotion::registerAccessor(RigidBodyMotionProxy* accessor) {
|
||||
auto lock = sead::makeScopedLock(mCS);
|
||||
|
||||
if (mLinkedAccessors.isFull()) {
|
||||
sead::FixedSafeString<128> list;
|
||||
for (int i = 0, n = mLinkedAccessors.size(); i < n; ++i) {
|
||||
if (i != 0)
|
||||
list.appendWithFormat(", ");
|
||||
list.appendWithFormat("%s:%s", mLinkedAccessors[i]->getBody()->getName(),
|
||||
mLinkedAccessors[i]->getBody()->getHkBodyName().cstr());
|
||||
};
|
||||
util::PrintDebugFmt("failed to register accessor. existing list: %s", list);
|
||||
return false;
|
||||
}
|
||||
|
||||
mLinkedAccessors.pushBack(accessor);
|
||||
|
||||
if (mFlags.isOff(Flag::_2) && mBody->isFlag8Set())
|
||||
setMotionFlag(RigidBody::MotionFlag::_80000);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RigidBodyMotion::deregisterAccessor(RigidBodyMotionProxy* accessor) {
|
||||
auto lock = sead::makeScopedLock(mCS);
|
||||
|
||||
const int idx = mLinkedAccessors.indexOf(accessor);
|
||||
if (idx < 0)
|
||||
return false;
|
||||
|
||||
// Found the accessor -- now we just need to erase it.
|
||||
if (mFlags.isOn(Flag::_2) && mBody->isFlag8Set())
|
||||
setMotionFlag(RigidBody::MotionFlag::_80000);
|
||||
mLinkedAccessors.erase(idx);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RigidBodyMotion::deregisterAllAccessors() {
|
||||
auto lock = sead::makeScopedLock(mCS);
|
||||
|
||||
// For efficiency reasons, deregister starting from the end of the array.
|
||||
// Popping from the end is O(1) while erasing from the beginning of a n-sized array
|
||||
// would lead to a total complexity of O(n^2).
|
||||
for (int i = 0, n = mLinkedAccessors.size(); i < n; ++i) {
|
||||
mLinkedAccessors.back()->resetLinkedRigidBody();
|
||||
}
|
||||
|
||||
if (mFlags.isOn(Flag::_2) && mBody->isFlag8Set())
|
||||
setMotionFlag(RigidBody::MotionFlag::_80000);
|
||||
return true;
|
||||
}
|
||||
|
||||
void RigidBodyMotion::copyTransformToAllLinkedBodies() {
|
||||
auto lock = sead::makeScopedLock(mCS);
|
||||
|
||||
for (int i = 0, n = mLinkedAccessors.size(); i < n; ++i) {
|
||||
auto* body = mLinkedAccessors[i]->getBody();
|
||||
if (!body->isFlag8Set() && body->isMotionFlag1Set()) {
|
||||
sead::Matrix34f transform;
|
||||
mBody->getTransform(&transform);
|
||||
body->setTransform(transform, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RigidBodyMotion::copyMotionToAllLinkedBodies() {
|
||||
auto lock = sead::makeScopedLock(mCS);
|
||||
|
||||
for (int i = 0, n = mLinkedAccessors.size(); i < n; ++i) {
|
||||
mLinkedAccessors[i]->copyMotionFromLinkedRigidBody();
|
||||
}
|
||||
}
|
||||
|
||||
void RigidBodyMotion::freeze(bool freeze, bool preserve_velocities, bool preserve_max_impulse) {
|
||||
if (!freeze) {
|
||||
setLinearVelocity(mLinearVelocity, sead::Mathf::epsilon());
|
||||
setAngularVelocity(mAngularVelocity, sead::Mathf::epsilon());
|
||||
mBody->setLinearDamping(mLinearDamping);
|
||||
mBody->setAngularDamping(mAngularDamping);
|
||||
mBody->setInertiaLocal(mInertiaLocal);
|
||||
mBody->setMass(mMass);
|
||||
mBody->setGravityFactor(mGravityFactor);
|
||||
mMaxImpulse = mMaxImpulseCopy;
|
||||
return;
|
||||
}
|
||||
|
||||
const float mass_factor = mFlags.isOn(Flag::_200) ? 20.0 : 1000.0;
|
||||
|
||||
if (preserve_velocities) {
|
||||
mLinearVelocity = mBody->getLinearVelocity();
|
||||
mAngularVelocity = mBody->getAngularVelocity();
|
||||
} else {
|
||||
mLinearVelocity.set(0, 0, 0);
|
||||
mAngularVelocity.set(0, 0, 0);
|
||||
}
|
||||
|
||||
mLinearDamping = mBody->getLinearDamping();
|
||||
mAngularDamping = mBody->getAngularDamping();
|
||||
mInertiaLocal = mBody->getInertiaLocal();
|
||||
mMass = mBody->getMass();
|
||||
mGravityFactor = mBody->getGravityFactor();
|
||||
mMaxImpulseCopy = mMaxImpulse;
|
||||
|
||||
mBody->setLinearVelocity(sead::Vector3f::zero, sead::Mathf::epsilon());
|
||||
mBody->setLinearDamping(1.0);
|
||||
mBody->setAngularVelocity(sead::Vector3f::zero, sead::Mathf::epsilon());
|
||||
mBody->setAngularDamping(1.0);
|
||||
|
||||
mBody->setInertiaLocal(mInertiaLocal * mass_factor);
|
||||
mBody->setMass(mMass * mass_factor);
|
||||
mBody->setGravityFactor(0.0);
|
||||
|
||||
if (!preserve_max_impulse)
|
||||
mMaxImpulse = sMaxImpulse;
|
||||
}
|
||||
|
||||
void RigidBodyMotion::setImpulseEpsilon(float epsilon) {
|
||||
sImpulseEpsilon = epsilon;
|
||||
}
|
||||
|
||||
void RigidBodyMotion::setMaxImpulse(float max_impulse) {
|
||||
sMaxImpulse = max_impulse;
|
||||
}
|
||||
|
||||
} // namespace ksys::phys
|
||||
|
|
|
@ -1,19 +1,125 @@
|
|||
#pragma once
|
||||
|
||||
#include <container/seadPtrArray.h>
|
||||
#include <prim/seadTypedBitFlag.h>
|
||||
#include <thread/seadAtomic.h>
|
||||
#include <thread/seadCriticalSection.h>
|
||||
#include "KingSystem/Physics/RigidBody/physMotionAccessor.h"
|
||||
#include "KingSystem/Physics/RigidBody/physRigidBody.h"
|
||||
|
||||
class hkpMotion;
|
||||
|
||||
namespace ksys::phys {
|
||||
|
||||
class RigidBodyMotionProxy;
|
||||
|
||||
class RigidBodyMotion : public MotionAccessor {
|
||||
SEAD_RTTI_OVERRIDE(RigidBodyMotion, MotionAccessor)
|
||||
public:
|
||||
enum class Flag {
|
||||
_1 = 1 << 0,
|
||||
_2 = 1 << 1,
|
||||
_200 = 1 << 9,
|
||||
};
|
||||
|
||||
explicit RigidBodyMotion(RigidBody* body);
|
||||
|
||||
void setTransform(const sead::Matrix34f& mtx, bool propagate_to_linked_motions) override;
|
||||
void setPosition(const sead::Vector3f& position, bool propagate_to_linked_motions) override;
|
||||
void getPosition(sead::Vector3f* position) override;
|
||||
void getRotation(sead::Quatf* rotation) override;
|
||||
void getTransform(sead::Matrix34f* mtx) override;
|
||||
|
||||
void setCenterOfMassInLocal(const sead::Vector3f& center) override;
|
||||
void getCenterOfMassInLocal(sead::Vector3f* center) override;
|
||||
|
||||
bool setLinearVelocity(const sead::Vector3f& velocity, float epsilon) override;
|
||||
bool setLinearVelocity(const hkVector4f& velocity, float epsilon) override;
|
||||
void getLinearVelocity(sead::Vector3f* velocity) override;
|
||||
bool setAngularVelocity(const sead::Vector3f& velocity, float epsilon) override;
|
||||
bool setAngularVelocity(const hkVector4f& velocity, float epsilon) override;
|
||||
void getAngularVelocity(sead::Vector3f* velocity) override;
|
||||
|
||||
void setMaxLinearVelocity(float max) override;
|
||||
float getMaxLinearVelocity() override;
|
||||
void setMaxAngularVelocity(float max) override;
|
||||
float getMaxAngularVelocity() override;
|
||||
|
||||
~RigidBodyMotion() override;
|
||||
|
||||
bool init(const RigidBodyInstanceParam& params, sead::Heap* heap) override;
|
||||
void getRotation(hkQuaternionf* quat) override;
|
||||
void setTimeFactor(float factor) override;
|
||||
float getTimeFactor() override;
|
||||
|
||||
void freeze(bool freeze, bool preserve_velocities, bool preserve_max_impulse) override;
|
||||
void resetFrozenState() override {
|
||||
mLinearVelocity.set(0, 0, 0);
|
||||
mAngularVelocity.set(0, 0, 0);
|
||||
}
|
||||
|
||||
bool applyLinearImpulse(const sead::Vector3f& impulse);
|
||||
bool applyAngularImpulse(const sead::Vector3f& impulse);
|
||||
bool applyPointImpulse(const sead::Vector3f& impulse, const sead::Vector3f& point);
|
||||
|
||||
void setMass(float mass);
|
||||
float getMass() const;
|
||||
float getMassInv() const;
|
||||
|
||||
// 0x0000007100fa2b68
|
||||
void setInertiaLocal(const sead::Vector3f&);
|
||||
void getInertiaLocal(sead::Vector3f* inertia) const;
|
||||
|
||||
void setLinearDamping(float value);
|
||||
float getLinearDamping() const;
|
||||
void setAngularDamping(float value);
|
||||
float getAngularDamping() const;
|
||||
void setGravityFactor(float value);
|
||||
float getGravityFactor() const;
|
||||
|
||||
void processUpdateFlags();
|
||||
void updateRigidBodyMotionExceptState();
|
||||
void updateRigidBodyMotionExceptStateAndVel();
|
||||
|
||||
bool registerAccessor(RigidBodyMotionProxy* accessor);
|
||||
bool deregisterAccessor(RigidBodyMotionProxy* accessor);
|
||||
bool deregisterAllAccessors();
|
||||
void copyTransformToAllLinkedBodies();
|
||||
void copyMotionToAllLinkedBodies();
|
||||
|
||||
static void setImpulseEpsilon(float epsilon);
|
||||
static void setMaxImpulse(float max_impulse);
|
||||
|
||||
private:
|
||||
hkpMotion* getMotionDependingOnFlag(RigidBody::MotionFlag use_local_motion_condition) const {
|
||||
if (hasMotionFlagSet(use_local_motion_condition))
|
||||
return mMotion;
|
||||
return getRigidBodyMotion();
|
||||
}
|
||||
|
||||
bool bodyHasFlag80000() const { return mBody->hasFlag(RigidBody::Flag::_80000); }
|
||||
|
||||
sead::Vector3f mLinearVelocity = sead::Vector3f::zero;
|
||||
float mLinearDamping{};
|
||||
sead::Vector3f mAngularVelocity = sead::Vector3f::zero;
|
||||
float mAngularDamping{};
|
||||
sead::Vector3f mInertiaLocal = sead::Vector3f::zero;
|
||||
float mMass{};
|
||||
float mGravityFactor{};
|
||||
float mMaxImpulseCopy{};
|
||||
hkpMotion* mMotion{};
|
||||
sead::FixedPtrArray<RigidBodyMotionProxy, 8> mLinkedAccessors;
|
||||
float mWaterBuoyancyScale = 1.0f;
|
||||
float mWaterFlowEffectiveRate = 1.0f;
|
||||
float mMagneMassScalingFactor = 1.0f;
|
||||
float mFrictionScale = 1.0f;
|
||||
float mRestitutionScale = 1.0f;
|
||||
float mMaxImpulse = -1.0f;
|
||||
float mColImpulseScale = 1.0f;
|
||||
sead::Atomic<u32> _c4;
|
||||
sead::TypedBitFlag<Flag, sead::Atomic<u32>> mFlags;
|
||||
u32 _cc{};
|
||||
sead::CriticalSection mCS;
|
||||
};
|
||||
|
||||
} // namespace ksys::phys
|
||||
|
|
|
@ -25,12 +25,14 @@ KSYS_ALWAYS_INLINE void RigidBodyMotionProxy::setTransformImpl(const sead::Matri
|
|||
mBody->getHkBody()->getMotion()->setTransform(transform);
|
||||
}
|
||||
|
||||
void RigidBodyMotionProxy::setTransform(const sead::Matrix34f& mtx, bool notify) {
|
||||
void RigidBodyMotionProxy::setTransform(const sead::Matrix34f& mtx,
|
||||
bool propagate_to_linked_motions) {
|
||||
mTransform = mtx;
|
||||
setTransformImpl(mtx);
|
||||
}
|
||||
|
||||
void RigidBodyMotionProxy::setPosition(const sead::Vector3f& position, bool notify) {
|
||||
void RigidBodyMotionProxy::setPosition(const sead::Vector3f& position,
|
||||
bool propagate_to_linked_motions) {
|
||||
if (hasMotionFlagDisabled(RigidBody::MotionFlag::_20)) {
|
||||
getTransform(&mTransform);
|
||||
}
|
||||
|
|
|
@ -16,8 +16,8 @@ public:
|
|||
|
||||
explicit RigidBodyMotionProxy(RigidBody* body);
|
||||
|
||||
void setTransform(const sead::Matrix34f& mtx, bool notify) override;
|
||||
void setPosition(const sead::Vector3f& position, bool notify) override;
|
||||
void setTransform(const sead::Matrix34f& mtx, bool propagate_to_linked_motions) override;
|
||||
void setPosition(const sead::Vector3f& position, bool propagate_to_linked_motions) override;
|
||||
// 0x0000007100fa4318
|
||||
void setTransformMaybe(const sead::Matrix34f& mtx);
|
||||
// 0x0000007100fa4594
|
||||
|
@ -47,8 +47,8 @@ public:
|
|||
void resetLinkedRigidBody();
|
||||
RigidBody* getLinkedRigidBody() const;
|
||||
bool isFlag40000Set() const;
|
||||
// 0x0000007100fa5058 - main update function? triggers shape, position, velocity updates
|
||||
void update();
|
||||
// 0x0000007100fa5058 - triggers shape, position, velocity updates
|
||||
void copyMotionFromLinkedRigidBody();
|
||||
|
||||
~RigidBodyMotionProxy() override;
|
||||
|
||||
|
@ -56,8 +56,8 @@ public:
|
|||
void getRotation(hkQuaternionf* quat) override;
|
||||
void setTimeFactor(float factor) override;
|
||||
float getTimeFactor() override;
|
||||
void m25(bool a, bool b, bool c) override;
|
||||
void m26() override;
|
||||
void freeze(bool freeze, bool preserve_velocities, bool preserve_max_impulse) override;
|
||||
void resetFrozenState() override;
|
||||
|
||||
private:
|
||||
void setTransformImpl(const sead::Matrix34f& mtx);
|
||||
|
|
Loading…
Reference in New Issue