initialize stars; currently behind camera :(

This commit is contained in:
Josh Holtrop 2011-03-24 14:03:51 -04:00
parent d034c2d667
commit c10caad2f9
2 changed files with 20 additions and 5 deletions

View File

@ -16,7 +16,7 @@ Starfield::Starfield(GnomeScreensaver & gs)
m_last_ticks = ticks; m_last_ticks = ticks;
srand(time(NULL) + getpid()); srand(time(NULL) + getpid());
for (int i = 0; i < NUM_STARS; i++) for (int i = 0; i < NUM_STARS; i++)
newStar(i, ticks); newStar(i, ticks + (uint64_t) (i * FLYBY_TICKS / (double)NUM_STARS));
} }
Starfield::~Starfield() Starfield::~Starfield()
@ -30,10 +30,17 @@ bool Starfield::expose (GnomeScreensaver & gs)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, gs.getWidth(), gs.getHeight()); glViewport(0, 0, gs.getWidth(), gs.getHeight());
glPushMatrix(); for (int i = 0; i < NUM_STARS; i++)
glTranslatef(0, 0, -30); {
m_logobox.draw(); glPushMatrix();
glPopMatrix(); glTranslatef(m_stars[i].x, m_stars[i].y,
(ticks - m_stars[i].create_time)
* (FLYBY_TICKS / (double)MAX_STAR_DIST));
glRotatef(m_stars[i].rot,
m_stars[i].axis[0], m_stars[i].axis[1], m_stars[i].axis[2]);
m_logobox.draw();
glPopMatrix();
}
m_last_ticks = gs.getTicks(); m_last_ticks = gs.getTicks();
@ -71,4 +78,7 @@ void Starfield::newStar(int idx, uint64_t ticks)
{ {
m_stars[idx].create_time = ticks; m_stars[idx].create_time = ticks;
getRandomAxis(&m_stars[idx].axis); getRandomAxis(&m_stars[idx].axis);
m_stars[idx].x = ((rand() / (double)RAND_MAX) - 0.5) * STAR_MAXX * 2;
m_stars[idx].y = ((rand() / (double)RAND_MAX) - 0.5) * STAR_MAXY * 2;
m_stars[idx].rot = rand() / (double)RAND_MAX * 360.0;
} }

View File

@ -8,6 +8,9 @@
#define NUM_STARS 1000 #define NUM_STARS 1000
#define MAX_STAR_DIST 1000 #define MAX_STAR_DIST 1000
#define FLYBY_TICKS 3000
#define STAR_MAXX 500
#define STAR_MAXY 400
class Starfield : public Mode class Starfield : public Mode
{ {
@ -22,6 +25,8 @@ class Starfield : public Mode
public: public:
float axis[3]; float axis[3];
uint64_t create_time; uint64_t create_time;
float x, y;
float rot;
}; };
protected: protected:
LogoBox m_logobox; LogoBox m_logobox;