From 2cab647bcb88fd96c8a1e0b42d4ae858bb785928 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Wed, 12 Oct 2011 12:37:30 -0400 Subject: [PATCH] Tunnel mode: abstract out addRing() --- modes/Tunnel.cc | 44 +++++++++++++++++++++++++++++++------------- modes/Tunnel.h | 7 +++++-- 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/modes/Tunnel.cc b/modes/Tunnel.cc index 4a00fc2..1357846 100644 --- a/modes/Tunnel.cc +++ b/modes/Tunnel.cc @@ -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::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; } diff --git a/modes/Tunnel.h b/modes/Tunnel.h index f1519a9..0ba1021 100644 --- a/modes/Tunnel.h +++ b/modes/Tunnel.h @@ -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 m_logos; - float m_offset; + double m_offset; + double m_last_ring_offset; + unsigned int m_ring_rot_idx; }; #endif /* TUNNEL_H */