pub struct WaterSurface {
pub width: usize,
pub depth: usize,
pub cell_size: f32,
pub height: Vec<f32>,
pub vel_x: Vec<f32>,
pub vel_z: Vec<f32>,
pub rest_height: f32,
pub wave_speed: f32,
pub damping: f32,
pub gravity: f32,
/* private fields */
}Expand description
Height-field water simulation using the shallow water equations.
Implements:
- 2D height field h(x,z) and velocity field (vx, vz)
- Wave propagation via semi-discrete shallow water equations
- Damping for energy dissipation
- Rain drops creating Gaussian ripples
Fields§
§width: usizeGrid width.
depth: usizeGrid depth.
cell_size: f32Cell size in world units.
height: Vec<f32>Height field (water depth above flat bottom).
vel_x: Vec<f32>X-velocity field.
vel_z: Vec<f32>Z-velocity field.
rest_height: f32Rest height (equilibrium water depth).
wave_speed: f32Wave speed factor.
damping: f32Damping coefficient (0 = no damping, 1 = full damping per step).
gravity: f32Gravity acceleration.
Implementations§
Source§impl WaterSurface
impl WaterSurface
pub fn new(width: usize, depth: usize, cell_size: f32, rest_height: f32) -> Self
Sourcepub fn rain_drop(
&mut self,
world_x: f32,
world_z: f32,
amplitude: f32,
radius: f32,
)
pub fn rain_drop( &mut self, world_x: f32, world_z: f32, amplitude: f32, radius: f32, )
Simulate a rain drop at (world_x, world_z) with given height perturbation.
Sourcepub fn add_wave_source(
&mut self,
z_start: usize,
z_end: usize,
amplitude: f32,
frequency: f32,
)
pub fn add_wave_source( &mut self, z_start: usize, z_end: usize, amplitude: f32, frequency: f32, )
Add a sinusoidal wave source at the left boundary.
Sourcepub fn step(&mut self, dt: f32)
pub fn step(&mut self, dt: f32)
Advance the water simulation by dt seconds using explicit finite difference.
Sourcepub fn sample_height(&self, world_x: f32, world_z: f32) -> f32
pub fn sample_height(&self, world_x: f32, world_z: f32) -> f32
Sample water height at a world-space (x, z) position via bilinear interpolation.
Sourcepub fn surface_normal(&self, world_x: f32, world_z: f32) -> Vec3
pub fn surface_normal(&self, world_x: f32, world_z: f32) -> Vec3
Compute the surface normal at a world-space (x, z) position.
Sourcepub fn to_positions(&self, y_offset: f32) -> Vec<Vec3>
pub fn to_positions(&self, y_offset: f32) -> Vec<Vec3>
Extract height field as a flat array of world-space Vec3 positions.
Sourcepub fn max_amplitude(&self) -> f32
pub fn max_amplitude(&self) -> f32
Max height deviation from rest height (wave amplitude proxy).
Sourcepub fn total_volume(&self) -> f32
pub fn total_volume(&self) -> f32
Total fluid volume.
Auto Trait Implementations§
impl Freeze for WaterSurface
impl RefUnwindSafe for WaterSurface
impl Send for WaterSurface
impl Sync for WaterSurface
impl Unpin for WaterSurface
impl UnsafeUnpin for WaterSurface
impl UnwindSafe for WaterSurface
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.