Added animation to stars
This commit is contained in:
parent
5999ff94ab
commit
9b6347d62d
@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
|
const int FREQUENCY = 2;
|
||||||
const int STAR_AMOUNT = 7;
|
const int STAR_AMOUNT = 7;
|
||||||
const float RADIUS = 0.7f;
|
const float RADIUS = 0.7f;
|
||||||
const float STAR_SIZE = 0.4f;
|
const float STAR_SIZE = 0.4f;
|
||||||
@ -73,7 +74,7 @@ void Stars::showFor(float time)
|
|||||||
{
|
{
|
||||||
m_enabled = true;
|
m_enabled = true;
|
||||||
m_remaining_time = time;
|
m_remaining_time = time;
|
||||||
m_fade_in_time = 1.0f;
|
m_period = time;
|
||||||
|
|
||||||
const int node_amount = (int)m_nodes.size();
|
const int node_amount = (int)m_nodes.size();
|
||||||
for (int n=0; n<node_amount; n++)
|
for (int n=0; n<node_amount; n++)
|
||||||
@ -115,6 +116,23 @@ void Stars::update(float delta_t)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is a basic Fourier series for a square wave, with edits to allow
|
||||||
|
// adjusting the period and controlling the frequency based on the
|
||||||
|
// period.
|
||||||
|
float factor = 0.0f;
|
||||||
|
for (int n = 1; n <= FREQUENCY * static_cast<int>(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();
|
const int node_amount = (int)m_nodes.size();
|
||||||
for (int n=0; n<node_amount; n++)
|
for (int n=0; n<node_amount; n++)
|
||||||
{
|
{
|
||||||
@ -128,28 +146,9 @@ void Stars::update(float delta_t)
|
|||||||
// keep angle in range [0, 1[
|
// keep angle in range [0, 1[
|
||||||
angle -= (int)angle;
|
angle -= (int)angle;
|
||||||
|
|
||||||
float radius = RADIUS;
|
|
||||||
|
|
||||||
|
|
||||||
// manage "fade-in"
|
|
||||||
if (m_fade_in_time > 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])
|
((scene::IBillboardSceneNode*)m_nodes[n])
|
||||||
->setSize( core::dimension2df(m_remaining_time*STAR_SIZE,
|
->setSize( core::dimension2df(factor*STAR_SIZE,
|
||||||
m_remaining_time*STAR_SIZE) );
|
factor*STAR_SIZE) );
|
||||||
}
|
|
||||||
|
|
||||||
// Set position: X and Z are the position in the cirlce,
|
// Set position: X and Z are the position in the cirlce,
|
||||||
// the Y components shakes the stars up and down like falling coin
|
// 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 );
|
std::sin(angle*M_PI*2.0f)*radius );
|
||||||
m_nodes[n]->setPosition(m_center + offset);
|
m_nodes[n]->setPosition(m_center + offset);
|
||||||
} // end for
|
} // end for
|
||||||
|
|
||||||
if (m_fade_in_time > 0.0f) m_fade_in_time -= delta_t;
|
|
||||||
} // update
|
} // update
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ private:
|
|||||||
/** Whether stars are currently enabled */
|
/** Whether stars are currently enabled */
|
||||||
bool m_enabled;
|
bool m_enabled;
|
||||||
|
|
||||||
float m_fade_in_time;
|
float m_period;
|
||||||
float m_remaining_time;
|
float m_remaining_time;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
Loading…
Reference in New Issue
Block a user