feat(physics): added wedge part
This commit is contained in:
parent
2538673fb2
commit
31aa28909e
3 changed files with 45 additions and 0 deletions
|
@ -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 },
|
||||
|
|
24
core/src/objects/part/wedgepart.cpp
Normal file
24
core/src/objects/part/wedgepart.cpp
Normal 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());
|
||||
}
|
19
core/src/objects/part/wedgepart.h
Normal file
19
core/src/objects/part/wedgepart.h
Normal 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>(); };
|
||||
};
|
Loading…
Add table
Reference in a new issue