Take into account parameters of destructibles (threshold/mass)
This commit is contained in:
parent
55efcceaf0
commit
02e779fc70
@ -73,6 +73,7 @@ game::MapObjectCollision::MapObjectCollision(collision::DynamicsWorld& world,
|
||||
if (destructible)
|
||||
{
|
||||
oflags |= collision::OF_DESTRUCTIBLE;
|
||||
model_->GetParamFloat("destr_th", destr_th_);
|
||||
}
|
||||
|
||||
// prefer simple cshape which allow destruction
|
||||
@ -105,6 +106,7 @@ void game::MapObjectCollision::Break()
|
||||
|
||||
btCollisionShape* shape = body_->getCollisionShape();
|
||||
float mass = 10.0f;
|
||||
model_->GetParamFloat("destr_mass", mass); // dont care if not present
|
||||
btVector3 local_inertia(0, 0, 0);
|
||||
shape->calculateLocalInertia(mass, local_inertia);
|
||||
|
||||
|
||||
@ -29,6 +29,7 @@ public:
|
||||
const std::shared_ptr<const assets::Model>& GetModel() const { return model_; }
|
||||
btRigidBody& GetBtBody() { return *body_; }
|
||||
net::ObjNum GetNum() const { return num_; }
|
||||
float GetDestroyThreshold() const { return destr_th_; }
|
||||
|
||||
virtual ~MapObjectCollision() override;
|
||||
|
||||
@ -37,6 +38,7 @@ private:
|
||||
std::shared_ptr<const assets::Model> model_;
|
||||
net::ObjNum num_;
|
||||
std::unique_ptr<btRigidBody> body_;
|
||||
float destr_th_ = 10.0f;
|
||||
};
|
||||
|
||||
class MapInstance
|
||||
|
||||
@ -101,6 +101,7 @@ void game::World::HandleContacts()
|
||||
auto& bt_world = GetBtWorld();
|
||||
int numManifolds = bt_world.getDispatcher()->getNumManifolds();
|
||||
|
||||
// destructibles
|
||||
static std::vector<net::ObjNum> to_destroy;
|
||||
to_destroy.clear();
|
||||
|
||||
@ -120,10 +121,8 @@ void game::World::HandleContacts()
|
||||
auto col = dynamic_cast<MapObjectCollision*>(cb);
|
||||
if (!col)
|
||||
return;
|
||||
|
||||
const float break_threshold = 100.0f; // TODO: per-object threshold
|
||||
|
||||
if (pt.getAppliedImpulse() > break_threshold)
|
||||
|
||||
if (pt.getAppliedImpulse() > col->GetDestroyThreshold())
|
||||
{
|
||||
to_destroy.push_back(col->GetNum());
|
||||
other_body->applyCentralImpulse(pt.m_normalWorldOnB * pt.getAppliedImpulse() * 0.5f);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user