diff options
| -rw-r--r-- | src/content/entities/entity_bullet_emitter.rs | 2 | ||||
| -rw-r--r-- | src/sim/entity/mod.rs | 18 | ||||
| -rw-r--r-- | src/sim/lib/force.rs | 8 | ||||
| -rw-r--r-- | src/sim/rb_manager/debug_render.rs | 6 | ||||
| -rw-r--r-- | src/sim/rb_manager/mod.rs | 13 | ||||
| -rw-r--r-- | src/sim/sim_manager/utils.rs | 5 |
6 files changed, 20 insertions, 32 deletions
diff --git a/src/content/entities/entity_bullet_emitter.rs b/src/content/entities/entity_bullet_emitter.rs index 1a39440..cddb4b3 100644 --- a/src/content/entities/entity_bullet_emitter.rs +++ b/src/content/entities/entity_bullet_emitter.rs @@ -64,7 +64,7 @@ pub fn entity_bullet_emitter_def(position: Vec2, life: f32) -> EntityDef { }; let rb = RigidBodyBuilder::dynamic() - .translation(position / crate::config::CELLS_TO_METRES) + .translation(position) .gravity_scale(0.0) .build(); diff --git a/src/sim/entity/mod.rs b/src/sim/entity/mod.rs index a86a51f..af4f0dd 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, MASS_SCALING}, + config::MASS_SCALING, content::materials::MaterialId, sim::{ cell::Cell, lib::marching_squares::Marchable, rb_manager::RbManager, sim_manager::SimCtx, @@ -90,9 +90,7 @@ impl EntityDef { cells: EntityCells, behaviour: Option<Box<dyn EntityBehaviour>>, ) -> Self { - let rb = RigidBodyBuilder::dynamic() - .translation(position / CELLS_TO_METRES) - .build(); + let rb = RigidBodyBuilder::dynamic().translation(position).build(); let collider = RbManager::convex_hull_collider_from_marchable(&cells, Some(10)) .mass(mass_from_cells(&cells.cells)) @@ -146,12 +144,12 @@ impl<'a> EntityUpdateCtx<'a> { impl EntityData { pub fn _transform(&self, rb_manager: &RbManager) -> Option<(Vec2, (f32, f32))> { self.rb_h.and_then(|rb_h| { - rb_manager.physics_manager.world.bodies.get(rb_h).map(|rb| { - ( - rb.translation() * CELLS_TO_METRES, - (rb.rotation().cos(), rb.rotation().sin()), - ) - }) + rb_manager + .physics_manager + .world + .bodies + .get(rb_h) + .map(|rb| (rb.translation(), (rb.rotation().cos(), rb.rotation().sin()))) }) } pub fn transform(&self, ctx: &SimCtx) -> Option<(Vec2, (f32, f32))> { diff --git a/src/sim/lib/force.rs b/src/sim/lib/force.rs index e99817c..c110c29 100644 --- a/src/sim/lib/force.rs +++ b/src/sim/lib/force.rs @@ -3,7 +3,6 @@ use rand::random_range; use rapier2d::{dynamics::RigidBodyHandle, parry::bounding_volume::Aabb, pipeline::QueryFilter}; use crate::{ - config::CELLS_TO_METRES, content::materials::{MaterialForm, MaterialId, fire::FireCellView}, sim::{cell::Cell, lib::ray::AwDda, particle_manager::particle::Particle, sim_manager::SimCtx}, }; @@ -82,10 +81,7 @@ pub fn apply_explosion( .physics_manager .world .intersect_aabb_conservative( - Aabb::new( - (centre - radius as f32) / CELLS_TO_METRES, - (centre + radius as f32) / CELLS_TO_METRES, - ), + Aabb::new(centre - radius as f32, (centre + radius as f32)), QueryFilter::only_dynamic(), ); @@ -96,7 +92,7 @@ pub fn apply_explosion( && let Some(body) = ctx.rb_manager.physics_manager.world.bodies.get_mut(h) { // magic divisor number for good vibes - body.apply_impulse(get_vel(body.translation() * CELLS_TO_METRES) / 3.0, true); + body.apply_impulse(get_vel(body.translation()) / 3.0, true); } } } diff --git a/src/sim/rb_manager/debug_render.rs b/src/sim/rb_manager/debug_render.rs index 532d9a6..77eba7a 100644 --- a/src/sim/rb_manager/debug_render.rs +++ b/src/sim/rb_manager/debug_render.rs @@ -1,7 +1,5 @@ use rapier2d::pipeline::{DebugColor, DebugRenderBackend, DebugRenderObject}; -use crate::config::CELLS_TO_METRES; - #[repr(C)] #[derive(Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)] pub struct DebugVertex { @@ -24,11 +22,11 @@ impl DebugRenderBackend for DebugLineBuffer { ) { let color = hsla_to_linear_rgba(color); self.vertices.push(DebugVertex { - position: [a.x * CELLS_TO_METRES, a.y * CELLS_TO_METRES], + position: [a.x, a.y], color, }); self.vertices.push(DebugVertex { - position: [b.x * CELLS_TO_METRES, b.y * CELLS_TO_METRES], + position: [b.x, b.y], color, }); } diff --git a/src/sim/rb_manager/mod.rs b/src/sim/rb_manager/mod.rs index 1a2abbf..36893b5 100644 --- a/src/sim/rb_manager/mod.rs +++ b/src/sim/rb_manager/mod.rs @@ -29,7 +29,7 @@ pub struct PhysicsManager { impl PhysicsManager { pub fn new() -> Self { let mut world = PhysicsWorld::new(); - let gravity = vec2(0.0, 9.81); + let gravity = vec2(0.0, 9.81 * CELLS_TO_METRES); world.gravity = gravity; world.integration_parameters = IntegrationParameters { // 20 pixels <-> 1 meter @@ -95,9 +95,7 @@ impl RbManager { continue; } for i in 0..p { - vertices.push( - (poly[i as usize] - (marchable.size().as_vec2() - 1.0) / 2.0) / CELLS_TO_METRES, - ); + vertices.push(poly[i as usize] - (marchable.size().as_vec2() - 1.0) / 2.0); indices.push([v + i, v + (i + 1) % p]); } } @@ -129,12 +127,11 @@ impl RbManager { pub fn upsert_chunk_collider(&mut self, cx: i32, cy: i32, chunk: &Chunk) { puffin::profile_function!(); - let collider = RbManager::polyline_collider_from_marchable(chunk, Some(20)).translation( - vec2( + let collider = + RbManager::polyline_collider_from_marchable(chunk, Some(20)).translation(vec2( (cx as f32 + 0.5) * CHUNK_SIZE as f32, (cy as f32 + 0.5) * CHUNK_SIZE as f32, - ) / CELLS_TO_METRES, - ); + )); if let Some(handle) = self.chunk_colliders.remove(&(cx, cy)) { self.physics_manager.world.remove_collider(handle); diff --git a/src/sim/sim_manager/utils.rs b/src/sim/sim_manager/utils.rs index c8c28d6..c72981f 100644 --- a/src/sim/sim_manager/utils.rs +++ b/src/sim/sim_manager/utils.rs @@ -1,8 +1,7 @@ use glam::IVec2; -use rapier2d::{dynamics::RigidBodyBuilder, math::Pose}; +use rapier2d::dynamics::RigidBodyBuilder; use crate::{ - config::CELLS_TO_METRES, content::materials::MaterialId, sim::{ cell::Cell, @@ -162,7 +161,7 @@ pub fn read_back_entities_from_world( sim.destroy_entity(entity_id); // and create a new entity for each component for component in components { - let r = old_pose.transform_vector(component.position / CELLS_TO_METRES); + let r = old_pose.transform_vector(component.position); let mut pose = old_pose; pose.translation += r; |
