hex-world
    Preparing search index...

    Class Wind

    One wind for the whole world: the vector that drifts the cloud deck, slants the rain, bends the trees, and marches the ripples across a lake.

    Nothing here draws anything. It is a handful of numbers advanced once a frame and read by every system that should agree about which way the weather is going — which is the entire point, because four effects each animating on their own clock is what makes a scene read as four animations instead of as one place with weather in it.

    base is the sustained wind: mutate it freely, and it is what the cloud deck drifts by. surface is what a gust is doing right now — base swung in speed by gustiness and in direction by turbulence — and it is what the rain and the plants follow. A whole overcast deck does not surge in a two-second gust; the hedge under it does, and having both available is what lets each take the one that is true of it.

    phase accumulates on the CPU rather than being recovered in a shader as time × rate. Multiplying a shared clock by a changing rate rewinds the wave's phase every time the wind picks up, which reads as the trees briefly swaying backwards. The same reasoning keeps the cloud offset and drift on the CPU.

    const wind = new Wind({ heading: Math.PI * 0.25, speed: 4 });
    // per frame:
    wind.advance(dt);
    setMaterialWind(myMaterials, wind);
    Index

    Constructors

    Properties

    base: Vector2 = ...

    The sustained wind in world units/sec. Mutate freely — everything derived from it turns smoothly, because the offsets that consume it are integrated rather than recomputed from a clock.

    surface: Vector2 = ...

    The wind at ground level this instant: base with the current gust and direction wander folded in. Recomputed by advance; treat as read-only.

    drift: Vector2 = ...

    How far a water surface's ripple pattern has travelled downwind, in world units. Integrated, so a change of wind turns the pattern instead of teleporting it.

    gustiness: number = 0.35

    WindOptions.gustiness

    gustPeriod: number = 7

    WindOptions.gustPeriod

    turbulence: number = 0.12

    WindOptions.turbulence

    referenceSpeed: number = 5

    WindOptions.referenceSpeed

    swayRate: number = 2.6

    WindOptions.swayRate

    waveLength: number = 26

    WindOptions.waveLength

    waterDrift: number = 0.02

    WindOptions.waterDrift

    Accessors

    • get speed(): number

      Sustained speed in world units/sec.

      Returns number

    • get heading(): number

      Sustained heading in radians, from +X toward +Z.

      Returns number

    • get gust(): number

      The current gust multiplier on base: 1 is the sustained wind.

      Returns number

    • get phase(): number

      Accumulated sway phase in radians.

      Returns number

      Wind — why this is integrated.

    • get strength(): number

      Surface wind as a fraction of referenceSpeed: 0 calm, 1 a full wind, above 1 a storm (capped at 2 so a wild base cannot fold a tree through the ground). This is the number the shaders scale by.

      Returns number

    • get waveNumber(): number

      Radians of gust phase per world unit travelled downwind.

      Returns number

    Methods

    • Point the sustained wind, in radians from +X toward +Z.

      Parameters

      • heading: number
      • speed: number

      Returns void

    • Advance the gust, the sway phase, and the water drift by one frame. Call once per frame from whoever owns this wind — HexWorld does it for the wind it shares with its WeatherSystem.

      Parameters

      • dt: number

      Returns void