FadingLogos: add LogoParams class to keep track of multiple logos
This commit is contained in:
parent
ef7e8107b6
commit
8bf3b595c3
@ -12,5 +12,5 @@ interface Mode
|
||||
*
|
||||
* @param[in] ms Elapsed milliseconds since this mode was started.
|
||||
*/
|
||||
public void display(ScreenSaver ss, int ms);
|
||||
public void display(ScreenSaver ss, uint ms);
|
||||
}
|
||||
|
@ -1,3 +1,7 @@
|
||||
import std.random : uniform;
|
||||
import std.algorithm;
|
||||
static import math = std.math;
|
||||
|
||||
import derelict.opengl3.gl3;
|
||||
import gl3n.linalg;
|
||||
|
||||
@ -8,7 +12,25 @@ import default_shader;
|
||||
|
||||
class FadingLogos : Mode
|
||||
{
|
||||
DefaultShader m_shader;
|
||||
immutable uint CREATE_DELAY = 5000;
|
||||
immutable uint CHARACTER_FLY_TIME = 500;
|
||||
immutable uint FADE_DELAY = 30000;
|
||||
immutable uint FADE_TIME = 15000;
|
||||
|
||||
class LogoParams
|
||||
{
|
||||
uint create_time;
|
||||
float c_x;
|
||||
float c_y;
|
||||
float rotation;
|
||||
float scale;
|
||||
uint character_create_time;
|
||||
float character_direction;
|
||||
}
|
||||
|
||||
protected DefaultShader m_shader;
|
||||
protected LogoParams m_logos[];
|
||||
protected uint m_last_create_time;
|
||||
|
||||
public void init(ScreenSaver ss)
|
||||
{
|
||||
@ -18,11 +40,13 @@ class FadingLogos : Mode
|
||||
m_shader.bind();
|
||||
}
|
||||
|
||||
public void display(ScreenSaver ss, int ms)
|
||||
public void display(ScreenSaver ss, uint ms)
|
||||
{
|
||||
mat4 view_matrix;
|
||||
update_logos(ss, ms);
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
mat4 view_matrix;
|
||||
view_matrix.make_identity();
|
||||
view_matrix.scale(ss.get_height() / cast(float)ss.get_width(), 1.0, 1.0);
|
||||
double scale = 0.35 * ss.get_width() * 1080.0 / (ss.get_height() * 1920.0);
|
||||
@ -54,4 +78,37 @@ class FadingLogos : Mode
|
||||
glUniform3fv(m_shader.color_idx, 1, color.ptr);
|
||||
logo.draw(logo.WIRE, word, character, m_shader.position_idx);
|
||||
}
|
||||
|
||||
protected void update_logos(ScreenSaver ss, uint ms)
|
||||
{
|
||||
const double max_scale = 0.35 * ss.get_aspect() * (1080.0 / 1920.0);
|
||||
if (m_last_create_time == 0 || (ms - m_last_create_time) >= CREATE_DELAY)
|
||||
{
|
||||
/* time to create a new logo */
|
||||
LogoParams lp = new LogoParams();
|
||||
lp.create_time = ms;
|
||||
lp.c_x = uniform(-0.8 * ss.get_aspect(), 0.8 * ss.get_aspect());
|
||||
lp.c_y = uniform(-0.8, 0.8);
|
||||
lp.rotation = uniform(0.0, math.PI * 2.0);
|
||||
lp.scale = uniform(0.2 * max_scale, max_scale);
|
||||
m_logos ~= lp;
|
||||
}
|
||||
|
||||
for (uint i = 0; i < m_logos.length; )
|
||||
{
|
||||
if ((ms - m_logos[i].create_time) >= (FADE_DELAY + FADE_TIME))
|
||||
{
|
||||
/* logo has expired */
|
||||
m_logos.remove(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((ms - m_logos[i].character_create_time) >= CHARACTER_FLY_TIME)
|
||||
{
|
||||
m_logos[i].character_direction = uniform(0.0, math.PI * 2.0);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user