pub struct WaveSpectrum {
pub params: OceanParams,
pub waves: Vec<GerstnerWave>,
}Expand description
A generated spectrum plus the params that produced it.
Fields§
§params: OceanParams§waves: Vec<GerstnerWave>Implementations§
Source§impl WaveSpectrum
impl WaveSpectrum
Sourcepub fn generate(params: &OceanParams) -> Self
pub fn generate(params: &OceanParams) -> Self
Deterministically generate a spectrum from params.
Sourcepub fn phases_at(&self, time: f64) -> Vec<f32>
pub fn phases_at(&self, time: f64) -> Vec<f32>
Per-wave phase ωᵢ·t − φ₀ᵢ, computed in f64 and wrapped to [0, 2π).
The shader (and the CPU sampler) evaluate θ = k·(d·p) − phase_t.
Sourcepub fn displacement(&self, x: f32, z: f32, phases: &[f32]) -> [f32; 3]
pub fn displacement(&self, x: f32, z: f32, phases: &[f32]) -> [f32; 3]
Lagrangian Gerstner offset of the parameter point (x, z) at the given pre-computed phases. Returns [dx, dy, dz].
Sourcepub fn normal(&self, x: f32, z: f32, phases: &[f32]) -> [f32; 3]
pub fn normal(&self, x: f32, z: f32, phases: &[f32]) -> [f32; 3]
Surface normal at parameter point (x, z).
Sourcepub fn sample_height(&self, x: f32, z: f32, time: f64) -> f32
pub fn sample_height(&self, x: f32, z: f32, time: f64) -> f32
Eulerian surface height at world (x, z) — what buoyancy wants.
Gerstner is Lagrangian (it moves particles horizontally), so we invert the horizontal displacement by fixed-point iteration: find the parameter point p whose displaced position lands on (x, z). Converges because Σ Q·k·A ≤ 1 keeps the map a contraction.
Sourcepub fn sample_height_with_phases(&self, x: f32, z: f32, phases: &[f32]) -> f32
pub fn sample_height_with_phases(&self, x: f32, z: f32, phases: &[f32]) -> f32
Like [sample_height], reusing precomputed phases (batch queries).
Sourcepub fn sample_normal(&self, x: f32, z: f32, time: f64) -> [f32; 3]
pub fn sample_normal(&self, x: f32, z: f32, time: f64) -> [f32; 3]
Eulerian surface normal at world (x, z).
Sourcepub fn sample_velocity_y(&self, x: f32, z: f32, time: f64) -> f32
pub fn sample_velocity_y(&self, x: f32, z: f32, time: f64) -> f32
Vertical velocity (m/s) of the surface at world (x, z): ∂/∂t of the height at the inverted parameter point. y = Σ A·sinθ with θ advancing at ω·speed_scale, so dy/dt = −Σ A·ω_eff·cosθ. The parameter-drift term (Q·horizontal motion) is omitted — exact at choppiness 0, bounded by the steepness budget otherwise. Intended for audio/gameplay triggers.
Sourcepub fn to_gpu(&self, time: f64) -> [[f32; 4]; 32]
pub fn to_gpu(&self, time: f64) -> [[f32; 4]; 32]
Pack waves for the GPU: two vec4s per wave slot, MAX_WAVES slots.
Slot layout: [dir.x, dir.y, k, amp], [phase_t, q, omega_eff, 0].
omega_eff = ω·speed_scale — the rate phase_t actually advances at,
so the shader’s analytic surface velocity (contact foam) matches the
animation. Unused slots are zero (amp 0 contributes nothing).
Trait Implementations§
Source§impl Clone for WaveSpectrum
impl Clone for WaveSpectrum
Source§fn clone(&self) -> WaveSpectrum
fn clone(&self) -> WaveSpectrum
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more