From 3573ecff39a617cc4084660aba2baf6f4bebfaaf Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 22 Sep 2024 12:54:48 +0100 Subject: Calculate sunlight direction from worldTime --- game/environment.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'game') diff --git a/game/environment.cpp b/game/environment.cpp index 665c11b..1ef9bcb 100644 --- a/game/environment.cpp +++ b/game/environment.cpp @@ -7,14 +7,16 @@ Environment::Environment() : worldTime {"2024-01-01T12:00:00"_time_t} { } void Environment::tick(TickDuration) { - worldTime += 1; + worldTime += 50; } void Environment::render(const SceneRenderer & renderer, const SceneProvider & scene) const { + const auto sunPos = getSunPos({}, worldTime); + const auto sunDir = (glm::mat3 {rotate_yp({sunPos.y + pi, sunPos.x})} * north); renderer.setAmbientLight({0.5F, 0.5F, 0.5F}); - renderer.setDirectionalLight({0.6F, 0.6F, 0.6F}, {-1, 1, -1}, scene); + renderer.setDirectionalLight({0.6F, 0.6F, 0.6F}, sunDir, scene); } // Based on the C++ code published at https://www.psa.es/sdg/sunpos.htm -- cgit v1.2.3