*/
#ifdef STANDALONE
-# define DEFAULTS "*delay: 20000 \n" \
+# define DEFAULTS "*delay: 15000 \n" \
"*showFPS: False \n" \
"*wireframe: False \n"
#ifdef USE_GL
# define DEF_SPEED "0.5"
-# define DEF_BALLS "25"
-# define DEF_BALLSIZE "2.0"
+# define DEF_BALLS "20"
+# define DEF_BALLSIZE "3.0"
# define DEF_EXPLOSION "15.0"
# define DEF_DECAY "0.07"
# define DEF_MOMENTUM "0.6"
#define FALSE 0
/* camera */
-#define CAM_HEIGHT 100.0f
-#define CAMDISTANCE_MIN 20.0
+#define CAM_HEIGHT 80.0f
+#define CAMDISTANCE_MIN 35.0
#define CAMDISTANCE_MAX 150.0
#define CAMDISTANCE_SPEED 1.5
+#define LOOKAT_R 30.0
/* rendering the sphere */
#define MESH_SIZE 10
vectorf loc;
vectorf dir;
BOOL far;
- BOOL gone;
+ int gone;
} tri;
typedef struct {
GLXContext *glx_context;
GLuint listobjects;
GLuint gllists[3];
+ int list_polys[3];
Window window;
BOOL stop;
char *tex1;
(bman->balls[b].loc.x > 95.0) ||
(bman->balls[b].loc.z < -95.0) ||
(bman->balls[b].loc.z > 95.0)) {
- if (bman->balls[b].loc.y < -1000.0)
+ if (bman->balls[b].loc.y < -2000.0)
createball(&bman->balls[b]);
} else {
bman->balls[b].loc.y = bman->balls[b].radius + (bman->balls[b].radius - bman->balls[b].loc.y);
for (i=0; i<(tman->num_tri); i++) {
tman->tris[i].far = FALSE;
- tman->tris[i].gone = FALSE;
+ tman->tris[i].gone = 0;
pos = i * 3;
/* kopieer elke poly apart naar een tri structure */
copyvector(&tman->vertices[pos+0],&spherev[spherei[pos+0]]);
for (b=0;b<t->num_tri;b++) {
/* the exploded triangles disappear over time */
- if (rnd() < t->decay) { t->tris[b].gone = TRUE; }
+ if (rnd() < t->decay) {
+ if (t->tris[b].gone == 0)
+ t->tris[b].gone = 1;
+ }
/* apply gravity */
t->tris[b].dir.y -= (0.1f * speed);
/* apply movement */
cfg_balls = MAX(3,MIN(40,cfg_balls));
cfg_ballsize = MAX(1.0f,MIN(5.0f,cfg_ballsize));
cfg_explosion = MAX(0.0f,MIN(50.0f,cfg_explosion));
- cfg_decay = MAX(0.0f,MIN(1.0f,cfg_decay));
+ cfg_decay = MAX(0.02f,MIN(0.90f,cfg_decay));
cfg_momentum = MAX(0.0f,MIN(1.0f,cfg_momentum));
config->numballs = cfg_balls;
/*
* draw bottom
*/
-static void drawfilledbox(boxedstruct *boxed, int wire)
+static int drawfilledbox(boxedstruct *boxed, int wire)
{
/* draws texture filled box,
top is drawn using the entire texture,
the sides are drawn using the edge of the texture
*/
+ int polys = 0;
/* front */
glBegin(wire ? GL_LINE_LOOP : GL_QUADS);
glVertex3f(1.0,-1.0,1.0);
glTexCoord2f(0,1);
glVertex3f(-1.0,-1.0,1.0);
+ polys++;
/* rear */
glTexCoord2f(0,1);
glVertex3f(1.0,1.0,-1.0);
glVertex3f(-1.0,-1.0,-1.0);
glTexCoord2f(0,1);
glVertex3f(1.0,-1.0,-1.0);
+ polys++;
/* left */
glTexCoord2f(1,1);
glVertex3f(-1.0,1.0,1.0);
glVertex3f(-1.0,-1.0,-1.0);
glTexCoord2f(0,1);
glVertex3f(-1.0,1.0,-1.0);
+ polys++;
/* right */
glTexCoord2f(0,1);
glVertex3f(1.0,1.0,1.0);
glVertex3f(1.0,-1.0,-1.0);
glTexCoord2f(0,1);
glVertex3f(1.0,-1.0,1.0);
+ polys++;
/* top */
glTexCoord2f(0.0,0.0);
glVertex3f(-1.0,1.0,1.0);
glVertex3f(1.0,1.0,-1.0);
glTexCoord2f(1.0,0.0);
glVertex3f(1.0,1.0,1.0);
+ polys++;
/* bottom */
glTexCoord2f(0,0);
glVertex3f(-1.0,-1.0,1.0);
glVertex3f(1.0,-1.0,-1.0);
glTexCoord2f(1,0);
glVertex3f(1.0,-1.0,1.0);
+ polys++;
glEnd();
+
+ return polys;
}
/*
* Draw a box made of lines
*/
-static void drawbox(boxedstruct *boxed)
+static int drawbox(boxedstruct *boxed)
{
+ int polys = 0;
/* top */
glBegin(GL_LINE_STRIP);
glVertex3f(-1.0,1.0,1.0);
- glVertex3f(-1.0,1.0,-1.0);
- glVertex3f(1.0,1.0,-1.0);
- glVertex3f(1.0,1.0,1.0);
- glVertex3f(-1.0,1.0,1.0);
+ glVertex3f(-1.0,1.0,-1.0); polys++;
+ glVertex3f(1.0,1.0,-1.0); polys++;
+ glVertex3f(1.0,1.0,1.0); polys++;
+ glVertex3f(-1.0,1.0,1.0); polys++;
glEnd();
/* bottom */
glBegin(GL_LINE_STRIP);
glVertex3f(-1.0,-1.0,1.0);
- glVertex3f(1.0,-1.0,1.0);
- glVertex3f(1.0,-1.0,-1.0);
- glVertex3f(-1.0,-1.0,-1.0);
- glVertex3f(-1.0,-1.0,1.0);
+ glVertex3f(1.0,-1.0,1.0); polys++;
+ glVertex3f(1.0,-1.0,-1.0); polys++;
+ glVertex3f(-1.0,-1.0,-1.0); polys++;
+ glVertex3f(-1.0,-1.0,1.0); polys++;
glEnd();
/* connect top & bottom */
glBegin(GL_LINES);
glVertex3f(-1.0,1.0,1.0);
- glVertex3f(-1.0,-1.0,1.0);
+ glVertex3f(-1.0,-1.0,1.0); polys++;
glVertex3f(1.0,1.0,1.0);
- glVertex3f(1.0,-1.0,1.0);
+ glVertex3f(1.0,-1.0,1.0); polys++;
glVertex3f(1.0,1.0,-1.0);
- glVertex3f(1.0,-1.0,-1.0);
+ glVertex3f(1.0,-1.0,-1.0); polys++;
glVertex3f(-1.0,1.0,-1.0);
- glVertex3f(-1.0,-1.0,-1.0);
+ glVertex3f(-1.0,-1.0,-1.0); polys++;
glEnd();
+ return polys;
}
/*
* Draw ball
*/
-static void drawball(boxedstruct *gp, ball *b, int wire)
+static int drawball(boxedstruct *gp, ball *b, int wire)
{
+ int polys = 0;
int i,pos,cnt;
GLint *spherei = gp->spherei;
vectorf *spherev = gp->spherev;
glNormal3f(spherev[spherei[pos+0]].x,spherev[spherei[pos+0]].y,spherev[spherei[pos+0]].z);
glVertex3f(spherev[spherei[pos+0]].x,spherev[spherei[pos+0]].y,spherev[spherei[pos+0]].z);
glNormal3f(spherev[spherei[pos+1]].x,spherev[spherei[pos+1]].y,spherev[spherei[pos+1]].z);
+ gp->list_polys[GLL_BALL]++;
glVertex3f(spherev[spherei[pos+1]].x,spherev[spherei[pos+1]].y,spherev[spherei[pos+1]].z);
glNormal3f(spherev[spherei[pos+2]].x,spherev[spherei[pos+2]].y,spherev[spherei[pos+2]].z);
glVertex3f(spherev[spherei[pos+2]].x,spherev[spherei[pos+2]].y,spherev[spherei[pos+2]].z);
+ gp->list_polys[GLL_BALL]++;
glEnd();
}
glEndList();
gp->gllists[GLL_BALL] = 1;
} else {
glCallList(gp->listobjects + GLL_BALL);
+ polys += gp->list_polys[GLL_BALL];
}
glPopMatrix();
+ return polys;
}
/*
* Draw all triangles in triman
*/
-static void drawtriman(triman *t, int wire)
+static int drawtriman(triman *t, int wire)
{
+ int polys = 0;
int i,pos;
vectorf *spherev = t->vertices;
GLfloat col[3];
glMaterialfv(GL_FRONT, GL_EMISSION,col);
for (i=0; i<t->num_tri; i++) {
- if (t->tris[i].gone == TRUE) { continue; }
+ if (t->tris[i].gone > 3) { continue; }
+ if (t->tris[i].gone > 0) {
+ glColor3f(t->color.x,t->color.y,t->color.z);
+ col[0] = 1.0f;
+ col[1] = 1.0f;
+ col[2] = 1.0f;
+ glMaterialfv(GL_FRONT, GL_DIFFUSE, col);
+ col[0] *= 0.8;
+ col[1] *= 0.8;
+ col[2] *= 0.8;
+ glMaterialfv(GL_FRONT, GL_EMISSION,col);
+
+ pos = i*3;
+ glPushMatrix();
+ glTranslatef(t->tris[i].loc.x,t->tris[i].loc.y,t->tris[i].loc.z);
+ glBegin(wire ? GL_LINE_LOOP : GL_TRIANGLES);
+ glNormal3f(t->normals[i].x,t->normals[i].y,t->normals[i].z);
+ glVertex3f(spherev[pos+0].x,spherev[pos+0].y,spherev[pos+0].z);
+ glVertex3f(spherev[pos+1].x,spherev[pos+1].y,spherev[pos+1].z);
+ glVertex3f(spherev[pos+2].x,spherev[pos+2].y,spherev[pos+2].z);
+ polys++;
+ glEnd();
+ glPopMatrix();
+
+ glColor3f(t->color.x,t->color.y,t->color.z);
+ col[0] = t->color.x;
+ col[1] = t->color.y;
+ col[2] = t->color.z;
+ glMaterialfv(GL_FRONT, GL_DIFFUSE, col);
+ col[0] *= 0.3;
+ col[1] *= 0.3;
+ col[2] *= 0.3;
+ glMaterialfv(GL_FRONT, GL_EMISSION,col);
+
+ t->tris[i].gone++;
+ continue;
+ }
+
pos = i*3;
glPushMatrix();
glTranslatef(t->tris[i].loc.x,t->tris[i].loc.y,t->tris[i].loc.z);
glVertex3f(spherev[pos+0].x,spherev[pos+0].y,spherev[pos+0].z);
glVertex3f(spherev[pos+1].x,spherev[pos+1].y,spherev[pos+1].z);
glVertex3f(spherev[pos+2].x,spherev[pos+2].y,spherev[pos+2].z);
+ polys++;
glEnd();
glPopMatrix();
}
glPopMatrix();
+ return polys;
}
/*
* draw floor pattern
*/
-static void drawpattern(boxedstruct *gp)
+static int drawpattern(boxedstruct *gp)
{
+ int polys = 0;
if (!gp->gllists[GLL_PATTERN]) {
glNewList(gp->listobjects + GLL_PATTERN, GL_COMPILE);
glBegin(GL_LINE_STRIP);
glVertex3f(-25.0f, 0.0f, 35.0f);
- glVertex3f(-15.0f, 0.0f, 35.0f);
- glVertex3f(-5.0f, 0.0f, 25.0f);
- glVertex3f(5.0f, 0.0f, 25.0f);
- glVertex3f(15.0f, 0.0f, 35.0f);
- glVertex3f(25.0f, 0.0f, 35.0f);
- glVertex3f(35.0f, 0.0f, 25.0f);
- glVertex3f(35.0f, 0.0f, 15.0f);
- glVertex3f(25.0f, 0.0f, 5.0f);
- glVertex3f(25.0f, 0.0f, -5.0f);
- glVertex3f(35.0f, 0.0f, -15.0f);
- glVertex3f(35.0f, 0.0f, -25.0f);
- glVertex3f(25.0f, 0.0f, -35.0f);
- glVertex3f(15.0f, 0.0f,-35.0f);
- glVertex3f(5.0f, 0.0f, -25.0f);
- glVertex3f(-5.0f, 0.0f, -25.0f);
- glVertex3f(-15.0f, 0.0f,-35.0f);
- glVertex3f(-25.0f, 0.0f,-35.0f);
- glVertex3f(-35.0f, 0.0f, -25.0f);
- glVertex3f(-35.0f, 0.0f, -15.0f);
- glVertex3f(-25.0f, 0.0f, -5.0f);
- glVertex3f(-25.0f, 0.0f, 5.0f);
- glVertex3f(-35.0f, 0.0f, 15.0f);
- glVertex3f(-35.0f, 0.0f, 25.0f);
- glVertex3f(-25.0f, 0.0f, 35.0f);
+ glVertex3f(-15.0f, 0.0f, 35.0f); gp->list_polys[GLL_PATTERN]++;
+ glVertex3f(-5.0f, 0.0f, 25.0f); gp->list_polys[GLL_PATTERN]++;
+ glVertex3f(5.0f, 0.0f, 25.0f); gp->list_polys[GLL_PATTERN]++;
+ glVertex3f(15.0f, 0.0f, 35.0f); gp->list_polys[GLL_PATTERN]++;
+ glVertex3f(25.0f, 0.0f, 35.0f); gp->list_polys[GLL_PATTERN]++;
+ glVertex3f(35.0f, 0.0f, 25.0f); gp->list_polys[GLL_PATTERN]++;
+ glVertex3f(35.0f, 0.0f, 15.0f); gp->list_polys[GLL_PATTERN]++;
+ glVertex3f(25.0f, 0.0f, 5.0f); gp->list_polys[GLL_PATTERN]++;
+ glVertex3f(25.0f, 0.0f, -5.0f); gp->list_polys[GLL_PATTERN]++;
+ glVertex3f(35.0f, 0.0f, -15.0f); gp->list_polys[GLL_PATTERN]++;
+ glVertex3f(35.0f, 0.0f, -25.0f); gp->list_polys[GLL_PATTERN]++;
+ glVertex3f(25.0f, 0.0f, -35.0f); gp->list_polys[GLL_PATTERN]++;
+ glVertex3f(15.0f, 0.0f,-35.0f); gp->list_polys[GLL_PATTERN]++;
+ glVertex3f(5.0f, 0.0f, -25.0f); gp->list_polys[GLL_PATTERN]++;
+ glVertex3f(-5.0f, 0.0f, -25.0f); gp->list_polys[GLL_PATTERN]++;
+ glVertex3f(-15.0f, 0.0f,-35.0f); gp->list_polys[GLL_PATTERN]++;
+ glVertex3f(-25.0f, 0.0f,-35.0f); gp->list_polys[GLL_PATTERN]++;
+ glVertex3f(-35.0f, 0.0f, -25.0f); gp->list_polys[GLL_PATTERN]++;
+ glVertex3f(-35.0f, 0.0f, -15.0f); gp->list_polys[GLL_PATTERN]++;
+ glVertex3f(-25.0f, 0.0f, -5.0f); gp->list_polys[GLL_PATTERN]++;
+ glVertex3f(-25.0f, 0.0f, 5.0f); gp->list_polys[GLL_PATTERN]++;
+ glVertex3f(-35.0f, 0.0f, 15.0f); gp->list_polys[GLL_PATTERN]++;
+ glVertex3f(-35.0f, 0.0f, 25.0f); gp->list_polys[GLL_PATTERN]++;
+ glVertex3f(-25.0f, 0.0f, 35.0f); gp->list_polys[GLL_PATTERN]++;
glEnd();
glBegin(GL_LINE_STRIP);
glVertex3f(-5.0f, 0.0f, 15.0f);
- glVertex3f(5.0f, 0.0f, 15.0f);
- glVertex3f(15.0f, 0.0f, 5.0f);
- glVertex3f(15.0f, 0.0f, -5.0f);
- glVertex3f(5.0f, 0.0f, -15.0f);
- glVertex3f(-5.0f, 0.0f, -15.0f);
- glVertex3f(-15.0f, 0.0f, -5.0f);
- glVertex3f(-15.0f, 0.0f, 5.0f);
- glVertex3f(-5.0f, 0.0f, 15.0f);
+ glVertex3f(5.0f, 0.0f, 15.0f); gp->list_polys[GLL_PATTERN]++;
+ glVertex3f(15.0f, 0.0f, 5.0f); gp->list_polys[GLL_PATTERN]++;
+ glVertex3f(15.0f, 0.0f, -5.0f); gp->list_polys[GLL_PATTERN]++;
+ glVertex3f(5.0f, 0.0f, -15.0f); gp->list_polys[GLL_PATTERN]++;
+ glVertex3f(-5.0f, 0.0f, -15.0f); gp->list_polys[GLL_PATTERN]++;
+ glVertex3f(-15.0f, 0.0f, -5.0f); gp->list_polys[GLL_PATTERN]++;
+ glVertex3f(-15.0f, 0.0f, 5.0f); gp->list_polys[GLL_PATTERN]++;
+ glVertex3f(-5.0f, 0.0f, 15.0f); gp->list_polys[GLL_PATTERN]++;
glEnd();
glEndList();
gp->gllists[GLL_PATTERN] = 1;
} else {
glCallList(gp->listobjects + GLL_PATTERN);
- }
+ polys += gp->list_polys[GLL_PATTERN];
+ }
+ return polys;
}
{
boxedstruct *gp = &boxed[MI_SCREEN(mi)];
int wire = MI_IS_WIREFRAME (mi);
- vectorf v1;
- GLfloat dcam;
+ vectorf v1,v2;
+ GLfloat r;
int dx, dz;
int i;
GLfloat l1_diffuse[] = {0.5, 0.5, 0.5, 1.0};
GLfloat l1_position[] = {0.0, 1.0, 0.0, 0.0}; /* w = 0 -> directional light */
+ mi->polygon_count = 0;
+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
+ glRotatef(current_device_rotation(), 0, 0, 1);
+
gp->tic += 0.01f;
gp->camtic += 0.01f + 0.01f * sin(gp->tic * speed);
/* rotate camera around (0,0,0), looking at (0,0,0), up is (0,1,0) */
- dcam = CAMDISTANCE_MIN + (CAMDISTANCE_MAX - CAMDISTANCE_MIN) + (CAMDISTANCE_MAX - CAMDISTANCE_MIN)*cos((gp->camtic/CAMDISTANCE_SPEED) * speed);
- v1.x = dcam * sin((gp->camtic/gp->cam_x_speed) * speed);
- v1.z = dcam * cos((gp->camtic/gp->cam_z_speed) * speed);
+ r = CAMDISTANCE_MIN + (CAMDISTANCE_MAX - CAMDISTANCE_MIN) + (CAMDISTANCE_MAX - CAMDISTANCE_MIN)*cos((gp->camtic/CAMDISTANCE_SPEED) * speed);
+ v1.x = r * sin((gp->camtic/gp->cam_x_speed) * speed);
+ v1.z = r * cos((gp->camtic/gp->cam_x_speed) * speed);
v1.y = CAM_HEIGHT * sin((gp->camtic/gp->cam_y_speed) * speed) + 1.02 * CAM_HEIGHT;
- gluLookAt(v1.x,v1.y,v1.z,0.0,0.0,0.0,0.0,1.0,0.0);
+
+ v2.x = LOOKAT_R * sin((gp->camtic/(gp->cam_x_speed * 5.0f)) * speed);
+ v2.z = LOOKAT_R * cos((gp->camtic/(gp->cam_x_speed * 5.0f)) * speed);
+ v2.y = (CAM_HEIGHT * sin((gp->camtic/gp->cam_y_speed) * speed) + 1.02 * CAM_HEIGHT)/10.0;
+
+ gluLookAt(v1.x,v1.y,v1.z,v2.x,v2.y,v2.x,0.0,1.0,0.0);
if (!wire) {
glLightfv(GL_LIGHT0, GL_AMBIENT, l0_ambient);
glColor3f(1.0,1.0,1.0);
glScalef(20.0,0.25,20.0);
glTranslatef(0.0,2.0,0.0);
- drawfilledbox(gp, wire);
+ mi->polygon_count += drawfilledbox(gp, wire);
glPopMatrix();
glDisable(GL_TEXTURE_2D);
glColor3f(0.2,0.5,0.2);
glScalef(20.0,20.0,0.25);
glTranslatef(0.0,1.0,81.0);
- drawbox(gp);
+ mi->polygon_count += drawbox(gp);
glPopMatrix();
glPushMatrix();
glColor3f(0.2,0.5,0.2);
glScalef(20.0,20.0,0.25);
glTranslatef(0.0,1.0,-81.0);
- drawbox(gp);
+ mi->polygon_count += drawbox(gp);
glPopMatrix();
glPushMatrix();
glColor3f(0.2,0.5,0.2);
glScalef(.25,20.0,20.0);
glTranslatef(-81.0,1.0,0.0);
- drawbox(gp);
+ mi->polygon_count += drawbox(gp);
glPopMatrix();
glPushMatrix();
glColor3f(0.2,0.5,0.2);
glScalef(.25,20.0,20.0);
glTranslatef(81.0,1.0,0.0);
- drawbox(gp);
+ mi->polygon_count += drawbox(gp);
glPopMatrix();
if (!wire) {
updatetris(&gp->tman[i]);
}
glDisable(GL_CULL_FACE);
- drawtriman(&gp->tman[i], wire);
+ mi->polygon_count += drawtriman(&gp->tman[i], wire);
if (!wire) glEnable(GL_CULL_FACE);
} else {
- drawball(gp, &gp->bman.balls[i], wire);
+ mi->polygon_count += drawball(gp, &gp->bman.balls[i], wire);
}
}
glShadeModel(GL_SMOOTH);
glClearDepth(1.0);
- glClearColor(0.0,0.05,0.1,0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
/* Load configuration */
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
clear_gl_error();
+#if 0
i = gluBuild2DMipmaps(GL_TEXTURE_2D, 3, 256, 256,
GL_RGB, GL_UNSIGNED_BYTE, gp->tex1);
if (i)
exit (1);
}
check_gl_error("mipmapping");
+#else
+ glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB, 256, 256, 0,
+ GL_RGB, GL_UNSIGNED_BYTE,
+ gp->tex1);
+ check_gl_error("texture");
+#endif
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);