diff --git a/src/integrations/rapier/fluids_pipeline.rs b/src/integrations/rapier/fluids_pipeline.rs index 0881c86..c2ce377 100644 --- a/src/integrations/rapier/fluids_pipeline.rs +++ b/src/integrations/rapier/fluids_pipeline.rs @@ -126,7 +126,7 @@ impl ColliderCouplingSet { &'a mut self, colliders: &'a ColliderSet, bodies: &'a mut RigidBodySet, - ) -> ColliderCouplingManager { + ) -> ColliderCouplingManager<'a> { ColliderCouplingManager { coupling: self, colliders, @@ -217,32 +217,35 @@ impl<'a> CouplingManager for ColliderCouplingManager<'a> { let dpt = particle_pos - proj.point; - if let Some((normal, depth)) = + let Some((normal, depth)) = Unit::try_new_and_get(dpt, f32::default_epsilon()) - { - if proj.is_inside { - fluid.positions[*particle_id] -= - *normal * (depth + margin); + else { + continue; + }; + if proj.is_inside { + fluid.positions[*particle_id] -= + *normal * (depth + margin); - let vel_err = - normal.dot(&fluid.velocities[*particle_id]); + let vel_err = + normal.dot(&fluid.velocities[*particle_id]); - if vel_err > na::zero::() { - fluid.velocities[*particle_id] -= - *normal * vel_err; - } - } else if depth > h + prediction { - continue; + if vel_err > na::zero::() { + fluid.velocities[*particle_id] -= *normal * vel_err; } + } else if depth > h + prediction { + continue; } + let normal = if proj.is_inside { -normal } else { normal }; + let pos = proj.point - *normal * particle_radius; + let velocity = body.map(|b| b.velocity_at_point(&proj.point)); boundary .velocities .push(velocity.unwrap_or(Vector::zeros())); - boundary.positions.push(proj.point); + boundary.positions.push(pos); boundary.volumes.push(na::zero::()); coupling.features.push(feature); }