From cc3d3ad03d0de298c47f4bcd4987a788cf736c01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Thu, 10 Feb 2022 20:16:27 +0100 Subject: [PATCH] ksys/phys: Implement PolytopeRigidBody --- data/uking_functions.csv | 39 +++++------ .../Shape/Polytope/physPolytopeRigidBody.cpp | 65 +++++++++++++++++++ .../Shape/Polytope/physPolytopeRigidBody.h | 26 +++++++- 3 files changed, 110 insertions(+), 20 deletions(-) diff --git a/data/uking_functions.csv b/data/uking_functions.csv index ddbc434b..34ee9c0b 100644 --- a/data/uking_functions.csv +++ b/data/uking_functions.csv @@ -83278,7 +83278,7 @@ Address,Quality,Size,Name 0x0000007100f993b4,O,000188,_ZN4ksys4phys16RigidBodyFactory19createCylinderWaterEPNS0_22RigidBodyInstanceParamEPN4sead4HeapE 0x0000007100f99470,O,000188,_ZN4ksys4phys16RigidBodyFactory9createBoxEPNS0_22RigidBodyInstanceParamEPN4sead4HeapE 0x0000007100f9952c,O,000188,_ZN4ksys4phys16RigidBodyFactory14createBoxWaterEPNS0_22RigidBodyInstanceParamEPN4sead4HeapE -0x0000007100f995e8,U,000188, +0x0000007100f995e8,O,000188,_ZN4ksys4phys16RigidBodyFactory14createPolytopeEPNS0_22RigidBodyInstanceParamEPN4sead4HeapE 0x0000007100f996a4,U,000188, 0x0000007100f99760,U,000264, 0x0000007100f99868,U,000036, @@ -83341,24 +83341,24 @@ Address,Quality,Size,Name 0x0000007100fa11b0,O,000008,_ZNK4ksys4phys14RigidBodyParam13getMotionTypeEv 0x0000007100fa11b8,O,001324,_ZN4ksys4phys14RigidBodyParam4Info9postRead_Ev 0x0000007100fa16e4,O,000004,_ZN4ksys4phys14RigidBodyParam4InfoD0Ev -0x0000007100fa16e8,U,000004, -0x0000007100fa16ec,U,000084, -0x0000007100fa1740,U,000088, -0x0000007100fa1798,U,000088, -0x0000007100fa17f0,U,000096, -0x0000007100fa1850,U,000096, -0x0000007100fa18b0,U,000008, -0x0000007100fa18b8,U,000012, -0x0000007100fa18c4,U,000032, -0x0000007100fa18e4,U,000008, -0x0000007100fa18ec,U,000012, -0x0000007100fa18f8,U,000016, -0x0000007100fa1908,U,000008, -0x0000007100fa1910,U,000008, -0x0000007100fa1918,U,000068, -0x0000007100fa195c,U,000008, -0x0000007100fa1964,U,000288, -0x0000007100fa1a84,U,000092, +0x0000007100fa16e8,O,000004,_ZN4ksys4phys17PolytopeRigidBody4makeEPNS0_22RigidBodyInstanceParamEPN4sead4HeapE +0x0000007100fa16ec,O,000084,_ZN4ksys4phys17PolytopeRigidBodyC1EP12hkpRigidBodyPNS0_13PolytopeShapeENS0_16ContactLayerTypeERKN4sead14SafeStringBaseIcEEbPNS7_4HeapE +0x0000007100fa1740,O,000088,_ZN4ksys4phys17PolytopeRigidBodyD1Ev +0x0000007100fa1798,O,000088,_ZThn32_N4ksys4phys17PolytopeRigidBodyD1Ev +0x0000007100fa17f0,O,000096,_ZN4ksys4phys17PolytopeRigidBodyD0Ev +0x0000007100fa1850,O,000096,_ZThn32_N4ksys4phys17PolytopeRigidBodyD0Ev +0x0000007100fa18b0,O,000008,_ZN4ksys4phys17PolytopeRigidBody9setVertexEiRKN4sead7Vector3IfEE +0x0000007100fa18b8,O,000012,_ZNK4ksys4phys17PolytopeRigidBody14getNumVerticesEv +0x0000007100fa18c4,O,000032,_ZNK4ksys4phys17PolytopeRigidBody9getVertexEi +0x0000007100fa18e4,O,000008,_ZN4ksys4phys17PolytopeRigidBody15setMaterialMaskERKNS0_12MaterialMaskE +0x0000007100fa18ec,O,000012,_ZNK4ksys4phys17PolytopeRigidBody15getMaterialMaskEv +0x0000007100fa18f8,O,000016,_ZN4ksys4phys17PolytopeRigidBody9getVolumeEv +0x0000007100fa1908,O,000008,_ZN4ksys4phys17PolytopeRigidBody9getShape_Ev +0x0000007100fa1910,O,000008,_ZNK4ksys4phys17PolytopeRigidBody9getShape_Ev +0x0000007100fa1918,O,000068,_ZN4ksys4phys17PolytopeRigidBody17getCollisionMasksEPNS0_9RigidBody14CollisionMasksEPKj +0x0000007100fa195c,O,000008,_ZN4ksys4phys17PolytopeRigidBody9setVolumeEf +0x0000007100fa1964,O,000288,_ZNK4ksys4phys17PolytopeRigidBody27checkDerivedRuntimeTypeInfoEPKN4sead15RuntimeTypeInfo9InterfaceE +0x0000007100fa1a84,O,000092,_ZNK4ksys4phys17PolytopeRigidBody18getRuntimeTypeInfoEv 0x0000007100fa1ae0,O,000188,_ZN4ksys4phys21RigidBodyMotionEntityC1EPNS0_9RigidBodyE 0x0000007100fa1b9c,O,000072,_ZN4ksys4phys21RigidBodyMotionEntityD1Ev 0x0000007100fa1be4,O,000080,_ZN4ksys4phys21RigidBodyMotionEntityD0Ev @@ -83669,6 +83669,7 @@ Address,Quality,Size,Name 0x0000007100faefbc,O,000520,_ZN4ksys4phys13PolytopeShape4initERKNS0_18PolytopeShapeParamEPN4sead4HeapE 0x0000007100faf1c4,O,000480,_ZNK4ksys4phys13PolytopeShape5cloneEPN4sead4HeapE 0x0000007100faf3a4,O,000228,_ZN4ksys4phys13PolytopeShape9setVertexEiRKN4sead7Vector3IfEE +0x0000007100faf488,O,000048,_ZN4ksys4phys13PolytopeShape15setMaterialMaskERKNS0_12MaterialMaskE 0x0000007100faf4b8,O,000232,_ZN4ksys4phys13PolytopeShapeD1Ev 0x0000007100faf5a0,O,000036,_ZN4ksys4phys13PolytopeShapeD0Ev 0x0000007100faf5c4,O,000028,_ZN4ksys4phys13PolytopeShape13getHavokShapeEv diff --git a/src/KingSystem/Physics/RigidBody/Shape/Polytope/physPolytopeRigidBody.cpp b/src/KingSystem/Physics/RigidBody/Shape/Polytope/physPolytopeRigidBody.cpp index 256ab6f6..b0b608c9 100644 --- a/src/KingSystem/Physics/RigidBody/Shape/Polytope/physPolytopeRigidBody.cpp +++ b/src/KingSystem/Physics/RigidBody/Shape/Polytope/physPolytopeRigidBody.cpp @@ -1 +1,66 @@ #include "KingSystem/Physics/RigidBody/Shape/Polytope/physPolytopeRigidBody.h" +#include "KingSystem/Physics/RigidBody/Shape/Polytope/physPolytopeShape.h" +#include "KingSystem/Physics/RigidBody/physRigidBodyFactory.h" +#include "KingSystem/Utils/SafeDelete.h" + +namespace ksys::phys { + +PolytopeRigidBody* PolytopeRigidBody::make(RigidBodyInstanceParam* param, sead::Heap* heap) { + return RigidBodyFactory::createPolytope(param, heap); +} + +PolytopeRigidBody::PolytopeRigidBody(hkpRigidBody* hk_body, PolytopeShape* shape, + ContactLayerType layer_type, const sead::SafeString& name, + bool set_flag_10, sead::Heap* heap) + : RigidBodyFromShape(hk_body, layer_type, name, set_flag_10, heap), mShape(shape) {} + +PolytopeRigidBody::~PolytopeRigidBody() { + if (hasFlag(RigidBody::Flag::_10) && mShape) { + util::safeDelete(mShape); + } +} + +bool PolytopeRigidBody::setVertex(int vertex_idx, const sead::Vector3f& vertex) { + return mShape->setVertex(vertex_idx, vertex); +} + +u16 PolytopeRigidBody::getNumVertices() const { + return mShape->getNumVertices(); +} + +const sead::Vector3f& PolytopeRigidBody::getVertex(int vertex_idx) const { + return mShape->getVertex(vertex_idx); +} + +void PolytopeRigidBody::setMaterialMask(const MaterialMask& mask) { + mShape->setMaterialMask(mask); +} + +const MaterialMask& PolytopeRigidBody::getMaterialMask() const { + return mShape->getMaterialMask(); +} + +float PolytopeRigidBody::getVolume() { + return mShape->getVolume(); +} + +void PolytopeRigidBody::setVolume(float volume) { + mShape->setVolume(volume); +} + +Shape* PolytopeRigidBody::getShape_() { + return mShape; +} + +const Shape* PolytopeRigidBody::getShape_() const { + return mShape; +} + +u32 PolytopeRigidBody::getCollisionMasks(RigidBody::CollisionMasks* masks, const u32* unk) { + masks->ignored_layers = ~mContactMask.getDirect(); + masks->collision_filter_info = getCollisionFilterInfo(); + masks->material_mask = getMaterialMask().getRawData(); + return 0; +} + +} // namespace ksys::phys diff --git a/src/KingSystem/Physics/RigidBody/Shape/Polytope/physPolytopeRigidBody.h b/src/KingSystem/Physics/RigidBody/Shape/Polytope/physPolytopeRigidBody.h index d830d793..b5b462f8 100644 --- a/src/KingSystem/Physics/RigidBody/Shape/Polytope/physPolytopeRigidBody.h +++ b/src/KingSystem/Physics/RigidBody/Shape/Polytope/physPolytopeRigidBody.h @@ -4,10 +4,34 @@ namespace ksys::phys { +class PolytopeShape; + class PolytopeRigidBody : public RigidBodyFromShape { SEAD_RTTI_OVERRIDE(PolytopeRigidBody, RigidBodyFromShape) public: - // TODO + static PolytopeRigidBody* make(RigidBodyInstanceParam* param, sead::Heap* heap); + + PolytopeRigidBody(hkpRigidBody* hk_body, PolytopeShape* shape, ContactLayerType layer_type, + const sead::SafeString& name, bool set_flag_10, sead::Heap* heap); + ~PolytopeRigidBody() override; + + bool setVertex(int vertex_idx, const sead::Vector3f& vertex); + u16 getNumVertices() const; + const sead::Vector3f& getVertex(int vertex_idx) const; + + void setMaterialMask(const MaterialMask& mask); + const MaterialMask& getMaterialMask() const; + + float getVolume() override; + void setVolume(float volume); + +protected: + Shape* getShape_() override; + const Shape* getShape_() const override; + u32 getCollisionMasks(RigidBody::CollisionMasks* masks, const u32* unk) override; + +private: + PolytopeShape* mShape{}; }; } // namespace ksys::phys