X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?p=xscreensaver;a=blobdiff_plain;f=hacks%2Fglx%2Fboxed.c;h=42f68c1c1970ffc4d86f1785063465f2c421dd94;hp=9f7706c6c9b03f86fa5b0061262fc94db7c877f7;hb=6b1c86cf395f59389e4ece4ea8f4bea2c332745b;hpb=0d6b320def9180cf907ceaed56b23a972a11b757 diff --git a/hacks/glx/boxed.c b/hacks/glx/boxed.c index 9f7706c6..42f68c1c 100644 --- a/hacks/glx/boxed.c +++ b/hacks/glx/boxed.c @@ -26,9 +26,12 @@ static const char sccsid[] = "@(#)boxed.c 0.9 01/09/26 xlockmore"; * * 2005: opts work. added options -balls, -ballsize, -explosion * + * 2006: opts work. added option -decay + * + * 2008: opts work. added option -momentum + * */ -#include #include "boxed.h" /* @@ -38,37 +41,37 @@ 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 DEF_SPEED "0.5" -# define DEF_BALLS "25" -# define DEF_BALLSIZE "2.0" -# define DEF_EXPLOSION "25.0f" # define DEFAULTS "*delay: 20000 \n" \ "*showFPS: False \n" \ "*wireframe: False \n" +# define refresh_boxed 0 +# define boxed_handle_event 0 # include "xlockmore.h" /* from the xscreensaver distribution */ #else /* !STANDALONE */ # include "xlock.h" /* from the xlockmore distribution */ #endif /* !STANDALONE */ #ifdef USE_GL -#include + +# define DEF_SPEED "0.5" +# define DEF_BALLS "25" +# define DEF_BALLSIZE "2.0" +# define DEF_EXPLOSION "15.0" +# define DEF_DECAY "0.07" +# define DEF_MOMENTUM "0.6" #undef countof #define countof(x) (int)(sizeof((x))/sizeof((*x))) #undef rnd #define rnd() (frand(1.0)) -GLfloat speed; /* jwz -- overall speed factor applied to all motion */ -int cfg_balls; -GLfloat cfg_ballsize; -GLfloat cfg_explosion; +static GLfloat speed; /* jwz -- overall speed factor applied to all motion */ +static int cfg_balls; +static GLfloat cfg_ballsize; +static GLfloat cfg_explosion; +static GLfloat cfg_decay; +static GLfloat cfg_momentum; static XrmOptionDescRec opts[] = { @@ -76,16 +79,20 @@ static XrmOptionDescRec opts[] = { {"-balls", ".boxed.balls", XrmoptionSepArg, 0}, {"-ballsize", ".boxed.ballsize", XrmoptionSepArg, 0}, {"-explosion", ".boxed.explosion", XrmoptionSepArg, 0}, + {"-decay", ".boxed.decay", XrmoptionSepArg, 0}, + {"-momentum", ".boxed.momentum", XrmoptionSepArg, 0}, }; static argtype vars[] = { {&speed, "speed", "Speed", DEF_SPEED, t_Float}, {&cfg_balls, "balls", "Balls", DEF_BALLS, t_Int}, {&cfg_ballsize, "ballsize", "Ball Size", DEF_BALLSIZE, t_Float}, - {&cfg_explosion, "explosion", "Exlosion", DEF_BALLSIZE, t_Float}, + {&cfg_explosion, "explosion", "Explosion", DEF_EXPLOSION, t_Float}, + {&cfg_decay, "decay", "Explosion Decay", DEF_DECAY, t_Float}, + {&cfg_momentum, "momentum", "Explosion Momentum", DEF_MOMENTUM, t_Float}, }; -ModeSpecOpt boxed_opts = {countof(opts), opts, countof(vars), vars, NULL}; +ENTRYPOINT ModeSpecOpt boxed_opts = {countof(opts), opts, countof(vars), vars, NULL}; #ifdef USE_MODULES @@ -145,6 +152,7 @@ typedef struct { vectorf loc; vectorf dir; BOOL far; + BOOL gone; } tri; typedef struct { @@ -152,6 +160,8 @@ typedef struct { int lifetime; float scalefac; float explosion; + float decay; + float momentum; vectorf color; tri *tris; GLint *indices; @@ -163,6 +173,8 @@ typedef struct { int numballs; float ballsize; float explosion; + float decay; + float momentum; BOOL textures; BOOL transparent; float camspeed; @@ -258,6 +270,12 @@ squaremagnitude(vectorf * v) return v->x * v->x + v->y * v->y + v->z * v->z; } +static inline GLfloat +squaremagnitudehorz(vectorf * v) +{ + return v->x * v->x + v->z * v->z; +} + /* @@ -266,7 +284,7 @@ squaremagnitude(vectorf * v) * Input: */ -static void generatesphere(void) +static void generatesphere(boxedstruct *gp) { float dj = M_PI/(MESH_SIZE+1.0f); float di = M_PI/MESH_SIZE; @@ -282,8 +300,8 @@ static void generatesphere(void) * vertices 0 and 1 are the north and south poles */ - spherei = boxed->spherei; - spherev = boxed->spherev; + spherei = gp->spherei; + spherev = gp->spherev; spherev[0].x = 0.0f; spherev[0].y =1.0f; spherev[0].z = 0.0f; spherev[1].x = 0.0f; spherev[1].y =-1.0f; spherev[1].z = 0.0f; @@ -346,7 +364,7 @@ static void generatesphere(void) * create fresh ball */ -void createball(ball *newball) +static void createball(ball *newball) { float r=0.0f,g=0.0f,b=0.0f; newball->loc.x = 5-10*rnd(); @@ -368,7 +386,7 @@ void createball(ball *newball) /* Update position of each ball */ -void updateballs(ballman *bman) +static void updateballs(ballman *bman) { register int b,j; vectorf dvect,richting,relspeed,influence; @@ -398,7 +416,10 @@ void updateballs(ballman *bman) scalevector(&bman->balls[b].dir,&bman->balls[b].dir,0.80f); if (squaremagnitude(&bman->balls[b].dir) < 0.08f) { createball(&bman->balls[b]); - } + } + if (squaremagnitudehorz(&bman->balls[b].dir) < 0.005f) { + createball(&bman->balls[b]); + } } } @@ -465,17 +486,19 @@ void updateballs(ballman *bman) * explode ball into triangles */ -void createtrisfromball(triman* tman, vectorf *spherev, GLint *spherei, int ind_num, ball *b) +static void createtrisfromball(triman* tman, vectorf *spherev, GLint *spherei, int ind_num, ball *b) { int pos; float explosion; + float momentum; float scale; register int i; - vectorf avgdir,dvect; + vectorf avgdir,dvect,mvect; tman->scalefac = b->radius; copyvector(&tman->color,&b->color); explosion = 1.0f + tman->explosion * 2.0 * rnd(); + momentum = tman->momentum; tman->num_tri = ind_num/3; @@ -487,6 +510,7 @@ void createtrisfromball(triman* tman, vectorf *spherev, GLint *spherei, int ind_ for (i=0; i<(tman->num_tri); i++) { tman->tris[i].far = FALSE; + tman->tris[i].gone = FALSE; pos = i * 3; /* kopieer elke poly apart naar een tri structure */ copyvector(&tman->vertices[pos+0],&spherev[spherei[pos+0]]); @@ -534,6 +558,12 @@ void createtrisfromball(triman* tman, vectorf *spherev, GLint *spherei, int ind_ dvect.y = (0.15f - 0.3f*rnd()); dvect.z = (0.1f - 0.2f*rnd()); addvectors(&tman->tris[i].dir,&tman->tris[i].dir,&dvect); + + /* add ball's momentum to each piece of the exploded ball */ + mvect.x = b->dir.x * momentum; + mvect.y = 0; + mvect.z = b->dir.z * momentum; + addvectors(&tman->tris[i].dir,&tman->tris[i].dir,&mvect); } } @@ -542,12 +572,14 @@ void createtrisfromball(triman* tman, vectorf *spherev, GLint *spherei, int ind_ * update position of each tri */ -void updatetris(triman *t) +static void updatetris(triman *t) { int b; GLfloat xd,zd; for (b=0;bnum_tri;b++) { + /* the exploded triangles disappear over time */ + if (rnd() < t->decay) { t->tris[b].gone = TRUE; } /* apply gravity */ t->tris[b].dir.y -= (0.1f * speed); /* apply movement */ @@ -615,7 +647,7 @@ void updatetris(triman *t) /* * free memory allocated by a tri manager */ -void freetris(triman *t) +static void freetris(triman *t) { if (!t) return; if (t->tris) free(t->tris); @@ -632,15 +664,20 @@ void freetris(triman *t) /* *load defaults in config structure */ -void setdefaultconfig(boxed_config *config) +static void setdefaultconfig(boxed_config *config) { 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_momentum = MAX(0.0f,MIN(1.0f,cfg_momentum)); + config->numballs = cfg_balls; config->textures = TRUE; config->transparent = FALSE; config->explosion = cfg_explosion; + config->decay = cfg_decay; + config->momentum = cfg_momentum; config->ballsize = cfg_ballsize; config->camspeed = 35.0f; } @@ -820,6 +857,7 @@ static void drawtriman(triman *t, int wire) glMaterialfv(GL_FRONT, GL_EMISSION,col); for (i=0; inum_tri; i++) { + if (t->tris[i].gone == TRUE) { continue; } pos = i*3; glPushMatrix(); glTranslatef(t->tris[i].loc.x,t->tris[i].loc.y,t->tris[i].loc.z); @@ -837,10 +875,10 @@ static void drawtriman(triman *t, int wire) /* * draw floor pattern */ -static void drawpattern(boxedstruct *boxed) +static void drawpattern(boxedstruct *gp) { - if (!boxed->gllists[GLL_PATTERN]) { - glNewList(boxed->listobjects + GLL_PATTERN, GL_COMPILE); + if (!gp->gllists[GLL_PATTERN]) { + glNewList(gp->listobjects + GLL_PATTERN, GL_COMPILE); glBegin(GL_LINE_STRIP); glVertex3f(-25.0f, 0.0f, 35.0f); @@ -883,9 +921,9 @@ static void drawpattern(boxedstruct *boxed) glEnd(); glEndList(); - boxed->gllists[GLL_PATTERN] = 1; + gp->gllists[GLL_PATTERN] = 1; } else { - glCallList(boxed->listobjects + GLL_PATTERN); + glCallList(gp->listobjects + GLL_PATTERN); } } @@ -1041,7 +1079,7 @@ static void draw(ModeInfo * mi) /* * new window size or exposure */ -void reshape_boxed(ModeInfo *mi, int width, int height) +ENTRYPOINT void reshape_boxed(ModeInfo *mi, int width, int height) { GLfloat h = (GLfloat) height / (GLfloat) width; @@ -1073,6 +1111,10 @@ pinit(ModeInfo * mi) /* Load configuration */ setdefaultconfig(&gp->config); + + /* give the decay parameter a better curve */ + if (gp->config.decay <= 0.8182) { gp->config.decay = gp->config.decay / 3; } + else { gp->config.decay = (gp->config.decay - 0.75) * 4; } bman = &gp->bman; @@ -1086,6 +1128,8 @@ pinit(ModeInfo * mi) for(i=0;inum_balls;i++) { gp->tman[i].explosion = (float) (((int)gp->config.explosion) / 15.0f ); + gp->tman[i].decay = gp->config.decay; + gp->tman[i].momentum = gp->config.momentum; gp->tman[i].vertices = NULL; gp->tman[i].normals = NULL; gp->tman[i].tris = NULL; @@ -1093,7 +1137,7 @@ pinit(ModeInfo * mi) bman->balls[i].loc.y *= rnd(); } - generatesphere(); + generatesphere(gp); if (!wire) { glEnable(GL_CULL_FACE); @@ -1145,7 +1189,7 @@ pinit(ModeInfo * mi) -void +ENTRYPOINT void init_boxed(ModeInfo * mi) { int screen = MI_SCREEN(mi); @@ -1176,7 +1220,7 @@ init_boxed(ModeInfo * mi) } -void +ENTRYPOINT void draw_boxed(ModeInfo * mi) { boxedstruct *gp = &boxed[MI_SCREEN(mi)]; @@ -1196,7 +1240,7 @@ draw_boxed(ModeInfo * mi) glXSwapBuffers(display, window); } -void +ENTRYPOINT void release_boxed(ModeInfo * mi) { int i; @@ -1231,6 +1275,8 @@ release_boxed(ModeInfo * mi) } +XSCREENSAVER_MODULE ("Boxed", boxed) + /*********************************************************/ #endif