From 9b6347d62de5dc33aed3b8349906d1e3eb996dbf Mon Sep 17 00:00:00 2001 From: Semphris Date: Sun, 9 Jan 2022 23:49:18 -0500 Subject: [PATCH] Added animation to stars --- src/graphics/stars.cpp | 47 ++++++++++++++++++++---------------------- src/graphics/stars.hpp | 2 +- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/src/graphics/stars.cpp b/src/graphics/stars.cpp index c36a0e94b..682069726 100644 --- a/src/graphics/stars.cpp +++ b/src/graphics/stars.cpp @@ -28,6 +28,7 @@ #include +const int FREQUENCY = 2; const int STAR_AMOUNT = 7; const float RADIUS = 0.7f; const float STAR_SIZE = 0.4f; @@ -73,7 +74,7 @@ void Stars::showFor(float time) { m_enabled = true; m_remaining_time = time; - m_fade_in_time = 1.0f; + m_period = time; const int node_amount = (int)m_nodes.size(); for (int n=0; n(m_period); n++) + { + factor += 4.0f / M_PI * (sin(M_PI / m_period * (2.0f * n - 1.0f) * + (m_period - m_remaining_time)) / (2.0f * n - 1.0f)); + } + factor = pow(factor, 2.f); + + // When the factor is very small, the stars are rendered incorrectly + if (factor <= 0.001f) + return; + + float radius = RADIUS * factor; + const int node_amount = (int)m_nodes.size(); for (int n=0; n 0.0f) - { - float fade = (1.0f - m_fade_in_time); - - ((scene::IBillboardSceneNode*)m_nodes[n])->setSize( - core::dimension2d< f32 >(fade*STAR_SIZE, fade*STAR_SIZE) ); - - radius *= fade; - } - // manage "fade-out" - else if (m_remaining_time < 1.0f) - { - radius *= m_remaining_time; - - ((scene::IBillboardSceneNode*)m_nodes[n]) - ->setSize( core::dimension2df(m_remaining_time*STAR_SIZE, - m_remaining_time*STAR_SIZE) ); - } + ((scene::IBillboardSceneNode*)m_nodes[n]) + ->setSize( core::dimension2df(factor*STAR_SIZE, + factor*STAR_SIZE) ); // Set position: X and Z are the position in the cirlce, // the Y components shakes the stars up and down like falling coin @@ -159,7 +158,5 @@ void Stars::update(float delta_t) std::sin(angle*M_PI*2.0f)*radius ); m_nodes[n]->setPosition(m_center + offset); } // end for - - if (m_fade_in_time > 0.0f) m_fade_in_time -= delta_t; } // update diff --git a/src/graphics/stars.hpp b/src/graphics/stars.hpp index 02c1d90fe..3097c3a7f 100644 --- a/src/graphics/stars.hpp +++ b/src/graphics/stars.hpp @@ -53,7 +53,7 @@ private: /** Whether stars are currently enabled */ bool m_enabled; - float m_fade_in_time; + float m_period; float m_remaining_time; public: