mirror of
https://github.com/zeldaret/botw
synced 2026-08-03 08:43:19 -04:00
ksys/phys: Finish BoxRigidBody
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "KingSystem/Physics/RigidBody/Shape/physBoxRigidBody.h"
|
||||
#include <Havok/Physics2012/Dynamics/Entity/hkpRigidBody.h>
|
||||
#include "KingSystem/Physics/RigidBody/Shape/physBoxShape.h"
|
||||
#include "KingSystem/Physics/RigidBody/physRigidBodyFactory.h"
|
||||
|
||||
@@ -19,6 +20,39 @@ BoxRigidBody::~BoxRigidBody() {
|
||||
}
|
||||
}
|
||||
|
||||
void BoxRigidBody::setExtents(const sead::Vector3f& extents) {
|
||||
if (mShape->setExtents(extents))
|
||||
updateShape();
|
||||
}
|
||||
|
||||
void BoxRigidBody::setTranslate(const sead::Vector3f& translate) {
|
||||
if (mShape->setTranslate(translate))
|
||||
updateShape();
|
||||
}
|
||||
|
||||
const sead::Vector3f& BoxRigidBody::getExtents() const {
|
||||
return mShape->mExtents;
|
||||
}
|
||||
|
||||
const sead::Vector3f& BoxRigidBody::getTranslate() const {
|
||||
return mShape->mTranslate;
|
||||
}
|
||||
|
||||
void BoxRigidBody::getTransformedTranslate(sead::Vector3f* translate) {
|
||||
lock();
|
||||
const auto& transform = getHkBody()->getMotion()->getMotionState()->getTransform();
|
||||
unlock();
|
||||
mShape->getTranslate(translate, transform);
|
||||
}
|
||||
|
||||
void BoxRigidBody::setMaterialMask(const MaterialMask& mask) {
|
||||
mShape->setMaterialMask(mask);
|
||||
}
|
||||
|
||||
const MaterialMask& BoxRigidBody::getMaterialMask() const {
|
||||
return mShape->mMaterialMask;
|
||||
}
|
||||
|
||||
float BoxRigidBody::getVolume() {
|
||||
return mShape->getVolume();
|
||||
}
|
||||
@@ -31,4 +65,11 @@ const Shape* BoxRigidBody::getShape_() const {
|
||||
return mShape;
|
||||
}
|
||||
|
||||
u32 BoxRigidBody::getCollisionMasks(RigidBody::CollisionMasks* masks) {
|
||||
masks->ignored_layers = ~mContactMask.getDirect();
|
||||
masks->collision_filter_info = getCollisionFilterInfo();
|
||||
masks->material_mask = getMaterialMask().getRawData();
|
||||
return 0;
|
||||
}
|
||||
|
||||
} // namespace ksys::phys
|
||||
|
||||
@@ -16,12 +16,24 @@ public:
|
||||
const sead::SafeString& name, bool set_flag_10, sead::Heap* heap);
|
||||
~BoxRigidBody() override;
|
||||
|
||||
/// Set the box extents and trigger a shape update.
|
||||
void setExtents(const sead::Vector3f& extents);
|
||||
/// Set the box translation and trigger a shape update.
|
||||
void setTranslate(const sead::Vector3f& translate);
|
||||
|
||||
const sead::Vector3f& getExtents() const;
|
||||
const sead::Vector3f& getTranslate() const;
|
||||
void getTransformedTranslate(sead::Vector3f* translate);
|
||||
|
||||
void setMaterialMask(const MaterialMask& mask);
|
||||
const MaterialMask& getMaterialMask() const;
|
||||
|
||||
float getVolume() override;
|
||||
|
||||
protected:
|
||||
Shape* getShape_() override;
|
||||
const Shape* getShape_() const override;
|
||||
void m9() override;
|
||||
u32 getCollisionMasks(CollisionMasks* masks) override;
|
||||
|
||||
BoxShape* mShape;
|
||||
};
|
||||
|
||||
@@ -9,7 +9,7 @@ class TeraMeshRigidBody : public RigidBody {
|
||||
public:
|
||||
TeraMeshRigidBody(hkpRigidBody* hk_body, sead::Heap* heap);
|
||||
|
||||
void m9() override;
|
||||
u32 getCollisionMasks(CollisionMasks* masks) override;
|
||||
};
|
||||
|
||||
} // namespace ksys::phys
|
||||
|
||||
@@ -40,6 +40,16 @@ public:
|
||||
class RigidBody : public sead::IDisposer, public RigidBase {
|
||||
SEAD_RTTI_BASE(RigidBody)
|
||||
public:
|
||||
struct CollisionMasks {
|
||||
/// See MaterialMaskData.
|
||||
u32 material_mask;
|
||||
/// EntityCollisionFilterInfo or ReceiverMask.
|
||||
u32 collision_filter_info;
|
||||
/// Contact layers we do not collide with.
|
||||
/// One bit per ContactLayer -- layers are relative to the layer base value.
|
||||
u32 ignored_layers;
|
||||
};
|
||||
|
||||
enum class Type {
|
||||
FromShape = 0,
|
||||
_1 = 1,
|
||||
@@ -509,7 +519,8 @@ public:
|
||||
bool isEntityMotionFlag200On() const;
|
||||
|
||||
protected:
|
||||
virtual void m9() = 0;
|
||||
// FIXME: return type
|
||||
virtual u32 getCollisionMasks(CollisionMasks* masks) = 0;
|
||||
|
||||
/// Called whenever a shape update is requested.
|
||||
/// @return the new shape to use for the Havok rigid body or null to keep the current hkpShape
|
||||
|
||||
@@ -14,7 +14,7 @@ public:
|
||||
const sead::SafeString& name, bool set_flag_10, sead::Heap* heap);
|
||||
~RigidBodyFromShape() override;
|
||||
|
||||
const MaterialMask* getMaterialMask() const;
|
||||
const MaterialMask* tryGetMaterialMask() const;
|
||||
|
||||
protected:
|
||||
const hkpShape* getNewHavokShape_() override;
|
||||
|
||||
Reference in New Issue
Block a user