diff --git a/core/src/objects/meta.cpp b/core/src/objects/meta.cpp index 17e993d..55443d3 100644 --- a/core/src/objects/meta.cpp +++ b/core/src/objects/meta.cpp @@ -6,6 +6,7 @@ #include "objects/joint/rotatev.h" #include "objects/joint/weld.h" #include "objects/message.h" +#include "objects/part/wedgepart.h" #include "objects/service/jointsservice.h" #include "objects/model.h" #include "objects/part/part.h" @@ -23,6 +24,7 @@ std::map INSTANCE_MAP = { { "BasePart", &BasePart::TYPE }, { "Part", &Part::TYPE }, + { "WedgePart", &WedgePart::TYPE }, { "Snap", &Snap::TYPE }, { "Weld", &Weld::TYPE }, { "Rotate", &Rotate::TYPE }, diff --git a/core/src/objects/part/wedgepart.cpp b/core/src/objects/part/wedgepart.cpp new file mode 100644 index 0000000..fdaee8c --- /dev/null +++ b/core/src/objects/part/wedgepart.cpp @@ -0,0 +1,24 @@ +#include "wedgepart.h" +#include "physics/util.h" + +WedgePart::WedgePart(): BasePart(&TYPE) { +} + +WedgePart::WedgePart(PartConstructParams params): BasePart(&TYPE, params) { + +} + +void WedgePart::updateCollider(rp::PhysicsCommon* common) { + rp::BoxShape* shape = common->createBoxShape(glmToRp(size * glm::vec3(0.5f))); + + // Recreate the rigidbody if the shape changes + if (rigidBody->getNbColliders() > 0 + && dynamic_cast(rigidBody->getCollider(0)->getCollisionShape())->getHalfExtents() != shape->getHalfExtents()) { + // TODO: This causes Touched to get called twice. Fix this. + rigidBody->removeCollider(rigidBody->getCollider(0)); + rigidBody->addCollider(shape, rp::Transform()); + } + + if (rigidBody->getNbColliders() == 0) + rigidBody->addCollider(shape, rp::Transform()); +} \ No newline at end of file diff --git a/core/src/objects/part/wedgepart.h b/core/src/objects/part/wedgepart.h new file mode 100644 index 0000000..a86824b --- /dev/null +++ b/core/src/objects/part/wedgepart.h @@ -0,0 +1,19 @@ +#pragma once + +#include "basepart.h" +#include "objects/annotation.h" + +class DEF_INST WedgePart : public BasePart { + AUTOGEN_PREAMBLE + +protected: + void updateCollider(rp::PhysicsCommon* common) override; + +public: + WedgePart(); + WedgePart(PartConstructParams params); + + static inline std::shared_ptr New() { return std::make_shared(); }; + static inline std::shared_ptr New(PartConstructParams params) { return std::make_shared(params); }; + static inline std::shared_ptr Create() { return std::make_shared(); }; +}; \ No newline at end of file