orb moving and bouncing off walls now

git-svn-id: svn://anubis/dwscr/trunk@108 5bef9df8-b654-44bb-925b-0ff18baa8f8c
This commit is contained in:
josh 2008-11-14 01:48:39 +00:00
parent f0b8e46ed5
commit 1fd4895298
2 changed files with 54 additions and 10 deletions

View File

@ -17,6 +17,7 @@ using namespace std;
#define STRIDE_MULTIPLIER 1.0;
#define ZOOM 12.0
#define ORB_RADIUS 1.5
#define ORB_SPEED 6.0
LightBounceBox::LightBounceBox(LogoBox * lb,
float x, float y, float z,
@ -76,42 +77,42 @@ LightBounce::LightBounce(SSMain * _SSMain) : SSMode(_SSMain)
glMatrixMode(GL_MODELVIEW);
float box_stride = m_logoBox.getWidth() * STRIDE_MULTIPLIER;
float half_size = SIZE * box_stride / 2.0;
float y = -half_size + box_stride / 2.0;
m_half_size = SIZE * box_stride / 2.0;
float y = -m_half_size + box_stride / 2.0;
int rot = false;
for (int i = 0; i < SIZE; i++)
{
float x = -half_size + box_stride / 2.0;
float x = -m_half_size + box_stride / 2.0;
for (int j = 0; j < SIZE; j++)
{
// front
LightBounceBox * box = new LightBounceBox(
&m_logoBox, x, y, -half_size, 0, 180.0, rot ? 90.0 : 0
&m_logoBox, x, y, -m_half_size, 0, 180.0, rot ? 90.0 : 0
);
m_boxes.push_back(box);
// right
box = new LightBounceBox(
&m_logoBox, half_size, y, x, 0, 90.0, rot ? 0 : 90.0
&m_logoBox, m_half_size, y, x, 0, 90.0, rot ? 0 : 90.0
);
m_boxes.push_back(box);
// back
box = new LightBounceBox(
&m_logoBox, x, y, half_size, 0, 0, rot ? 90.0 : 0
&m_logoBox, x, y, m_half_size, 0, 0, rot ? 90.0 : 0
);
m_boxes.push_back(box);
// left
box = new LightBounceBox(
&m_logoBox, -half_size, y, x, 0, 270.0, rot ? 0 : 90.0
&m_logoBox, -m_half_size, y, x, 0, 270.0, rot ? 0 : 90.0
);
m_boxes.push_back(box);
// top
box = new LightBounceBox(
&m_logoBox, x, half_size, y, 270, 0, rot ? 0 : 90.0
&m_logoBox, x, m_half_size, y, 270, 0, rot ? 0 : 90.0
);
m_boxes.push_back(box);
// bottom
box = new LightBounceBox(
&m_logoBox, x, -half_size, y, 90, 0, rot ? 0 : 90.0
&m_logoBox, x, -m_half_size, y, 90, 0, rot ? 0 : 90.0
);
m_boxes.push_back(box);
@ -169,7 +170,10 @@ 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();
@ -182,6 +186,42 @@ void LightBounce::update()
float viewer_z = viewer_dist * sin(angle);
float viewer_y = SIZE * ZOOM * 2.0 / 3.0;
/* update the orb position */
float multiplier = ORB_SPEED * (m_elapsed - 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)
{
m_orb_dir[0] = -m_orb_dir[0];
m_orb_pos[0] = -2 * m_half_size - m_orb_pos[0];
}
else if (m_orb_pos[0] > m_half_size)
{
m_orb_dir[0] = -m_orb_dir[0];
m_orb_pos[0] = 2 * m_half_size - m_orb_pos[0];
}
if (m_orb_pos[1] < -m_half_size)
{
m_orb_dir[1] = -m_orb_dir[1];
m_orb_pos[1] = -2 * m_half_size - m_orb_pos[1];
}
else if (m_orb_pos[1] > m_half_size)
{
m_orb_dir[1] = -m_orb_dir[1];
m_orb_pos[1] = 2 * m_half_size - m_orb_pos[1];
}
if (m_orb_pos[2] < -m_half_size)
{
m_orb_dir[2] = -m_orb_dir[2];
m_orb_pos[2] = -2 * m_half_size - m_orb_pos[2];
}
else if (m_orb_pos[2] > m_half_size)
{
m_orb_dir[2] = -m_orb_dir[2];
m_orb_pos[2] = 2 * m_half_size - m_orb_pos[2];
}
for (int i = 0, sz = m_boxes.size(); i < sz; i++)
{
m_boxes[i]->updateDist(viewer_x, viewer_y, viewer_z);
@ -202,12 +242,15 @@ 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();
drewOrb = true;
}
m_boxes[i]->draw();
}
glTranslatef(m_orb_pos[0], m_orb_pos[1], m_orb_pos[2]);
}
SDL_GL_SwapBuffers();
last_elapsed = m_elapsed;
}

View File

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