diff --git a/data/uking_functions.csv b/data/uking_functions.csv index 1211e6e9..ee4707c7 100644 --- a/data/uking_functions.csv +++ b/data/uking_functions.csv @@ -83313,8 +83313,8 @@ Address,Quality,Size,Name 0x0000007100f9cd38,O,000108,_ZN4ksys4phys18RigidBodyFromShapeD0Ev 0x0000007100f9cda4,O,000112,_ZThn32_N4ksys4phys18RigidBodyFromShapeD0Ev 0x0000007100f9ce14,U,000948, -0x0000007100f9d1c8,U,000036, -0x0000007100f9d1ec,U,000244, +0x0000007100f9d1c8,O,000036,_ZN4ksys4phys18RigidBodyFromShape17getNewHavokShape_Ev +0x0000007100f9d1ec,O,000244,_ZN4ksys4phys18RigidBodyFromShape12updateScale_Eff 0x0000007100f9d2e0,O,000204,_ZNK4ksys4phys18RigidBodyFromShape27checkDerivedRuntimeTypeInfoEPKN4sead15RuntimeTypeInfo9InterfaceE 0x0000007100f9d3ac,O,000092,_ZNK4ksys4phys18RigidBodyFromShape18getRuntimeTypeInfoEv 0x0000007100f9d408,U,000904, @@ -83602,7 +83602,7 @@ Address,Quality,Size,Name 0x0000007100fabe80,O,000192,_ZN4ksys4phys12CapsuleShape14sub_7100FABE80EPN4sead7Vector3IfEES5_RK12hkTransformf 0x0000007100fabf40,U,000204, 0x0000007100fac00c,U,000092, -0x0000007100fac068,U,000008, +0x0000007100fac068,O,000008,_ZNK4ksys4phys12CapsuleShape7getTypeEv 0x0000007100fac070,U,000420, 0x0000007100fac214,U,000192, 0x0000007100fac2d4,U,000884, diff --git a/src/KingSystem/Physics/RigidBody/Shape/physCapsuleShape.h b/src/KingSystem/Physics/RigidBody/Shape/physCapsuleShape.h index 3fb26bf9..0dd22d62 100644 --- a/src/KingSystem/Physics/RigidBody/Shape/physCapsuleShape.h +++ b/src/KingSystem/Physics/RigidBody/Shape/physCapsuleShape.h @@ -36,9 +36,11 @@ public: CapsuleShape(const CapsuleShapeParam& shape_, hkpShape* hkp_shape_); ~CapsuleShape() override; + ShapeType getType() const override { return ShapeType::Capsule; } + float getVolume() const override; hkpShape* getHavokShape() override; const hkpShape* getHavokShape() const override; - void updateHavokShape() override; + hkpShape* updateHavokShape() override; void setScale(float scale) override; RigidBody* createBody(bool flag, const RigidBodyInstanceParam& params, sead::Heap* heap); @@ -47,7 +49,6 @@ public: void getVertices(sead::Vector3f* va, sead::Vector3f* vb) const; bool setRadius(f32 r); bool setVertices(const sead::Vector3f& va, const sead::Vector3f& vb); - f32 getVolume() const; void sub_7100FABE80(sead::Vector3f* veca, sead::Vector3f* vecb, const hkTransformf& rb_vec); void setMaterialMask(const MaterialMask& mask); diff --git a/src/KingSystem/Physics/RigidBody/Shape/physShape.h b/src/KingSystem/Physics/RigidBody/Shape/physShape.h index 2bc8c973..4cab1053 100644 --- a/src/KingSystem/Physics/RigidBody/Shape/physShape.h +++ b/src/KingSystem/Physics/RigidBody/Shape/physShape.h @@ -23,11 +23,13 @@ class Shape { public: Shape() = default; + virtual ShapeType getType() const = 0; + virtual float getVolume() const = 0; virtual ~Shape() = default; - virtual hkpShape* getHavokShape() = 0; virtual const hkpShape* getHavokShape() const = 0; - virtual void updateHavokShape() = 0; + virtual hkpShape* updateHavokShape() = 0; + /// @param scale New scale (relative to the current scale) virtual void setScale(float scale) = 0; }; diff --git a/src/KingSystem/Physics/RigidBody/physRigidBodyFromShape.cpp b/src/KingSystem/Physics/RigidBody/physRigidBodyFromShape.cpp index 85507c87..5e0e297b 100644 --- a/src/KingSystem/Physics/RigidBody/physRigidBodyFromShape.cpp +++ b/src/KingSystem/Physics/RigidBody/physRigidBodyFromShape.cpp @@ -1,5 +1,6 @@ #include "KingSystem/Physics/RigidBody/physRigidBodyFromShape.h" #include +#include "KingSystem/Physics/RigidBody/Shape/physShape.h" namespace ksys::phys { @@ -17,4 +18,31 @@ RigidBodyFromShape::~RigidBodyFromShape() { operator delete(mHkBody); } +const hkpShape* RigidBodyFromShape::getNewHavokShape_() { + return getShape_()->updateHavokShape(); +} + +float RigidBodyFromShape::updateScale_(float scale, float old_scale) { + if (scale == old_scale) + return old_scale; + + // Relative scale. + const float ratio = scale / old_scale; + + getShape_()->setScale(ratio); + updateShape(); + + setCenterOfMassInLocal(getCenterOfMassInLocal() * ratio); + + if (isEntity()) { + const float scale3 = ratio * ratio * ratio; + setMass(getMass() * scale3); + + const float scale5 = scale3 * ratio * ratio; + setInertiaLocal(getInertiaLocal() * scale5); + } + + return scale; +} + } // namespace ksys::phys diff --git a/src/KingSystem/Physics/RigidBody/physRigidBodyFromShape.h b/src/KingSystem/Physics/RigidBody/physRigidBodyFromShape.h index d0693895..0eb01083 100644 --- a/src/KingSystem/Physics/RigidBody/physRigidBodyFromShape.h +++ b/src/KingSystem/Physics/RigidBody/physRigidBodyFromShape.h @@ -4,6 +4,7 @@ namespace ksys::phys { +class MaterialMask; class Shape; class RigidBodyFromShape : public RigidBody { @@ -13,6 +14,8 @@ public: const sead::SafeString& name, bool set_flag_10, sead::Heap* heap); ~RigidBodyFromShape() override; + const MaterialMask* getMaterialMask() const; + protected: const hkpShape* getNewHavokShape_() override; float updateScale_(float scale, float old_scale) override;