diff options
Diffstat (limited to 'src/sim/rb_sim/mod.rs')
| -rw-r--r-- | src/sim/rb_sim/mod.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/sim/rb_sim/mod.rs b/src/sim/rb_sim/mod.rs index 48e4282..0192555 100644 --- a/src/sim/rb_sim/mod.rs +++ b/src/sim/rb_sim/mod.rs @@ -2,6 +2,7 @@ pub mod debug_render; pub mod rb_entity; use fxhash::FxHashMap; +use glam::Vec2; use rapier2d::{ dynamics::{self}, geometry, @@ -13,6 +14,8 @@ use crate::{ config::{CELLS_IN_CHUNK, CHUNK_SIZE, PHYSICS_DELTA_TIME, PIXELS_TO_METRES}, sim::{ cell::{cell::Cell, materials::MaterialId}, + cell_sim::chunk::Chunk, + lib::marching_squares::marching_squares_vertex_trace, rb_sim::{ debug_render::{DebugLineBuffer, DebugVertex}, rb_entity::RbEntity, @@ -161,6 +164,28 @@ impl RbSimManager { } } + fn collider_from_chunk(&self, position: Vec2, chunk: &Chunk) -> geometry::Collider { + let mut paths = marching_squares_vertex_trace(chunk, CHUNK_SIZE, CHUNK_SIZE); + let mut path: Vec<Vec2> = paths + // NAIVE, using the second and assuming it's the outer path + .swap_remove(0) + .iter() + .map(|v| v / PIXELS_TO_METRES) + .collect(); + // close the loop + let first = (*path.first().unwrap()).clone(); + path.push(first); + + geometry::ColliderBuilder::polyline(path, None) + .translation(position / PIXELS_TO_METRES) + .build() + } + + pub fn test_add_collider_from_chunk(&mut self, position: Vec2, chunk: &Chunk) { + let collider = self.collider_from_chunk(position, chunk); + self.physics_manager.collider_set.insert(collider); + } + pub fn test(&mut self) { /* Create the ground. */ let collider = |
