first wall of LightBox done
git-svn-id: svn://anubis/dwscr/trunk@92 5bef9df8-b654-44bb-925b-0ff18baa8f8c
This commit is contained in:
parent
4ed97f09f6
commit
126b75fb56
1
Makefile
1
Makefile
@ -11,6 +11,7 @@ export CXXFLAGS := -O2 -Wall
|
||||
export CPPFLAGS
|
||||
ifdef DEBUG
|
||||
CPPFLAGS += -DDEBUG
|
||||
CPPFLAGS += -g
|
||||
endif
|
||||
ifdef WITHOUT_ODE
|
||||
CPPFLAGS += -DWITHOUT_ODE
|
||||
|
@ -8,8 +8,11 @@
|
||||
#include "LightBounce.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
|
||||
#define SIZE 5
|
||||
|
||||
/* construct screensaver mode and do some basic OpenGL setup */
|
||||
LightBounce::LightBounce(SSMain * _SSMain) : SSMode(_SSMain)
|
||||
{
|
||||
@ -22,13 +25,38 @@ LightBounce::LightBounce(SSMain * _SSMain) : SSMode(_SSMain)
|
||||
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);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
int numMonitors = m_SSMain->getNumMonitors();
|
||||
int width = m_SSMain->getWidth();
|
||||
int height = m_SSMain->getHeight();
|
||||
@ -36,9 +64,21 @@ void LightBounce::update()
|
||||
{
|
||||
glViewport(i*width/numMonitors, 0, width/numMonitors, height);
|
||||
glLoadIdentity();
|
||||
gluLookAt(0, 0, 12, 0, 0, 0, 0, 1, 0);
|
||||
gluLookAt(0, 0, SIZE * 5.0, 0, 0, 0, 0, 1, 0);
|
||||
glRotatef(m_elapsed/33.0f, 0, 1, 0);
|
||||
m_logoBox.draw();
|
||||
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();
|
||||
}
|
||||
|
@ -9,6 +9,20 @@
|
||||
#include "SSMain.h"
|
||||
#include "SSMode.h"
|
||||
#include "LogoBox.h"
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
LogoBox * logoBox;
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
float xr;
|
||||
float yr;
|
||||
float zr;
|
||||
float dist;
|
||||
} LightBounce_Box;
|
||||
|
||||
class LightBounce : public SSMode
|
||||
{
|
||||
@ -16,7 +30,7 @@ public:
|
||||
LightBounce(SSMain * _SSMain);
|
||||
void update();
|
||||
protected:
|
||||
LogoBox m_logoBox;
|
||||
vector<LightBounce_Box *> m_boxes;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -137,7 +137,7 @@ void TumblingLogos::update()
|
||||
for (unsigned int i = 0; i < delta / 2; i++)
|
||||
worldStep();
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
int numMonitors = m_SSMain->getNumMonitors();
|
||||
int width = m_SSMain->getWidth();
|
||||
int height = m_SSMain->getHeight();
|
||||
@ -190,36 +190,36 @@ void TumblingLogos::update()
|
||||
void TumblingLogos_collide_callback(void * data, dGeomID o1, dGeomID o2)
|
||||
{
|
||||
TumblingLogos * tl = (TumblingLogos *) data;
|
||||
static dContact contact[4];
|
||||
dBodyID b1 = dGeomGetBody(o1);
|
||||
dBodyID b2 = dGeomGetBody(o2);
|
||||
if (b1 && b2 && dAreConnected(b1, b2))
|
||||
return;
|
||||
int num = dCollide(o1, o2, 4, &contact[0].geom, sizeof(dContact));
|
||||
int i;
|
||||
for (i = 0; i < num; i++)
|
||||
{
|
||||
contact[i].surface.mode =
|
||||
dContactSlip1 | dContactSlip2 | dContactBounce |
|
||||
dContactSoftERP | dContactSoftCFM | dContactApprox1;
|
||||
contact[i].surface.mu = 0.5;
|
||||
contact[i].surface.slip1 = 0.0;
|
||||
contact[i].surface.slip2 = 0.0;
|
||||
contact[i].surface.soft_erp = 0.8;
|
||||
contact[i].surface.soft_cfm = 0.01;
|
||||
contact[i].surface.bounce = 0.4;
|
||||
dJointID joint = dJointCreateContact(tl->m_world,
|
||||
tl->m_contactJointGroup, contact + i);
|
||||
dJointAttach(joint, b1, b2);
|
||||
}
|
||||
static dContact contact[4];
|
||||
dBodyID b1 = dGeomGetBody(o1);
|
||||
dBodyID b2 = dGeomGetBody(o2);
|
||||
if (b1 && b2 && dAreConnected(b1, b2))
|
||||
return;
|
||||
int num = dCollide(o1, o2, 4, &contact[0].geom, sizeof(dContact));
|
||||
int i;
|
||||
for (i = 0; i < num; i++)
|
||||
{
|
||||
contact[i].surface.mode =
|
||||
dContactSlip1 | dContactSlip2 | dContactBounce |
|
||||
dContactSoftERP | dContactSoftCFM | dContactApprox1;
|
||||
contact[i].surface.mu = 0.5;
|
||||
contact[i].surface.slip1 = 0.0;
|
||||
contact[i].surface.slip2 = 0.0;
|
||||
contact[i].surface.soft_erp = 0.8;
|
||||
contact[i].surface.soft_cfm = 0.01;
|
||||
contact[i].surface.bounce = 0.4;
|
||||
dJointID joint = dJointCreateContact(tl->m_world,
|
||||
tl->m_contactJointGroup, contact + i);
|
||||
dJointAttach(joint, b1, b2);
|
||||
}
|
||||
}
|
||||
|
||||
/* invokes ODE to do physics on our world */
|
||||
void TumblingLogos::worldStep()
|
||||
{
|
||||
dSpaceCollide(m_space, this, TumblingLogos_collide_callback);
|
||||
dWorldQuickStep(m_world, WORLD_STEP);
|
||||
dJointGroupEmpty(m_contactJointGroup);
|
||||
dSpaceCollide(m_space, this, TumblingLogos_collide_callback);
|
||||
dWorldQuickStep(m_world, WORLD_STEP);
|
||||
dJointGroupEmpty(m_contactJointGroup);
|
||||
}
|
||||
|
||||
/* randomly chooses a gravity direction */
|
||||
|
Loading…
x
Reference in New Issue
Block a user