diff options
Diffstat (limited to 'src/sim/entity/mod.rs')
| -rw-r--r-- | src/sim/entity/mod.rs | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/sim/entity/mod.rs b/src/sim/entity/mod.rs index 555d2c6..0f4ae3c 100644 --- a/src/sim/entity/mod.rs +++ b/src/sim/entity/mod.rs @@ -5,7 +5,7 @@ use rapier2d::{ }; use crate::{ - config::CELLS_TO_METRES, + config::{CELLS_TO_METRES, MASS_SCALING}, sim::{ cell::{cell::Cell, materials::MaterialId}, lib::marching_squares::Marchable, @@ -48,16 +48,16 @@ impl Marchable for EntityCells { pub trait EntityBehaviour { fn update( &mut self, - update_ctx: &mut EntityUpdateCtx, - ctx: &mut SimCtx, - delta_time: f32, + _update_ctx: &mut EntityUpdateCtx, + _ctx: &mut SimCtx, + _delta_time: f32, ) -> () { } fn physics_update( &mut self, - update_ctx: &mut EntityUpdateCtx, - ctx: &mut SimCtx, - delta_time: f32, + _update_ctx: &mut EntityUpdateCtx, + _ctx: &mut SimCtx, + _delta_time: f32, ) -> () { } } @@ -79,7 +79,15 @@ impl EntityDef { .translation(position / CELLS_TO_METRES) .build(); - let collider = RbManager::convex_hull_collider_from_marchable(&cells, None).build(); + let mass = cells + .cells + .iter() + .fold(0, |acc, cur| acc + cur.material.def().density) as f32 + * MASS_SCALING; + + let collider = RbManager::convex_hull_collider_from_marchable(&cells, None) + .mass(mass) + .build(); EntityDef { rb: Some(rb), |
