mirror of
https://github.com/zeldaret/botw
synced 2026-06-26 17:52:07 -04:00
ksys/phys: Implement most of RigidBodyFromShape
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "KingSystem/Physics/RigidBody/physRigidBodyFromShape.h"
|
||||
#include <Havok/Physics2012/Dynamics/Entity/hkpRigidBody.h>
|
||||
#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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user