diff --git a/ss/LightBounce.cc b/ss/LightBounce.cc index 89705ae..073cb0f 100644 --- a/ss/LightBounce.cc +++ b/ss/LightBounce.cc @@ -17,7 +17,7 @@ using namespace std; #define STRIDE_MULTIPLIER 1.0; #define ZOOM 12.0 #define ORB_RADIUS 1.5 -#define ORB_SPEED 12.0 +#define ORB_SPEED 20.0 LightBounceBox::LightBounceBox(LogoBox * lb, float x, float y, float z, @@ -34,11 +34,11 @@ LightBounceBox::LightBounceBox(LogoBox * lb, m_dl = glGenLists(1); glNewList(m_dl, GL_COMPILE); glPushMatrix(); - glTranslatef(x, y, z); - glRotatef(xr, 1, 0, 0); - glRotatef(yr, 0, 1, 0); - glRotatef(zr, 0, 0, 1); - lb->draw(); + glTranslatef(x, y, z); + glRotatef(xr, 1, 0, 0); + glRotatef(yr, 0, 1, 0); + glRotatef(zr, 0, 0, 1); + lb->draw(); glPopMatrix(); glEndList(); } @@ -144,19 +144,12 @@ LightBounce::LightBounce(SSMain * _SSMain) : SSMode(_SSMain) glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - GLuint tex; - glGenTextures(1, &tex); + glGenTextures(1, &m_alpha_texture); glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, tex); - GLfloat pixels[] = {1, 1, 1, 0.5}; - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_FLOAT, pixels); + glBindTexture(GL_TEXTURE_2D, m_alpha_texture); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); -#if 0 - glEnable(GL_COLOR_MATERIAL); - glColor4f(1, 1, 1, 0.3); -#endif - m_last_elapsed = m_elapsed; + m_last_elapsed = 0; } LightBounce::~LightBounce() @@ -166,12 +159,16 @@ LightBounce::~LightBounce() int sz = m_boxes.size(); for (int i = 0; i < sz; i++) delete m_boxes[i]; + glDeleteTextures(1, &m_alpha_texture); + glDeleteLists(m_orb_dl, 1); } /* called every time this screensaver mode should redraw the screen */ void LightBounce::update() { SSMode::update(); + if (m_last_elapsed == 0) + m_last_elapsed = m_elapsed; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); int numMonitors = m_SSMain->getNumMonitors(); int width = m_SSMain->getWidth(); @@ -182,7 +179,7 @@ void LightBounce::update() double viewer_dist = SIZE * ZOOM; float viewer_x = viewer_dist * cos(angle); float viewer_z = viewer_dist * sin(angle); - float viewer_y = SIZE * ZOOM * 2.0 / 3.0; + float viewer_y = SIZE * ZOOM * 0.2; /* update the orb position */ float multiplier = ORB_SPEED * (m_elapsed - m_last_elapsed) / 1000.0; @@ -241,12 +238,29 @@ void LightBounce::update() { if (m_boxes[i]->getDist() < orbDist && !drewOrb) { - glPushMatrix(); - glTranslatef(m_orb_pos[0], m_orb_pos[1], m_orb_pos[2]); - glCallList(m_orb_dl); - glPopMatrix(); + glPushAttrib(GL_ENABLE_BIT); + glDisable(GL_TEXTURE_2D); + glPushMatrix(); + glTranslatef(m_orb_pos[0], m_orb_pos[1], m_orb_pos[2]); + glCallList(m_orb_dl); + glPopMatrix(); + glPopAttrib(); drewOrb = true; } + float dx = m_orb_pos[0] - m_boxes[i]->getX(); + float dy = m_orb_pos[1] - m_boxes[i]->getY(); + float dz = m_orb_pos[2] - m_boxes[i]->getZ(); +// float orb_box_dist = sqrtf((dx * dx) + (dy * dy) + (dz * dz)); + float orb_box_dist = (dx * dx) + (dy * dy) + (dz * dz); + orb_box_dist /= m_half_size * m_half_size * 1.5; +// orb_box_dist *= M_PI; + if (orb_box_dist > 1) + orb_box_dist = 1; + float alpha = 1 - orb_box_dist; +// alpha = (alpha + 1.0) / 2.0; + GLfloat pixels[] = {1, 1, 1, alpha}; + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, + GL_RGBA, GL_FLOAT, pixels); m_boxes[i]->draw(); } } diff --git a/ss/LightBounce.h b/ss/LightBounce.h index f25b726..b1e1767 100644 --- a/ss/LightBounce.h +++ b/ss/LightBounce.h @@ -22,6 +22,9 @@ public: void draw() { glCallList(m_dl); } void updateDist(float x, float y, float z); float getDist() { return dist; } + float getX() { return x; } + float getY() { return y; } + float getZ() { return z; } private: float x; @@ -56,6 +59,7 @@ protected: GLuint m_orb_dl; float m_half_size; Uint32 m_last_elapsed; + GLuint m_alpha_texture; }; #endif