/* Author: Josh Holtrop * DornerWorks screensaver */ #include #include #include "LightBounce.h" #include #include using namespace std; #define SIZE 5 /* construct screensaver mode and do some basic OpenGL setup */ LightBounce::LightBounce(SSMain * _SSMain) : SSMode(_SSMain) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60.0, (double)m_SSMain->getWidth() / (double)m_SSMain->getHeight() / (double)m_SSMain->getNumMonitors(), 0.01, 1000.01); glMatrixMode(GL_MODELVIEW); LogoBox tmp; float box_stride = tmp.getWidth() * 1.2; float half_size = SIZE * box_stride / 2.0; float y = -half_size; int rot = false; for (int i = 0; i < SIZE; i++) { float x = -half_size; for (int j = 0; j < SIZE; j++) { LightBounce_Box * box = new LightBounce_Box; box->logoBox = new LogoBox(); box->x = x; box->y = y; box->z = -half_size; box->xr = 0; box->yr = 0; box->zr = rot ? 90.0 : 0; m_boxes.push_back(box); x += box_stride; rot = !rot; } y += box_stride; } } /* called every time this screensaver mode should redraw the screen */ void LightBounce::update() { SSMode::update(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); int numMonitors = m_SSMain->getNumMonitors(); int width = m_SSMain->getWidth(); int height = m_SSMain->getHeight(); for (int i = 0; i < numMonitors; i++) { glViewport(i*width/numMonitors, 0, width/numMonitors, height); glLoadIdentity(); gluLookAt(0, 0, SIZE * 5.0, 0, 0, 0, 0, 1, 0); glRotatef(m_elapsed/33.0f, 0, 1, 0); int sz = m_boxes.size(); for (int i = 0; i < sz; i++) { glPushMatrix(); glTranslatef(m_boxes[i]->x, m_boxes[i]->y, m_boxes[i]->z); glRotatef(m_boxes[i]->xr, 1, 0, 0); glRotatef(m_boxes[i]->yr, 0, 1, 0); glRotatef(m_boxes[i]->zr, 0, 0, 1); m_boxes[i]->logoBox->draw(); glPopMatrix(); } } SDL_GL_SwapBuffers(); }