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:
parent
f0b8e46ed5
commit
1fd4895298
@ -17,6 +17,7 @@ using namespace std;
|
|||||||
#define STRIDE_MULTIPLIER 1.0;
|
#define STRIDE_MULTIPLIER 1.0;
|
||||||
#define ZOOM 12.0
|
#define ZOOM 12.0
|
||||||
#define ORB_RADIUS 1.5
|
#define ORB_RADIUS 1.5
|
||||||
|
#define ORB_SPEED 6.0
|
||||||
|
|
||||||
LightBounceBox::LightBounceBox(LogoBox * lb,
|
LightBounceBox::LightBounceBox(LogoBox * lb,
|
||||||
float x, float y, float z,
|
float x, float y, float z,
|
||||||
@ -76,42 +77,42 @@ LightBounce::LightBounce(SSMain * _SSMain) : SSMode(_SSMain)
|
|||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
|
||||||
float box_stride = m_logoBox.getWidth() * STRIDE_MULTIPLIER;
|
float box_stride = m_logoBox.getWidth() * STRIDE_MULTIPLIER;
|
||||||
float half_size = SIZE * box_stride / 2.0;
|
m_half_size = SIZE * box_stride / 2.0;
|
||||||
float y = -half_size + box_stride / 2.0;
|
float y = -m_half_size + box_stride / 2.0;
|
||||||
int rot = false;
|
int rot = false;
|
||||||
for (int i = 0; i < SIZE; i++)
|
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++)
|
for (int j = 0; j < SIZE; j++)
|
||||||
{
|
{
|
||||||
// front
|
// front
|
||||||
LightBounceBox * box = new LightBounceBox(
|
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);
|
m_boxes.push_back(box);
|
||||||
// right
|
// right
|
||||||
box = new LightBounceBox(
|
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);
|
m_boxes.push_back(box);
|
||||||
// back
|
// back
|
||||||
box = new LightBounceBox(
|
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);
|
m_boxes.push_back(box);
|
||||||
// left
|
// left
|
||||||
box = new LightBounceBox(
|
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);
|
m_boxes.push_back(box);
|
||||||
// top
|
// top
|
||||||
box = new LightBounceBox(
|
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);
|
m_boxes.push_back(box);
|
||||||
// bottom
|
// bottom
|
||||||
box = new LightBounceBox(
|
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);
|
m_boxes.push_back(box);
|
||||||
|
|
||||||
@ -169,7 +170,10 @@ LightBounce::~LightBounce()
|
|||||||
/* called every time this screensaver mode should redraw the screen */
|
/* called every time this screensaver mode should redraw the screen */
|
||||||
void LightBounce::update()
|
void LightBounce::update()
|
||||||
{
|
{
|
||||||
|
static Uint32 last_elapsed = 0;
|
||||||
SSMode::update();
|
SSMode::update();
|
||||||
|
if (last_elapsed == 0)
|
||||||
|
last_elapsed = m_elapsed;
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
int numMonitors = m_SSMain->getNumMonitors();
|
int numMonitors = m_SSMain->getNumMonitors();
|
||||||
int width = m_SSMain->getWidth();
|
int width = m_SSMain->getWidth();
|
||||||
@ -182,6 +186,42 @@ void LightBounce::update()
|
|||||||
float viewer_z = viewer_dist * sin(angle);
|
float viewer_z = viewer_dist * sin(angle);
|
||||||
float viewer_y = SIZE * ZOOM * 2.0 / 3.0;
|
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++)
|
for (int i = 0, sz = m_boxes.size(); i < sz; i++)
|
||||||
{
|
{
|
||||||
m_boxes[i]->updateDist(viewer_x, viewer_y, viewer_z);
|
m_boxes[i]->updateDist(viewer_x, viewer_y, viewer_z);
|
||||||
@ -202,12 +242,15 @@ void LightBounce::update()
|
|||||||
{
|
{
|
||||||
if (m_boxes[i]->getDist() < orbDist && !drewOrb)
|
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);
|
glCallList(m_orb_dl);
|
||||||
|
glPopMatrix();
|
||||||
drewOrb = true;
|
drewOrb = true;
|
||||||
}
|
}
|
||||||
m_boxes[i]->draw();
|
m_boxes[i]->draw();
|
||||||
}
|
}
|
||||||
glTranslatef(m_orb_pos[0], m_orb_pos[1], m_orb_pos[2]);
|
|
||||||
}
|
}
|
||||||
SDL_GL_SwapBuffers();
|
SDL_GL_SwapBuffers();
|
||||||
|
last_elapsed = m_elapsed;
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,7 @@ protected:
|
|||||||
GLfloat m_orb_pos[3];
|
GLfloat m_orb_pos[3];
|
||||||
GLfloat m_orb_dir[3];
|
GLfloat m_orb_dir[3];
|
||||||
GLuint m_orb_dl;
|
GLuint m_orb_dl;
|
||||||
|
float m_half_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user