Flint Engine / Guide / API Reference

WaveSpectrum

Struct WaveSpectrum 

Source
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

Source

pub fn generate(params: &OceanParams) -> Self

Deterministically generate a spectrum from params.

Source

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.

Source

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].

Source

pub fn normal(&self, x: f32, z: f32, phases: &[f32]) -> [f32; 3]

Surface normal at parameter point (x, z).

Source

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.

Source

pub fn sample_height_with_phases(&self, x: f32, z: f32, phases: &[f32]) -> f32

Like [sample_height], reusing precomputed phases (batch queries).

Source

pub fn sample_normal(&self, x: f32, z: f32, time: f64) -> [f32; 3]

Eulerian surface normal at world (x, z).

Source

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.

Source

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

Source§

fn clone(&self) -> WaveSpectrum

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for WaveSpectrum

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.