From 82d72cab0688b11379271f81c303081311edd761 Mon Sep 17 00:00:00 2001 From: josh Date: Fri, 14 Nov 2008 03:52:28 +0000 Subject: [PATCH] fixed orb limit to take into account ORB_RADIUS git-svn-id: svn://anubis/dwscr/trunk@109 5bef9df8-b654-44bb-925b-0ff18baa8f8c --- ss/LightBounce.cc | 35 +++++++++++++++++------------------ ss/LightBounce.h | 1 + 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/ss/LightBounce.cc b/ss/LightBounce.cc index ca4466c..89705ae 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 6.0 +#define ORB_SPEED 12.0 LightBounceBox::LightBounceBox(LogoBox * lb, float x, float y, float z, @@ -156,6 +156,7 @@ LightBounce::LightBounce(SSMain * _SSMain) : SSMode(_SSMain) glEnable(GL_COLOR_MATERIAL); glColor4f(1, 1, 1, 0.3); #endif + m_last_elapsed = m_elapsed; } LightBounce::~LightBounce() @@ -170,10 +171,7 @@ LightBounce::~LightBounce() /* called every time this screensaver mode should redraw the screen */ void LightBounce::update() { - static Uint32 last_elapsed = 0; SSMode::update(); - if (last_elapsed == 0) - last_elapsed = m_elapsed; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); int numMonitors = m_SSMain->getNumMonitors(); int width = m_SSMain->getWidth(); @@ -187,39 +185,40 @@ void LightBounce::update() float viewer_y = SIZE * ZOOM * 2.0 / 3.0; /* update the orb position */ - float multiplier = ORB_SPEED * (m_elapsed - last_elapsed) / 1000.0; + float multiplier = ORB_SPEED * (m_elapsed - m_last_elapsed) / 1000.0; m_orb_pos[0] += multiplier * m_orb_dir[0]; m_orb_pos[1] += multiplier * m_orb_dir[1]; m_orb_pos[2] += multiplier * m_orb_dir[2]; - if (m_orb_pos[0] < -m_half_size) + float orb_limit = m_half_size - ORB_RADIUS; + if (m_orb_pos[0] < -orb_limit) { m_orb_dir[0] = -m_orb_dir[0]; - m_orb_pos[0] = -2 * m_half_size - m_orb_pos[0]; + m_orb_pos[0] = -2 * orb_limit - m_orb_pos[0]; } - else if (m_orb_pos[0] > m_half_size) + else if (m_orb_pos[0] > orb_limit) { m_orb_dir[0] = -m_orb_dir[0]; - m_orb_pos[0] = 2 * m_half_size - m_orb_pos[0]; + m_orb_pos[0] = 2 * orb_limit - m_orb_pos[0]; } - if (m_orb_pos[1] < -m_half_size) + if (m_orb_pos[1] < -orb_limit) { m_orb_dir[1] = -m_orb_dir[1]; - m_orb_pos[1] = -2 * m_half_size - m_orb_pos[1]; + m_orb_pos[1] = -2 * orb_limit - m_orb_pos[1]; } - else if (m_orb_pos[1] > m_half_size) + else if (m_orb_pos[1] > orb_limit) { m_orb_dir[1] = -m_orb_dir[1]; - m_orb_pos[1] = 2 * m_half_size - m_orb_pos[1]; + m_orb_pos[1] = 2 * orb_limit - m_orb_pos[1]; } - if (m_orb_pos[2] < -m_half_size) + if (m_orb_pos[2] < -orb_limit) { m_orb_dir[2] = -m_orb_dir[2]; - m_orb_pos[2] = -2 * m_half_size - m_orb_pos[2]; + m_orb_pos[2] = -2 * orb_limit - m_orb_pos[2]; } - else if (m_orb_pos[2] > m_half_size) + else if (m_orb_pos[2] > orb_limit) { m_orb_dir[2] = -m_orb_dir[2]; - m_orb_pos[2] = 2 * m_half_size - m_orb_pos[2]; + m_orb_pos[2] = 2 * orb_limit - m_orb_pos[2]; } for (int i = 0, sz = m_boxes.size(); i < sz; i++) @@ -252,5 +251,5 @@ void LightBounce::update() } } SDL_GL_SwapBuffers(); - last_elapsed = m_elapsed; + m_last_elapsed = m_elapsed; } diff --git a/ss/LightBounce.h b/ss/LightBounce.h index 7bf5d3e..f25b726 100644 --- a/ss/LightBounce.h +++ b/ss/LightBounce.h @@ -55,6 +55,7 @@ protected: GLfloat m_orb_dir[3]; GLuint m_orb_dl; float m_half_size; + Uint32 m_last_elapsed; }; #endif