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.