diff options
| author | Léo Lam <leo@leolam.fr> | 2022-02-01 17:08:03 +0100 |
|---|---|---|
| committer | Léo Lam <leo@leolam.fr> | 2022-02-01 17:08:03 +0100 |
| commit | d277eac80e1bc2fb9874120ee63b1a55956db2d9 (patch) | |
| tree | ea6e9c660d2617b756ee208574c0bb855cc6ddd8 /src | |
| parent | 2cd2d9dc69ca2da025b8a5a350f57fe343998650 (diff) | |
ksys/phys: Move BoxShapeParam::createShape to BoxShape::make
The same BoxShapeParam class is used for two different shape classes
(BoxShape and BoxWaterShape) so it's more natural to move the factory
function to the shape class itself
Diffstat (limited to 'src')
3 files changed, 12 insertions, 12 deletions
diff --git a/src/KingSystem/Physics/RigidBody/Shape/physBoxShape.cpp b/src/KingSystem/Physics/RigidBody/Shape/physBoxShape.cpp index b123276e..7e0e9444 100644 --- a/src/KingSystem/Physics/RigidBody/Shape/physBoxShape.cpp +++ b/src/KingSystem/Physics/RigidBody/Shape/physBoxShape.cpp @@ -7,21 +7,21 @@ namespace ksys::phys { -BoxShape* BoxShapeParam::createShape(sead::Heap* heap) const { +BoxShape* BoxShape::make(const BoxShapeParam& param, sead::Heap* heap) { hkpBoxShape* box = nullptr; if (auto* storage = util::allocStorage<hkpBoxShape>(heap)) { - const auto radius = convex_radius; - const hkVector4f half_extents{sead::Mathf::max(extents.x / 2 - radius, 0.001), - sead::Mathf::max(extents.y / 2 - radius, 0.001), - sead::Mathf::max(extents.z / 2 - radius, 0.001)}; + const auto radius = param.convex_radius; + const hkVector4f half_extents{sead::Mathf::max(param.extents.x / 2 - radius, 0.001), + sead::Mathf::max(param.extents.y / 2 - radius, 0.001), + sead::Mathf::max(param.extents.z / 2 - radius, 0.001)}; box = new (storage) hkpBoxShape(half_extents, radius); } hkpConvexTransformShape* transform_shape = nullptr; if (auto* storage = util::allocStorage<hkpConvexTransformShape>(heap)) { sead::Quatf rotation; - rotation.setRPY(rotate.x, rotate.y, rotate.z); - hkQsTransformf transform{toHkVec4(translate), toHkQuat(rotation)}; + rotation.setRPY(param.rotate.x, param.rotate.y, param.rotate.z); + hkQsTransformf transform{toHkVec4(param.translate), toHkQuat(rotation)}; transform_shape = new (storage) hkpConvexTransformShape(box, transform); } @@ -33,7 +33,7 @@ BoxShape* BoxShapeParam::createShape(sead::Heap* heap) const { return nullptr; } - return new (heap) BoxShape(*this, box, transform_shape); + return new (heap) BoxShape(param, box, transform_shape); } BoxShape* BoxShape::clone(sead::Heap* heap) const { @@ -41,7 +41,7 @@ BoxShape* BoxShape::clone(sead::Heap* heap) const { param.extents = mExtents; param.translate = mTranslate; param.rotate = mRotate; - auto* cloned = param.createShape(heap); + auto* cloned = make(param, heap); cloned->setMaterialMask(mMaterialMask); return cloned; } diff --git a/src/KingSystem/Physics/RigidBody/Shape/physBoxShape.h b/src/KingSystem/Physics/RigidBody/Shape/physBoxShape.h index 81bece30..561454ee 100644 --- a/src/KingSystem/Physics/RigidBody/Shape/physBoxShape.h +++ b/src/KingSystem/Physics/RigidBody/Shape/physBoxShape.h @@ -30,6 +30,8 @@ public: DirtyTransform = 1 << 2, }; + static BoxShape* make(const BoxShapeParam& param, sead::Heap* heap); + BoxShape(const BoxShapeParam& param, hkpBoxShape* shape, hkpConvexTransformShape* transform_shape); ~BoxShape() override; @@ -62,8 +64,6 @@ public: }; struct BoxShapeParam { - BoxShape* createShape(sead::Heap* heap) const; - sead::Vector3f extents; sead::Vector3f translate; sead::Vector3f rotate; diff --git a/src/KingSystem/Physics/RigidBody/physRigidBodyFactory.cpp b/src/KingSystem/Physics/RigidBody/physRigidBodyFactory.cpp index 7fbdcc32..03825ea8 100644 --- a/src/KingSystem/Physics/RigidBody/physRigidBodyFactory.cpp +++ b/src/KingSystem/Physics/RigidBody/physRigidBodyFactory.cpp @@ -49,7 +49,7 @@ BoxRigidBody* RigidBodyFactory::createBox(RigidBodyInstanceParam* params, sead:: params->motion_type = MotionType::Keyframed; auto* v = sead::DynamicCast<BoxParam>(params); - auto* shape = v->shape.createShape(heap); + auto* shape = BoxShape::make(v->shape, heap); return shape->createBody(true, *params, heap); } |
