#pragma once #include "hd2d/Weather.h" #include #include namespace hd2d { // Time of day: turns an hour into a complete clear-weather WeatherLook by // smoothly interpolating tweakable keyframes, and moves the directional // light along a sun arc by day and a moon arc by night (so shadows always // work). Feed the result to Weather::setClearLook() every frame; the hour is // usually driven externally (e.g. by a game server). class DayCycle { public: struct Keyframe { float hour; // [0, 24) const char* name; // for tuning UIs WeatherLook look; // sunAzimuth / sunElevation / daylight are ignored (computed from the hour) }; DayCycle(); // default keys: late night, dawn, morning, noon, afternoon, dusk, night WeatherLook look(float hour) const; // any hour, wraps to [0, 24) float daylight(float hour) const; // 0 night .. 1 day (sun height above the horizon) float night(float hour) const; // 0 day .. 1 night (stars + moon visibility) // Direction of the directional light: x = azimuth, y = elevation // (radians, see Sun); the sun between sunrise and sunset, else the moon. glm::vec2 lightAngles(float hour) const; bool moonUp(float hour) const; std::vector keys; // sorted by hour; interpolation wraps around midnight float sunrise = 5.0f, sunset = 19.0f; float sunAzimuth = -0.6f; // azimuth at solar noon float sunSweep = 2.6f; // azimuth travelled from sunrise to sunset float sunMaxElevation = 1.05f; float moonAzimuth = 0.45f; // azimuth at the middle of the night float moonSweep = 1.6f; float moonMaxElevation = 0.62f; float horizonFade = 0.12f; // light elevation (radians) over which it fades in float minElevation = 0.05f; // light never goes lower (keeps shadows stable) }; } // namespace hd2d