create new stars when old ones pass

This commit is contained in:
Josh Holtrop 2011-03-24 14:21:33 -04:00
parent 0b6c19cc0e
commit 57fc49ea54
2 changed files with 12 additions and 1 deletions

View File

@ -16,7 +16,9 @@ Starfield::Starfield(GnomeScreensaver & gs)
m_last_ticks = ticks;
srand(time(NULL) + getpid());
for (int i = 0; i < NUM_STARS; i++)
newStar(i, ticks - (uint64_t) (i * FLYBY_TICKS / (double)NUM_STARS));
newStar(NUM_STARS - i - 1,
ticks - (uint64_t) (i * FLYBY_TICKS / (double)NUM_STARS));
m_star_idx = 0;
}
Starfield::~Starfield()
@ -43,6 +45,14 @@ bool Starfield::expose (GnomeScreensaver & gs)
glPopMatrix();
}
while ((m_stars[m_star_idx].create_time + FLYBY_TICKS) <= ticks)
{
newStar(m_star_idx, ticks);
m_star_idx++;
if (m_star_idx >= NUM_STARS)
m_star_idx = 0;
}
m_last_ticks = gs.getTicks();
return true;

View File

@ -31,6 +31,7 @@ class Starfield : public Mode
protected:
LogoBox m_logobox;
uint64_t m_last_ticks;
int m_star_idx;
Star m_stars[NUM_STARS];
void getRandomAxis(float (*axis)[3]);
void newStar(int idx, uint64_t ticks);