Take into account parameters of destructibles (threshold/mass)

This commit is contained in:
tovjemam 2026-03-01 12:28:49 +01:00
parent 55efcceaf0
commit 02e779fc70
3 changed files with 7 additions and 4 deletions

View File

@ -73,6 +73,7 @@ game::MapObjectCollision::MapObjectCollision(collision::DynamicsWorld& world,
if (destructible) if (destructible)
{ {
oflags |= collision::OF_DESTRUCTIBLE; oflags |= collision::OF_DESTRUCTIBLE;
model_->GetParamFloat("destr_th", destr_th_);
} }
// prefer simple cshape which allow destruction // prefer simple cshape which allow destruction
@ -105,6 +106,7 @@ void game::MapObjectCollision::Break()
btCollisionShape* shape = body_->getCollisionShape(); btCollisionShape* shape = body_->getCollisionShape();
float mass = 10.0f; float mass = 10.0f;
model_->GetParamFloat("destr_mass", mass); // dont care if not present
btVector3 local_inertia(0, 0, 0); btVector3 local_inertia(0, 0, 0);
shape->calculateLocalInertia(mass, local_inertia); shape->calculateLocalInertia(mass, local_inertia);

View File

@ -29,6 +29,7 @@ public:
const std::shared_ptr<const assets::Model>& GetModel() const { return model_; } const std::shared_ptr<const assets::Model>& GetModel() const { return model_; }
btRigidBody& GetBtBody() { return *body_; } btRigidBody& GetBtBody() { return *body_; }
net::ObjNum GetNum() const { return num_; } net::ObjNum GetNum() const { return num_; }
float GetDestroyThreshold() const { return destr_th_; }
virtual ~MapObjectCollision() override; virtual ~MapObjectCollision() override;
@ -37,6 +38,7 @@ private:
std::shared_ptr<const assets::Model> model_; std::shared_ptr<const assets::Model> model_;
net::ObjNum num_; net::ObjNum num_;
std::unique_ptr<btRigidBody> body_; std::unique_ptr<btRigidBody> body_;
float destr_th_ = 10.0f;
}; };
class MapInstance class MapInstance

View File

@ -101,6 +101,7 @@ void game::World::HandleContacts()
auto& bt_world = GetBtWorld(); auto& bt_world = GetBtWorld();
int numManifolds = bt_world.getDispatcher()->getNumManifolds(); int numManifolds = bt_world.getDispatcher()->getNumManifolds();
// destructibles
static std::vector<net::ObjNum> to_destroy; static std::vector<net::ObjNum> to_destroy;
to_destroy.clear(); to_destroy.clear();
@ -121,9 +122,7 @@ void game::World::HandleContacts()
if (!col) if (!col)
return; return;
const float break_threshold = 100.0f; // TODO: per-object threshold if (pt.getAppliedImpulse() > col->GetDestroyThreshold())
if (pt.getAppliedImpulse() > break_threshold)
{ {
to_destroy.push_back(col->GetNum()); to_destroy.push_back(col->GetNum());
other_body->applyCentralImpulse(pt.m_normalWorldOnB * pt.getAppliedImpulse() * 0.5f); other_body->applyCentralImpulse(pt.m_normalWorldOnB * pt.getAppliedImpulse() * 0.5f);