initialize stars array

This commit is contained in:
Josh Holtrop committed 2011-03-24 13:44:08 -04:00
1 parent 605483b41c
commit d034c2d667
3 files changed
+25 -7

No files matched your search

+1 -1
View File
@@ -35,7 +35,7 @@ int main (int argc, char *argv[])
GnomeScreensaver gs(&argc, &argv, configure, expose, update, 12);
Mode *modes[] = {
new Starfield(),
new Starfield(gs),
new Spin(),
new Flip()
};
+12 -5
View File
@@ -10,10 +10,13 @@
#include "Starfield.h"
Starfield::Starfield()
Starfield::Starfield(GnomeScreensaver & gs)
{
m_last_ticks = 0;
uint64_t ticks = gs.getTicks();
m_last_ticks = ticks;
srand(time(NULL) + getpid());
for (int i = 0; i < NUM_STARS; i++)
newStar(i, ticks);
}
Starfield::~Starfield()
@@ -22,8 +25,7 @@ Starfield::~Starfield()
bool Starfield::expose (GnomeScreensaver & gs)
{
if (m_last_ticks == 0)
m_last_ticks = gs.getTicks();
uint64_t ticks = gs.getTicks();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, gs.getWidth(), gs.getHeight());
@@ -42,7 +44,7 @@ bool Starfield::configure (GnomeScreensaver & gs)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, gs.getAspectRatio(), 0.01, 1000.0);
gluPerspective(60.0, gs.getAspectRatio(), 0.01, MAX_STAR_DIST);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
@@ -65,3 +67,8 @@ void Starfield::getRandomAxis(float (*axis)[3])
(*axis)[2] = cos(beta);
}
void Starfield::newStar(int idx, uint64_t ticks)
{
m_stars[idx].create_time = ticks;
getRandomAxis(&m_stars[idx].axis);
}
+12 -1
View File
@@ -6,18 +6,29 @@
#include "Mode.h"
#include "GnomeScreensaver.h"
#define NUM_STARS 1000
#define MAX_STAR_DIST 1000
class Starfield : public Mode
{
public:
Starfield();
Starfield(GnomeScreensaver & gs);
~Starfield();
bool expose (GnomeScreensaver & gs);
bool configure (GnomeScreensaver & gs);
bool update (GnomeScreensaver & gs);
class Star
{
public:
float axis[3];
uint64_t create_time;
};
protected:
LogoBox m_logobox;
uint64_t m_last_ticks;
Star m_stars[NUM_STARS];
void getRandomAxis(float (*axis)[3]);
void newStar(int idx, uint64_t ticks);
};
#endif /* STARFIELD_H */