X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fglx%2Fboxed.c;h=e875f0fa2a3a43d07e29956ae1efa5137e2e3ba7;hb=3f438031d610c7e15fd33876a879b97e290e05fb;hp=cdf04a52a80744b01c39315fd7fab1c80c5ea83a;hpb=4cecfc89e5e889c7232693897c06168fb378bd5c;p=xscreensaver diff --git a/hacks/glx/boxed.c b/hacks/glx/boxed.c index cdf04a52..e875f0fa 100644 --- a/hacks/glx/boxed.c +++ b/hacks/glx/boxed.c @@ -1,8 +1,7 @@ /* thebox --- 3D bouncing balls that explode */ -#if !defined( lint ) && !defined( SABER ) +#if 0 static const char sccsid[] = "@(#)boxed.c 0.9 01/09/26 xlockmore"; - #endif /*- @@ -36,17 +35,20 @@ static const char sccsid[] = "@(#)boxed.c 0.9 01/09/26 xlockmore"; */ #ifdef STANDALONE -# define PROGCLASS "boxed" -# define HACK_INIT init_boxed -# define HACK_DRAW draw_boxed -# define HACK_RESHAPE reshape_boxed -# define boxed_opts xlockmore_opts -# define DEFAULTS "*delay: 20000 \n" \ - "*showFPS: False \n" \ - -# include "xlockmore.h" /* from the xscreensaver distribution */ +# define PROGCLASS "boxed" +# define HACK_INIT init_boxed +# define HACK_DRAW draw_boxed +# define HACK_RESHAPE reshape_boxed +# define boxed_opts xlockmore_opts + +# define DEF_SPEED "0.5" +# define DEFAULTS "*delay: 20000 \n" \ + "*showFPS: False \n" \ + "*wireframe: False \n" + +# include "xlockmore.h" /* from the xscreensaver distribution */ #else /* !STANDALONE */ -# include "xlock.h" /* from the xlockmore distribution */ +# include "xlock.h" /* from the xlockmore distribution */ #endif /* !STANDALONE */ #ifdef USE_GL @@ -57,23 +59,18 @@ static const char sccsid[] = "@(#)boxed.c 0.9 01/09/26 xlockmore"; #undef rnd #define rnd() (frand(1.0)) -/* #define DEF_PLANETARY "False" +GLfloat speed; /* jwz -- overall speed factor applied to all motion */ -static int planetary; static XrmOptionDescRec opts[] = { - {"-planetary", ".gears.planetary", XrmoptionNoArg, (caddr_t) "true" }, - {"+planetary", ".gears.planetary", XrmoptionNoArg, (caddr_t) "false" }, + {"-speed", ".boxed.speed", XrmoptionSepArg, 0}, }; static argtype vars[] = { - {(caddr_t *) &planetary, "planetary", "Planetary", DEF_PLANETARY, t_Bool}, + {&speed, "speed", "Speed", DEF_SPEED, t_Float}, }; -*/ -/* ModeSpecOpts boxed_opts = {countof(opts), opts, countof(vars), vars, NULL}; */ - -ModeSpecOpt boxed_opts = {0, NULL, 0, NULL, NULL}; +ModeSpecOpt boxed_opts = {countof(opts), opts, countof(vars), vars, NULL}; #ifdef USE_MODULES @@ -91,6 +88,7 @@ ModStruct boxed_description = { /* rendering defines */ + /* box size */ #define BOX_SIZE 20.0f @@ -101,7 +99,7 @@ ModStruct boxed_description = { #define CAMDISTANCE_SPEED 1.5 /* rendering the sphere */ -#define MESH_SIZE 5 +#define MESH_SIZE 10 #define SPHERE_VERTICES (2+MESH_SIZE*MESH_SIZE*2) #define SPHERE_INDICES ((MESH_SIZE*4 + MESH_SIZE*4*(MESH_SIZE-1))*3) @@ -343,14 +341,15 @@ static void generatesphere(void) * create fresh ball */ -void createball(ball *newball) { +void createball(ball *newball) +{ float r=0.0f,g=0.0f,b=0.0f; newball->loc.x = 5-10*rnd(); newball->loc.y = 35+20*rnd(); newball->loc.z = 5-10*rnd(); - newball->dir.x = 0.5f-rnd(); + newball->dir.x = (0.5f-rnd()) * speed; newball->dir.y = 0.0; - newball->dir.z = 0.5-rnd(); + newball->dir.z = (0.5-rnd()) * speed; newball->offside = 0; newball->bounced = FALSE; newball->radius = BALLSIZE; @@ -364,15 +363,18 @@ void createball(ball *newball) { /* Update position of each ball */ -void updateballs(ballman *bman) { +void updateballs(ballman *bman) +{ register int b,j; vectorf dvect,richting,relspeed,influence; GLfloat squaredist; for (b=0;bnum_balls;b++) { + GLfloat gravity = 0.15f * speed; + /* apply gravity */ - bman->balls[b].dir.y -= 0.15f; + bman->balls[b].dir.y -= gravity; /* apply movement */ addvectors(&bman->balls[b].loc,&bman->balls[b].loc,&bman->balls[b].dir); /* boundary check */ @@ -458,7 +460,8 @@ void updateballs(ballman *bman) { * explode ball into triangles */ -void createtrisfromball(triman* tman, vectorf *spherev, GLint *spherei, int ind_num, ball *b) { +void createtrisfromball(triman* tman, vectorf *spherev, GLint *spherei, int ind_num, ball *b) +{ int pos; float explosion; float scale; @@ -512,9 +515,9 @@ void createtrisfromball(triman* tman, vectorf *spherev, GLint *spherei, int ind_ /* bereken nieuwe richting */ scalevector(&tman->tris[i].dir,&avgdir,explosion); - dvect.x = 0.1f - 0.2f*rnd(); - dvect.y = 0.15f - 0.3f*rnd(); - dvect.z = 0.1f - 0.2f*rnd(); + dvect.x = (0.1f - 0.2f*rnd()); + dvect.y = (0.15f - 0.3f*rnd()); + dvect.z = (0.1f - 0.2f*rnd()); addvectors(&tman->tris[i].dir,&tman->tris[i].dir,&dvect); } } @@ -524,13 +527,14 @@ void createtrisfromball(triman* tman, vectorf *spherev, GLint *spherei, int ind_ * update position of each tri */ -void updatetris(triman *t) { +void updatetris(triman *t) +{ int b; GLfloat xd,zd; for (b=0;bnum_tri;b++) { /* apply gravity */ - t->tris[b].dir.y -= 0.1f; + t->tris[b].dir.y -= (0.1f * speed); /* apply movement */ addvectors(&t->tris[b].loc,&t->tris[b].loc,&t->tris[b].dir); /* boundary check */ @@ -596,7 +600,8 @@ void updatetris(triman *t) { /* * free memory allocated by a tri manager */ -void freetris(triman *t) { +void freetris(triman *t) +{ if (!t) return; if (t->tris) free(t->tris); if (t->vertices) free(t->vertices); @@ -612,7 +617,8 @@ void freetris(triman *t) { /* *load defaults in config structure */ -void setdefaultconfig(boxed_config *config) { +void setdefaultconfig(boxed_config *config) +{ config->numballs = NUMBALLS; config->textures = TRUE; config->transparent = FALSE; @@ -625,7 +631,7 @@ void setdefaultconfig(boxed_config *config) { /* * draw bottom */ -static void drawfilledbox(boxedstruct *boxed) +static void drawfilledbox(boxedstruct *boxed, int wire) { /* draws texture filled box, top is drawn using the entire texture, @@ -633,7 +639,7 @@ static void drawfilledbox(boxedstruct *boxed) */ /* front */ - glBegin(GL_QUADS); + glBegin(wire ? GL_LINE_LOOP : GL_QUADS); glTexCoord2f(0,1); glVertex3f(-1.0,1.0,1.0); glTexCoord2f(1,1); @@ -730,7 +736,7 @@ static void drawbox(boxedstruct *boxed) /* * Draw ball */ -static void drawball(boxedstruct *gp, ball *b) +static void drawball(boxedstruct *gp, ball *b, int wire) { int i,pos,cnt; GLint *spherei = gp->spherei; @@ -756,7 +762,7 @@ static void drawball(boxedstruct *gp, ball *b) cnt = SPHERE_INDICES/3; for (i=0; ivertices; @@ -799,7 +805,7 @@ static void drawtriman(triman *t) pos = i*3; glPushMatrix(); glTranslatef(t->tris[i].loc.x,t->tris[i].loc.y,t->tris[i].loc.z); - glBegin(GL_TRIANGLES); + 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); @@ -873,6 +879,7 @@ static void drawpattern(boxedstruct *boxed) static void draw(ModeInfo * mi) { boxedstruct *gp = &boxed[MI_SCREEN(mi)]; + int wire = MI_IS_WIREFRAME (mi); vectorf v1; GLfloat dcam; int dx, dz; @@ -897,29 +904,31 @@ static void draw(ModeInfo * mi) gp->tic += 0.01f; /* 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->tic/CAMDISTANCE_SPEED); - v1.x = dcam * sin(gp->tic/gp->cam_x_speed); - v1.z = dcam * cos(gp->tic/gp->cam_z_speed); - v1.y = CAM_HEIGHT * sin(gp->tic/gp->cam_y_speed) + 1.02 * CAM_HEIGHT; + dcam = CAMDISTANCE_MIN + (CAMDISTANCE_MAX - CAMDISTANCE_MIN) + (CAMDISTANCE_MAX - CAMDISTANCE_MIN)*cos((gp->tic/CAMDISTANCE_SPEED) * speed); + v1.x = dcam * sin((gp->tic/gp->cam_x_speed) * speed); + v1.z = dcam * cos((gp->tic/gp->cam_z_speed) * speed); + v1.y = CAM_HEIGHT * sin((gp->tic/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); - glLightfv(GL_LIGHT0, GL_AMBIENT, l0_ambient); - glLightfv(GL_LIGHT0, GL_DIFFUSE, l0_diffuse); - glLightfv(GL_LIGHT0, GL_SPECULAR, l0_specular); - glLightfv(GL_LIGHT0, GL_POSITION, l0_position); - glLightfv(GL_LIGHT1, GL_AMBIENT, l1_ambient); - glLightfv(GL_LIGHT1, GL_DIFFUSE, l1_diffuse); - glLightfv(GL_LIGHT1, GL_SPECULAR, l1_specular); - glLightfv(GL_LIGHT1, GL_POSITION, l1_position); - glEnable(GL_LIGHT0); - glEnable(GL_LIGHT1); + if (!wire) { + glLightfv(GL_LIGHT0, GL_AMBIENT, l0_ambient); + glLightfv(GL_LIGHT0, GL_DIFFUSE, l0_diffuse); + glLightfv(GL_LIGHT0, GL_SPECULAR, l0_specular); + glLightfv(GL_LIGHT0, GL_POSITION, l0_position); + glLightfv(GL_LIGHT1, GL_AMBIENT, l1_ambient); + glLightfv(GL_LIGHT1, GL_DIFFUSE, l1_diffuse); + glLightfv(GL_LIGHT1, GL_SPECULAR, l1_specular); + glLightfv(GL_LIGHT1, GL_POSITION, l1_position); + glEnable(GL_LIGHT0); + glEnable(GL_LIGHT1); - glFrontFace(GL_CW); + glFrontFace(GL_CW); - glMaterialfv(GL_FRONT, GL_SPECULAR, black); - glMaterialfv(GL_FRONT, GL_EMISSION, lblue); - glMaterialfv(GL_FRONT,GL_AMBIENT,black); - glMaterialf(GL_FRONT, GL_SHININESS, 5.0); + glMaterialfv(GL_FRONT, GL_SPECULAR, black); + glMaterialfv(GL_FRONT, GL_EMISSION, lblue); + glMaterialfv(GL_FRONT,GL_AMBIENT,black); + glMaterialf(GL_FRONT, GL_SHININESS, 5.0); + } /* draw ground grid */ @@ -938,12 +947,12 @@ static void draw(ModeInfo * mi) /* Set drawing mode for the boxes */ glEnable(GL_DEPTH_TEST); - glEnable(GL_TEXTURE_2D); + if (!wire) glEnable(GL_TEXTURE_2D); glPushMatrix(); glColor3f(1.0,1.0,1.0); glScalef(20.0,0.25,20.0); glTranslatef(0.0,2.0,0.0); - drawfilledbox(gp); + drawfilledbox(gp, wire); glPopMatrix(); glDisable(GL_TEXTURE_2D); @@ -975,10 +984,12 @@ static void draw(ModeInfo * mi) drawbox(gp); glPopMatrix(); - glEnable(GL_LIGHTING); + if (!wire) { + glEnable(GL_LIGHTING); - glMaterialfv(GL_FRONT, GL_DIFFUSE, dgray); - glMaterialfv(GL_FRONT, GL_EMISSION, black); /* turn it off before painting the balls */ + glMaterialfv(GL_FRONT, GL_DIFFUSE, dgray); + glMaterialfv(GL_FRONT, GL_EMISSION, black); /* turn it off before painting the balls */ + } /* move the balls and shrapnel */ updateballs(&gp->bman); @@ -996,10 +1007,10 @@ static void draw(ModeInfo * mi) updatetris(&gp->tman[i]); } glDisable(GL_CULL_FACE); - drawtriman(&gp->tman[i]); - glEnable(GL_CULL_FACE); + drawtriman(&gp->tman[i], wire); + if (!wire) glEnable(GL_CULL_FACE); } else { - drawball(gp, &gp->bman.balls[i]); + drawball(gp, &gp->bman.balls[i], wire); } } @@ -1030,6 +1041,7 @@ static void pinit(ModeInfo * mi) { boxedstruct *gp = &boxed[MI_SCREEN(mi)]; + int wire = MI_IS_WIREFRAME (mi); ballman *bman; int i,texpixels; char *texpixeldata; @@ -1064,8 +1076,10 @@ pinit(ModeInfo * mi) generatesphere(); - glEnable(GL_CULL_FACE); - glEnable(GL_LIGHTING); + if (!wire) { + glEnable(GL_CULL_FACE); + glEnable(GL_LIGHTING); + } /* define cam path */ gp->cam_x_speed = 1.0f/((float)gp->config.camspeed/50.0 + rnd()*((float)gp->config.camspeed/50.0)); @@ -1092,7 +1106,7 @@ pinit(ModeInfo * mi) GL_RGB, GL_UNSIGNED_BYTE, gp->tex1); if (i) { - const char *s = gluErrorString (i); + const char *s = (char *) gluErrorString (i); fprintf (stderr, "%s: error mipmapping texture: %s\n", progname, (s ? s : "(unknown)")); exit (1);