feat(physics): added wedge part

This commit is contained in:
maelstrom 2025-07-13 22:37:01 +02:00
parent 2538673fb2
commit 31aa28909e
3 changed files with 45 additions and 0 deletions

View file

@ -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<std::string, const InstanceType*> INSTANCE_MAP = {
{ "BasePart", &BasePart::TYPE },
{ "Part", &Part::TYPE },
{ "WedgePart", &WedgePart::TYPE },
{ "Snap", &Snap::TYPE },
{ "Weld", &Weld::TYPE },
{ "Rotate", &Rotate::TYPE },

View file

@ -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<rp::BoxShape*>(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());
}

View file

@ -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<WedgePart> New() { return std::make_shared<WedgePart>(); };
static inline std::shared_ptr<WedgePart> New(PartConstructParams params) { return std::make_shared<WedgePart>(params); };
static inline std::shared_ptr<Instance> Create() { return std::make_shared<WedgePart>(); };
};