DayNight module — a time-of-day cycle that drives the sun, sky and light. 更多...
#include <DayNight.h>
类 | |
| struct | Impl |
Public 成员函数 | |
| Module_REG (DayNight) | |
| DayNight () | |
| ~DayNight () override | |
| void | init (graphics::Graphics *gfx) |
| Idempotent; builds lights / sky cubemap on first call. | |
| void | update (float dt, graphics::Graphics *gfx) |
| Advance the clock and push sun/sky/light state; before gfx.render3D(). | |
| void | setTimeOfDay (float hours) |
| float | getTimeOfDay () const |
| void | setSpeed (float hoursPerRealHour) |
| float | getSpeed () const |
| void | setPaused (bool paused) |
| bool | isPaused () const |
| bool | isNight () const |
| True when the sun is below the horizon (night). | |
| float | getSunElevation () const |
| Solar elevation in degrees (max at local noon, ~70°). | |
| float | getSunAzimuth () const |
| Solar azimuth in degrees, measured clockwise from +Z. | |
| float | getSunDirX () const |
| World-space direction pointing AT the sun (normalized). | |
| float | getSunDirY () const |
| float | getSunDirZ () const |
| float | getSunIntensity () const |
| 0..1 sun energy; ramps to 0 below the horizon. | |
| float | getSkyR () const |
| float | getSkyG () const |
| float | getSkyB () const |
| float | getAmbientR () const |
| float | getAmbientG () const |
| float | getAmbientB () const |
| float | getAmbientBrightness () const |
| void | setSkyboxEnabled (bool enabled) |
| bool | isSkyboxEnabled () const |
| void | setNightLight (const std::string &name, bool enabled) |
| Enable a named light system: "moonlight"|"starlight"|"fire"|"fireflies". | |
| bool | isNightLight (const std::string &name) const |
| void | setFirePosition (float x, float y, float z) |
| Position of the campfire point light (fire system). | |
| void | addFirefly (float x, float y, float z) |
| Add one firefly anchor (world space); up to kMaxFireflies. | |
| void | clearFireflies () |
| int | getFireflyCount () const |
Public 成员函数 继承自 eve::Module | |
| virtual | ~Module () |
| virtual std::string | getName () const =0 |
静态 Public 属性 | |
| static const char *const | kNamedLights [] = {"moonlight", "starlight", "fire", "fireflies"} |
| static const int | kNamedLightCount = 4 |
详细描述
DayNight module — a time-of-day cycle that drives the sun, sky and light.
Advances a 24-hour clock (configurable speed) and, each frame, repositions the directional sun to match the current solar elevation / azimuth. A procedural sky cubemap (sky gradient + sun disc + night stars) is generated on demand and registered as the 3D IBL environment so both the skybox angle and the reflected sky follow the sun as time flows.
At night the module can switch between complementary lighting systems, each implemented as a pool of Light3D entities:
- moonlight : a cool, low directional light from the moon direction
- starlight : a faint, slightly-blue ambient that softens the dark
- fire : a warm point light at a caller-provided campfire position
- fireflies : a set of warm, gently-drifting point lights
Usage from script: daynight.setTimeOfDay(12.0); // solar noon daynight.setSpeed(1.0); // 1 real hour per simulated hour daynight.setNightLight("fireflies", true); // each frame before gfx.render3D(): daynight.update(dt, gfx); camera.setAmbient(daynight.getAmbientR(), ...);
在文件 DayNight.h 第 39 行定义.
构造及析构函数说明
◆ DayNight()
| eve::daynight::DayNight::DayNight | ( | ) |
在文件 DayNight.cpp 第 174 行定义.
◆ ~DayNight()
|
override |
在文件 DayNight.cpp 第 175 行定义.
成员函数说明
◆ addFirefly()
| void eve::daynight::DayNight::addFirefly | ( | float | x, |
| float | y, | ||
| float | z | ||
| ) |
Add one firefly anchor (world space); up to kMaxFireflies.
在文件 DayNight.cpp 第 261 行定义.
引用了 eve::daynight::DayNight::Impl::built, eve::graphics::Light3D::createLight(), f, eve::daynight::DayNight::Impl::flies, eve::daynight::DayNight::Impl::flyLights, eve::graphics::Light3D::setColor(), eve::graphics::Light3D::setEnabled(), eve::graphics::Light3D::setPosition(), eve::graphics::Light3D::setRadius(), eve::daynight::DayNight::Impl::Fly::x, x, y , 以及 z.
◆ clearFireflies()
| void eve::daynight::DayNight::clearFireflies | ( | ) |
在文件 DayNight.cpp 第 276 行定义.
引用了 eve::daynight::DayNight::Impl::flies , 以及 eve::daynight::DayNight::Impl::flyLights.
◆ getAmbientB()
| float eve::daynight::DayNight::getAmbientB | ( | ) | const |
在文件 DayNight.cpp 第 218 行定义.
引用了 getAmbientBrightness() , 以及 eve::daynight::DayNight::Impl::sunEnergy.
◆ getAmbientBrightness()
| float eve::daynight::DayNight::getAmbientBrightness | ( | ) | const |
在文件 DayNight.cpp 第 206 行定义.
引用了 eve::daynight::DayNight::Impl::nightLight , 以及 eve::daynight::DayNight::Impl::sunEnergy.
被这些函数引用 getAmbientB(), getAmbientG() , 以及 getAmbientR().
◆ getAmbientG()
| float eve::daynight::DayNight::getAmbientG | ( | ) | const |
在文件 DayNight.cpp 第 214 行定义.
引用了 getAmbientBrightness() , 以及 eve::daynight::DayNight::Impl::sunEnergy.
◆ getAmbientR()
| float eve::daynight::DayNight::getAmbientR | ( | ) | const |
在文件 DayNight.cpp 第 210 行定义.
◆ getFireflyCount()
| int eve::daynight::DayNight::getFireflyCount | ( | ) | const |
在文件 DayNight.cpp 第 280 行定义.
◆ getSkyB()
| float eve::daynight::DayNight::getSkyB | ( | ) | const |
◆ getSkyG()
| float eve::daynight::DayNight::getSkyG | ( | ) | const |
◆ getSkyR()
| float eve::daynight::DayNight::getSkyR | ( | ) | const |
◆ getSpeed()
| float eve::daynight::DayNight::getSpeed | ( | ) | const |
在文件 DayNight.cpp 第 189 行定义.
◆ getSunAzimuth()
| float eve::daynight::DayNight::getSunAzimuth | ( | ) | const |
Solar azimuth in degrees, measured clockwise from +Z.
在文件 DayNight.cpp 第 196 行定义.
◆ getSunDirX()
| float eve::daynight::DayNight::getSunDirX | ( | ) | const |
World-space direction pointing AT the sun (normalized).
在文件 DayNight.cpp 第 197 行定义.
◆ getSunDirY()
| float eve::daynight::DayNight::getSunDirY | ( | ) | const |
在文件 DayNight.cpp 第 198 行定义.
◆ getSunDirZ()
| float eve::daynight::DayNight::getSunDirZ | ( | ) | const |
在文件 DayNight.cpp 第 199 行定义.
◆ getSunElevation()
| float eve::daynight::DayNight::getSunElevation | ( | ) | const |
Solar elevation in degrees (max at local noon, ~70°).
在文件 DayNight.cpp 第 195 行定义.
◆ getSunIntensity()
| float eve::daynight::DayNight::getSunIntensity | ( | ) | const |
0..1 sun energy; ramps to 0 below the horizon.
在文件 DayNight.cpp 第 200 行定义.
◆ getTimeOfDay()
| float eve::daynight::DayNight::getTimeOfDay | ( | ) | const |
在文件 DayNight.cpp 第 186 行定义.
◆ init()
| void eve::daynight::DayNight::init | ( | graphics::Graphics * | gfx | ) |
Idempotent; builds lights / sky cubemap on first call.
在文件 DayNight.cpp 第 286 行定义.
引用了 eve::daynight::DayNight::Impl::built, eve::graphics::Light3D::createLight(), f, eve::daynight::DayNight::Impl::fireLight, eve::daynight::DayNight::Impl::fireX, eve::daynight::DayNight::Impl::fireY, eve::daynight::DayNight::Impl::fireZ, eve::daynight::DayNight::Impl::flies, eve::daynight::DayNight::Impl::flyLights, eve::daynight::DayNight::Impl::gfx, eve::daynight::DayNight::Impl::moonLight, eve::graphics::Light3D::setColor(), eve::graphics::Light3D::setDirection(), eve::graphics::Light3D::setEnabled(), eve::graphics::Light3D::setPosition() , 以及 eve::graphics::Light3D::setRadius().
被这些函数引用 update().
◆ isNight()
| bool eve::daynight::DayNight::isNight | ( | ) | const |
True when the sun is below the horizon (night).
在文件 DayNight.cpp 第 193 行定义.
◆ isNightLight()
| bool eve::daynight::DayNight::isNightLight | ( | const std::string & | name | ) | const |
在文件 DayNight.cpp 第 245 行定义.
引用了 kNamedLightCount, kNamedLights, name , 以及 eve::daynight::DayNight::Impl::nightLight.
◆ isPaused()
| bool eve::daynight::DayNight::isPaused | ( | ) | const |
在文件 DayNight.cpp 第 191 行定义.
◆ isSkyboxEnabled()
| bool eve::daynight::DayNight::isSkyboxEnabled | ( | ) | const |
在文件 DayNight.cpp 第 231 行定义.
◆ Module_REG()
| eve::daynight::DayNight::Module_REG | ( | DayNight | ) |
◆ setFirePosition()
| void eve::daynight::DayNight::setFirePosition | ( | float | x, |
| float | y, | ||
| float | z | ||
| ) |
Position of the campfire point light (fire system).
在文件 DayNight.cpp 第 252 行定义.
引用了 eve::daynight::DayNight::Impl::fireLight, eve::daynight::DayNight::Impl::fireX, eve::daynight::DayNight::Impl::fireY, eve::daynight::DayNight::Impl::fireZ, eve::graphics::Light3D::setColor(), eve::graphics::Light3D::setPosition(), eve::graphics::Light3D::setRadius(), x, y , 以及 z.
◆ setNightLight()
| void eve::daynight::DayNight::setNightLight | ( | const std::string & | name, |
| bool | enabled | ||
| ) |
Enable a named light system: "moonlight"|"starlight"|"fire"|"fireflies".
在文件 DayNight.cpp 第 237 行定义.
引用了 enabled, kNamedLightCount, kNamedLights, name , 以及 eve::daynight::DayNight::Impl::nightLight.
◆ setPaused()
| void eve::daynight::DayNight::setPaused | ( | bool | paused | ) |
在文件 DayNight.cpp 第 190 行定义.
引用了 p , 以及 eve::daynight::DayNight::Impl::paused.
◆ setSkyboxEnabled()
| void eve::daynight::DayNight::setSkyboxEnabled | ( | bool | enabled | ) |
◆ setSpeed()
| void eve::daynight::DayNight::setSpeed | ( | float | hoursPerRealHour | ) |
在文件 DayNight.cpp 第 188 行定义.
◆ setTimeOfDay()
| void eve::daynight::DayNight::setTimeOfDay | ( | float | hours | ) |
在文件 DayNight.cpp 第 181 行定义.
引用了 h , 以及 eve::daynight::DayNight::Impl::timeOfDay.
◆ update()
| void eve::daynight::DayNight::update | ( | float | dt, |
| graphics::Graphics * | gfx | ||
| ) |
Advance the clock and push sun/sky/light state; before gfx.render3D().
在文件 DayNight.cpp 第 316 行定义.
引用了 eve::daynight::DayNight::Impl::azimDeg, eve::daynight::DayNight::Impl::built, eve::daynight::DayNight::Impl::elevDeg, f, eve::daynight::DayNight::Impl::fireLight, eve::daynight::DayNight::Impl::flies, eve::daynight::DayNight::Impl::flyLights, getSkyB(), getSkyG(), getSkyR(), eve::daynight::DayNight::Impl::gfx, init(), eve::daynight::DayNight::Impl::lastSkyBucket, eve::daynight::DayNight::Impl::moonLight, eve::graphics::Graphics::newCubemap(), eve::daynight::DayNight::Impl::nightLight, eve::daynight::DayNight::Impl::paused, eve::graphics::Graphics::setBackgroundColorRGBA(), eve::graphics::Light3D::setDirection(), eve::graphics::Graphics::setDirectionalLight(), eve::graphics::Light3D::setEnabled(), eve::graphics::Graphics::setMesh3DEnv(), eve::graphics::Light3D::setPosition(), eve::daynight::DayNight::Impl::skyboxEnabled, eve::daynight::DayNight::Impl::skyCube, eve::daynight::DayNight::Impl::speed, eve::daynight::DayNight::Impl::sunDir, eve::daynight::DayNight::Impl::sunEnergy , 以及 eve::daynight::DayNight::Impl::timeOfDay.
类成员变量说明
◆ kNamedLightCount
|
static |
在文件 DayNight.h 第 91 行定义.
被这些函数引用 isNightLight() , 以及 setNightLight().
◆ kNamedLights
|
static |
在文件 DayNight.h 第 90 行定义.
被这些函数引用 isNightLight() , 以及 setNightLight().
该类的文档由以下文件生成:
- src/modules/daynight/DayNight.h
- src/modules/daynight/DayNight.cpp
Public 成员函数 继承自