From a0e2ff6eab4866471c1c4fe3ddd12fdd8c616739 Mon Sep 17 00:00:00 2001 From: LaG1924 <12997935+LaG1924@users.noreply.github.com> Date: Tue, 21 Aug 2018 14:23:16 +0500 Subject: Smooth sun movement --- src/GameState.cpp | 5 +++++ src/GameState.hpp | 3 +++ src/RendererWorld.cpp | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/GameState.cpp b/src/GameState.cpp index c42092a..fabfdb8 100644 --- a/src/GameState.cpp +++ b/src/GameState.cpp @@ -58,6 +58,9 @@ void GameState::Update(float deltaTime) { isBlockSelected = raycast.isHit; raycastHit = raycast.hitPos; + + if (doDaylightCycle) + interpolatedTimeOfDay += 20.0 * deltaTime; } } @@ -433,8 +436,10 @@ void GameState::UpdatePacket(std::shared_ptr ptr) { case TimeUpdate: { auto packet = std::static_pointer_cast(ptr); + doDaylightCycle = TimeOfDay != packet->TimeOfDay; WorldAge = packet->WorldAge; TimeOfDay = packet->TimeOfDay; + interpolatedTimeOfDay = TimeOfDay; break; } diff --git a/src/GameState.hpp b/src/GameState.hpp index 81ab3dc..e96af29 100644 --- a/src/GameState.hpp +++ b/src/GameState.hpp @@ -67,4 +67,7 @@ public: Vector selectedBlock; float distanceToSelectedBlock; VectorF raycastHit; + + double interpolatedTimeOfDay; + bool doDaylightCycle = true; }; diff --git a/src/RendererWorld.cpp b/src/RendererWorld.cpp index 2ed2620..023ac32 100644 --- a/src/RendererWorld.cpp +++ b/src/RendererWorld.cpp @@ -349,7 +349,7 @@ void RendererWorld::Render(RenderState & renderState) { model = glm::translate(model, gs->player->pos.glm()); const float scale = 1000000.0f; model = glm::scale(model, glm::vec3(scale, scale, scale)); - float shift = gs->TimeOfDay / 24000.0f; + float shift = gs->interpolatedTimeOfDay / 24000.0f; if (shift < 0) shift *= -1.0f; model = glm::rotate(model, glm::radians(90.0f), glm::vec3(0, 1.0f, 0.0f)); -- cgit v1.2.3