transparency based on orb distance working, need new orb and light source

git-svn-id: svn://anubis/dwscr/trunk@110 5bef9df8-b654-44bb-925b-0ff18baa8f8c
This commit is contained in:
josh 2008-11-14 04:22:12 +00:00
parent 82d72cab06
commit 943e1dade3
2 changed files with 39 additions and 21 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 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();
}
}

View File

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