diff --git a/ss/LightBounce.cc b/ss/LightBounce.cc index 5885f43..3dd1550 100644 --- a/ss/LightBounce.cc +++ b/ss/LightBounce.cc @@ -7,6 +7,7 @@ #include #include "LightBounce.h" +#include "math.h" #include #include #include @@ -15,6 +16,7 @@ using namespace std; #define SIZE 5 #define STRIDE_MULTIPLIER 1.0; #define ZOOM 12.0 +#define ORB_RADIUS 1.5 LightBounceBox::LightBounceBox(LogoBox * lb, float x, float y, float z, @@ -119,7 +121,25 @@ LightBounce::LightBounce(SSMain * _SSMain) : SSMode(_SSMain) y += box_stride; } + /* Set up the orb */ + m_orb_pos[0] = m_orb_pos[1] = m_orb_pos[2] = 0.0f; + double theta = M_2_PI * ((double)rand() / (double)RAND_MAX); + double gamma = M_PI * ((double)rand() / (double)RAND_MAX); + m_orb_dir[0] = cos(theta) * sin(gamma); + m_orb_dir[1] = sin(theta) * sin(gamma); + m_orb_dir[2] = cos(gamma); + + m_orb_dl = glGenLists(1); + glNewList(m_orb_dl, GL_COMPILE); + GLfloat mat[] = {1, 1, 0.2, 0.8}; + glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat); + GLUquadric * quad = gluNewQuadric(); + gluQuadricNormals(quad, GL_TRUE); + gluSphere(quad, ORB_RADIUS, 16, 8); + glEndList(); + glPushAttrib(GL_POLYGON_BIT); /* store CULL_FACE settings */ + glPushAttrib(GL_ENABLE_BIT); /* store current GL_BLEND setting */ glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -139,7 +159,8 @@ LightBounce::LightBounce(SSMain * _SSMain) : SSMode(_SSMain) LightBounce::~LightBounce() { - glPopAttrib(); + glPopAttrib(); /* restore old GL_BLEND setting */ + glPopAttrib(); /* restore old CULL_FACE settings */ int sz = m_boxes.size(); for (int i = 0; i < sz; i++) delete m_boxes[i]; @@ -176,6 +197,8 @@ void LightBounce::update() { m_boxes[i]->draw(); } + glTranslatef(m_orb_pos[0], m_orb_pos[1], m_orb_pos[2]); + glCallList(m_orb_dl); } SDL_GL_SwapBuffers(); } diff --git a/ss/LightBounce.h b/ss/LightBounce.h index 64c17c4..35a002c 100644 --- a/ss/LightBounce.h +++ b/ss/LightBounce.h @@ -51,6 +51,9 @@ protected: LightBounceBoxComparator m_comparator; vector m_boxes; LogoBox m_logoBox; + GLfloat m_orb_pos[3]; + GLfloat m_orb_dir[3]; + GLuint m_orb_dl; }; #endif