vkmEngine 1.0.15
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
ocean_surface.h
1#pragma once
2
3#include <array>
4#include <cstdint>
5
6#include <glm/glm.hpp>
7
8#include "ecs/component/render/ocean.h"
9
10namespace Vkm::Engine {
11
13constexpr double JONSWAP_GAMMA = 3.3;
14constexpr double JONSWAP_SIGMA_BELOW = 0.07;
15constexpr double JONSWAP_SIGMA_ABOVE = 0.09;
16
19 glm::vec2 direction = {0.0f, 1.0f};
20 float wavenumber = 0.0f;
21 float frequency = 0.0f;
22 float amplitude = 0.0f;
24 float steepness = 0.0f;
25 float phase = 0.0f;
26};
27
30 float height = 0.0f;
31 glm::vec3 normal = {0.0f, 1.0f, 0.0f};
32};
33
48 static constexpr double GRAVITY = 9.81;
49
51 static constexpr float SURGE_WHOLE = 0.6f;
52
55 static constexpr uint32_t INVERSE_STEPS = 4;
56
57 std::array<GerstnerWave, Ocean::MAX_WAVES> waves{};
58 uint32_t count = 0;
60 std::array<OceanSurge, Ocean::MAX_SURGES> surges{};
61 glm::vec2 centre = glm::vec2(0.0f);
62 float calmRadius = 0.0f;
63 float stillRadius = 0.0f;
64
78 static OceanSurface at(const Ocean& ocean, const glm::vec3& centre, double time);
79
81 float reach(const glm::vec2& rest) const;
82
84 glm::vec3 displacement(const glm::vec2& rest) const;
85
87 float heightAt(const glm::vec2& point) const;
88
90 glm::vec3 normalAt(const glm::vec2& point) const;
91
93 OceanSample sampleAt(const glm::vec2& point) const;
94
96 float significantHeight() const;
97
100 glm::vec2 farthestReach() const;
101
104};
105
117 static constexpr double LOOP = 256.0;
118
119 float longest = 0.0f;
120 float shortest = 0.0f;
121 float peak = 0.0f;
122 float alpha = 0.0f;
123 float depth = 0.0f;
124 float heightScale = 1.0f;
125 float choppiness = 0.0f;
126 glm::vec2 wind = {0.0f, 1.0f};
127 float spreadPower = 1.0f;
128 float spreadScale = 0.0f;
129 uint32_t seed = 0;
130 float cycle = 0.0f;
131
139 static OceanRipples at(const Ocean& ocean, double time);
140
142 bool any() const { return shortest > longest && alpha > 0.0f; }
143
145 float density(const glm::vec2& k) const;
146
148 float slopeVariance(float from, float to) const;
149};
150
151} // namespace Vkm::Engine
One wave of an ocean's sum, at the surface's moment.
Definition ocean_surface.h:18
glm::vec2 direction
Unit, on the XZ plane: the way it rolls.
Definition ocean_surface.h:19
float wavenumber
Radians a metre: 2 pi over its length.
Definition ocean_surface.h:20
float amplitude
Definition ocean_surface.h:22
float frequency
Radians a second, by the dispersion at the ocean's depth.
Definition ocean_surface.h:21
float phase
Radians at the rest point's origin and this moment, in [0, 2 pi).
Definition ocean_surface.h:25
float steepness
How far a crest draws the water toward it, in amplitudes; the sum never folds over.
Definition ocean_surface.h:24
An ocean's ripples at one moment: its spectrum on below minWavelength, down to shortestRipple,...
Definition ocean_surface.h:114
static constexpr double LOOP
Definition ocean_surface.h:117
glm::vec2 wind
Unit, on the XZ plane: the way the waves roll.
Definition ocean_surface.h:126
static OceanRipples at(const Ocean &ocean, double time)
The ripples of ocean, time seconds in: none for a windless ocean.
float slopeVariance(float from, float to) const
The variance of the slope the ripples between wavenumbers from and to raise.
float alpha
Its scale, Phillips' alpha times g squared.
Definition ocean_surface.h:122
float spreadPower
s, in the spread's cos^2s of half the angle off the wind.
Definition ocean_surface.h:127
float cycle
How far through LOOP, 0..1.
Definition ocean_surface.h:130
float longest
The band's lowest wavenumber, radians a metre: the shortest wave's.
Definition ocean_surface.h:119
float density(const glm::vec2 &k) const
Height variance a square radian a metre of wavenumber k holds: what the grids draw.
float peak
JONSWAP's peak frequency, radians a second.
Definition ocean_surface.h:121
float spreadScale
What makes the spread one round the circle.
Definition ocean_surface.h:128
float shortest
Its highest; no ripples unless above longest.
Definition ocean_surface.h:120
bool any() const
Whether there are any: wind, and a band.
Definition ocean_surface.h:142
float choppiness
How far a crest squeezes the surface, as the waves'.
Definition ocean_surface.h:125
float depth
Metres; 0 deep.
Definition ocean_surface.h:123
The water over a world point: its height above the surface's rest, and the surface's normal.
Definition ocean_surface.h:29
An ocean's surface at one moment: the waves the spectrum gives, and what they do.
Definition ocean_surface.h:46
static OceanSurface at(const Ocean &ocean, const glm::vec3 &centre, double time)
The surface of ocean, centred at centre, time seconds in.
float reach(const glm::vec2 &rest) const
How much of the waves reach rest: 1 inside calmRadius, 0 from stillRadius out.
glm::vec3 normalAt(const glm::vec2 &point) const
The surface's unit normal over the world point point.
glm::vec2 centre
Where the waves are whole.
Definition ocean_surface.h:61
OceanSurface withoutSurges() const
The same surface without its surges: the wind's sea alone.
std::array< OceanSurge, Ocean::MAX_SURGES > surges
The ocean's, as they stand this moment, each direction unit; one with none is left out.
Definition ocean_surface.h:60
static constexpr uint32_t INVERSE_STEPS
Definition ocean_surface.h:55
glm::vec3 displacement(const glm::vec2 &rest) const
Where the water resting at rest has been carried: X and Z across, Y up.
static constexpr double GRAVITY
Metres a second squared: what pulls every wave back, and sets how fast each rolls.
Definition ocean_surface.h:48
OceanSample sampleAt(const glm::vec2 &point) const
Both, for the price of finding the water over point once: what floating things ask.
float significantHeight() const
Spectral significant wave height, 4 sqrt(m0): the mean of the highest third of the waves.
static constexpr float SURGE_WHOLE
Of a surge's length, the share in the middle at its full height; past it each end tapers away.
Definition ocean_surface.h:51
glm::vec2 farthestReach() const
float heightAt(const glm::vec2 &point) const
The water's height over the world point point, above the surface's rest.
The scene's sea: wind-driven waves moving every surface whose material is waves.
Definition ocean.h:40