fixed orb limit to take into account ORB_RADIUS

git-svn-id: svn://anubis/dwscr/trunk@109 5bef9df8-b654-44bb-925b-0ff18baa8f8c
This commit is contained in:
josh 2008-11-14 03:52:28 +00:00
parent 1fd4895298
commit 82d72cab06
2 changed files with 18 additions and 18 deletions

View File

@ -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;
}

View File

@ -55,6 +55,7 @@ protected:
GLfloat m_orb_dir[3];
GLuint m_orb_dl;
float m_half_size;
Uint32 m_last_elapsed;
};
#endif