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:
parent
82d72cab06
commit
943e1dade3
@ -17,7 +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 12.0
|
#define ORB_SPEED 20.0
|
||||||
|
|
||||||
LightBounceBox::LightBounceBox(LogoBox * lb,
|
LightBounceBox::LightBounceBox(LogoBox * lb,
|
||||||
float x, float y, float z,
|
float x, float y, float z,
|
||||||
@ -34,11 +34,11 @@ LightBounceBox::LightBounceBox(LogoBox * lb,
|
|||||||
m_dl = glGenLists(1);
|
m_dl = glGenLists(1);
|
||||||
glNewList(m_dl, GL_COMPILE);
|
glNewList(m_dl, GL_COMPILE);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glTranslatef(x, y, z);
|
glTranslatef(x, y, z);
|
||||||
glRotatef(xr, 1, 0, 0);
|
glRotatef(xr, 1, 0, 0);
|
||||||
glRotatef(yr, 0, 1, 0);
|
glRotatef(yr, 0, 1, 0);
|
||||||
glRotatef(zr, 0, 0, 1);
|
glRotatef(zr, 0, 0, 1);
|
||||||
lb->draw();
|
lb->draw();
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
glEndList();
|
glEndList();
|
||||||
}
|
}
|
||||||
@ -144,19 +144,12 @@ LightBounce::LightBounce(SSMain * _SSMain) : SSMode(_SSMain)
|
|||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
GLuint tex;
|
glGenTextures(1, &m_alpha_texture);
|
||||||
glGenTextures(1, &tex);
|
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
glBindTexture(GL_TEXTURE_2D, tex);
|
glBindTexture(GL_TEXTURE_2D, m_alpha_texture);
|
||||||
GLfloat pixels[] = {1, 1, 1, 0.5};
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_FLOAT, pixels);
|
|
||||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||||
|
|
||||||
#if 0
|
m_last_elapsed = 0;
|
||||||
glEnable(GL_COLOR_MATERIAL);
|
|
||||||
glColor4f(1, 1, 1, 0.3);
|
|
||||||
#endif
|
|
||||||
m_last_elapsed = m_elapsed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LightBounce::~LightBounce()
|
LightBounce::~LightBounce()
|
||||||
@ -166,12 +159,16 @@ LightBounce::~LightBounce()
|
|||||||
int sz = m_boxes.size();
|
int sz = m_boxes.size();
|
||||||
for (int i = 0; i < sz; i++)
|
for (int i = 0; i < sz; i++)
|
||||||
delete m_boxes[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 */
|
/* called every time this screensaver mode should redraw the screen */
|
||||||
void LightBounce::update()
|
void LightBounce::update()
|
||||||
{
|
{
|
||||||
SSMode::update();
|
SSMode::update();
|
||||||
|
if (m_last_elapsed == 0)
|
||||||
|
m_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,7 +179,7 @@ void LightBounce::update()
|
|||||||
double viewer_dist = SIZE * ZOOM;
|
double viewer_dist = SIZE * ZOOM;
|
||||||
float viewer_x = viewer_dist * cos(angle);
|
float viewer_x = viewer_dist * cos(angle);
|
||||||
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 * 0.2;
|
||||||
|
|
||||||
/* update the orb position */
|
/* update the orb position */
|
||||||
float multiplier = ORB_SPEED * (m_elapsed - m_last_elapsed) / 1000.0;
|
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)
|
if (m_boxes[i]->getDist() < orbDist && !drewOrb)
|
||||||
{
|
{
|
||||||
glPushMatrix();
|
glPushAttrib(GL_ENABLE_BIT);
|
||||||
glTranslatef(m_orb_pos[0], m_orb_pos[1], m_orb_pos[2]);
|
glDisable(GL_TEXTURE_2D);
|
||||||
glCallList(m_orb_dl);
|
glPushMatrix();
|
||||||
glPopMatrix();
|
glTranslatef(m_orb_pos[0], m_orb_pos[1], m_orb_pos[2]);
|
||||||
|
glCallList(m_orb_dl);
|
||||||
|
glPopMatrix();
|
||||||
|
glPopAttrib();
|
||||||
drewOrb = true;
|
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();
|
m_boxes[i]->draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,9 @@ public:
|
|||||||
void draw() { glCallList(m_dl); }
|
void draw() { glCallList(m_dl); }
|
||||||
void updateDist(float x, float y, float z);
|
void updateDist(float x, float y, float z);
|
||||||
float getDist() { return dist; }
|
float getDist() { return dist; }
|
||||||
|
float getX() { return x; }
|
||||||
|
float getY() { return y; }
|
||||||
|
float getZ() { return z; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float x;
|
float x;
|
||||||
@ -56,6 +59,7 @@ protected:
|
|||||||
GLuint m_orb_dl;
|
GLuint m_orb_dl;
|
||||||
float m_half_size;
|
float m_half_size;
|
||||||
Uint32 m_last_elapsed;
|
Uint32 m_last_elapsed;
|
||||||
|
GLuint m_alpha_texture;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user