Tunnel mode: abstract out addRing()

This commit is contained in:
Josh Holtrop 2011-10-12 12:37:30 -04:00
parent 14b92e35af
commit 2cab647bcb
2 changed files with 36 additions and 15 deletions

View File

@ -17,6 +17,7 @@ using namespace std;
#define RING_RADIUS 18
#define BREAKOFF_DIST 80
#define RING_LAYER_DIST 10
#define XLATE_RATE 0.02
Tunnel::Tunnel()
{
@ -30,6 +31,11 @@ Tunnel::~Tunnel()
bool Tunnel::expose (GnomeScreensaver & gs)
{
if (m_last_ticks == 0)
m_last_ticks = gs.getTicks();
uint64_t ticks = gs.getTicks();
int elapsed = ticks - m_last_ticks;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
for (list<LBStruct>::const_iterator it = m_logos.begin();
@ -47,9 +53,28 @@ bool Tunnel::expose (GnomeScreensaver & gs)
glPopMatrix();
}
m_last_ticks = ticks;
return true;
}
void Tunnel::addRing()
{
for (int j = 0; j < N_LOGOS_PER_RING; j++)
{
float zrot = ((j + m_ring_rot_idx) & 0x3) * 90.0;
float trot = j * 360.0 / N_LOGOS_PER_RING;
LBStruct lbs = {
m_offset,
zrot,
trot,
{0, 0, 1}
};
m_logos.push_back(lbs);
}
m_ring_rot_idx++;
}
bool Tunnel::configure (GnomeScreensaver & gs)
{
glMatrixMode(GL_PROJECTION);
@ -63,22 +88,15 @@ bool Tunnel::configure (GnomeScreensaver & gs)
glViewport(0, 0, gs.getWidth(), gs.getHeight());
for (int i = 0; i < N_INITIAL_LAYERS; i++)
for (int i = 0; i <= N_INITIAL_LAYERS; i++)
{
for (int j = 0; j < N_LOGOS_PER_RING; j++)
{
float zrot = ((j + i) & 0x3) * 90.0;
float trot = j * 360.0 / N_LOGOS_PER_RING;
LBStruct lbs = {
(N_INITIAL_LAYERS - i) * RING_LAYER_DIST,
zrot,
trot,
{0, 0, 1}
};
m_logos.push_back(lbs);
}
m_offset = (N_INITIAL_LAYERS - i) * RING_LAYER_DIST,
addRing();
}
m_offset = 0.0;
m_last_ring_offset = 0.0;
return true;
}

View File

@ -17,16 +17,19 @@ class Tunnel : public Mode
bool configure (GnomeScreensaver & gs);
bool update (GnomeScreensaver & gs);
typedef struct {
float offset;
double offset;
float zrot;
float trot;
float spin_axis[3];
} LBStruct;
protected:
void addRing();
LogoBox m_logobox;
uint64_t m_last_ticks;
std::list<LBStruct> m_logos;
float m_offset;
double m_offset;
double m_last_ring_offset;
unsigned int m_ring_rot_idx;
};
#endif /* TUNNEL_H */