X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fglx%2Fstairs.c;h=33e73ab03f9318af5d9bb557ce9b6ca1c8948e88;hb=6a1da724858673ac40aa13a9612340d8bed8c7b9;hp=9c9bf0f7d5222f2f52cbc50c084434debb52d6b0;hpb=df053bcb240bd8d82e3bebf48a9766a8728bca4b;p=xscreensaver diff --git a/hacks/glx/stairs.c b/hacks/glx/stairs.c index 9c9bf0f7..33e73ab0 100644 --- a/hacks/glx/stairs.c +++ b/hacks/glx/stairs.c @@ -33,9 +33,7 @@ static const char sccsid[] = "@(#)stairs.c 4.07 97/11/24 xlockmore"; * Since I'm not a native English speaker, my apologies for any grammatical * mistake. * - * My e-mail addresses are - * vianna@cat.cbpf.br - * and + * My e-mail address is * m-vianna@usa.net * * Marcelo F. Vianna (Jun-01-1997) @@ -66,9 +64,10 @@ static const char sccsid[] = "@(#)stairs.c 4.07 97/11/24 xlockmore"; # define PROGCLASS "Stairs" # define HACK_INIT init_stairs # define HACK_DRAW draw_stairs +# define HACK_RESHAPE reshape_stairs # define stairs_opts xlockmore_opts -# define DEFAULTS "*cycles: 1 \n" \ - "*delay: 200000 \n" \ +# define DEFAULTS "*delay: 20000 \n" \ + "*showFPS: False \n" \ "*wireframe: False \n" # include "xlockmore.h" /* from the xscreensaver distribution */ #else /* !STANDALONE */ @@ -110,6 +109,7 @@ typedef struct { Bool direction; int AreObjectsDefined[1]; int sphere_position; + int sphere_tick; GLXContext *glx_context; } stairsstruct; @@ -197,6 +197,8 @@ static float positions[] = #define NPOSITIONS ((sizeof positions) / (sizeof positions[0])) +#define SPHERE_TICKS 8 + static stairsstruct *stairs = NULL; static GLuint objects; @@ -315,21 +317,106 @@ draw_stairs_internal(ModeInfo * mi) glPushMatrix(); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialYellow); - glTranslatef((GLfloat) positions[sp->sphere_position], - (GLfloat) positions[sp->sphere_position + 1], - (GLfloat) positions[sp->sphere_position + 2]); + { + int pos = sp->sphere_position; + int ppos = sp->sphere_position - 3; + int npos = sp->sphere_position + 3; + GLfloat spx, spy, spz; + GLfloat dx, dy, dz; + int div; + + if (ppos < 0) ppos += NPOSITIONS; + if (npos >= NPOSITIONS) npos -= NPOSITIONS; + + if (sp->sphere_tick < 0) + { + dx = positions[ppos] - positions[pos]; + dy = positions[ppos+1] - positions[pos+1]; + dz = positions[ppos+2] - positions[pos+2]; + div = SPHERE_TICKS + sp->sphere_tick; + } + else + { + dx = positions[npos] - positions[pos]; + dy = positions[npos+1] - positions[pos+1]; + dz = positions[npos+2] - positions[ppos+2]; + div = SPHERE_TICKS - sp->sphere_tick; + } + + spx = positions[pos]; + spy = positions[pos+1]; + spz = positions[pos+2]; + if (div != 0) + { + spx += dx / div; + spy += dy / div; + spz += dz / div; + } + + + spy -= 0.5; /* move the bottom of the ball closer to the stairs */ + + +#ifdef DEBUG + fprintf(stderr, "%3d %3d %2.2f %2.2f %2.2f %2.2f %2.2f %2.2f\n", + sp->sphere_position, sp->sphere_tick, + dx, dy, dz, + spx, spy, spz); + + glBegin(GL_LINE_LOOP); /* path 1 */ + glVertex3f(positions[pos], positions[pos+1], positions[pos+2]); + glVertex3f(positions[npos], positions[npos+1], positions[npos+2]); + glEnd(); + + glBegin(GL_LINE_LOOP); /* path 2 */ + glVertex3f(positions[pos], positions[pos+1], positions[pos+2]); + glVertex3f(positions[ppos], positions[ppos+1], positions[ppos+2]); + glEnd(); + + glBegin(GL_LINE_LOOP); /* base origin */ + glVertex3f(positions[pos], positions[pos+1]-10, positions[pos+2]); + glVertex3f(positions[pos], positions[pos+1]+10, positions[pos+2]); + glEnd(); + + glBegin(GL_LINE_LOOP); /* base origin */ + glVertex3f(positions[pos]-10, positions[pos+1], positions[pos+2]); + glVertex3f(positions[pos]+10, positions[pos+1], positions[pos+2]); + glEnd(); + + glBegin(GL_LINE_LOOP); /* base origin */ + glVertex3f(positions[pos], positions[pos+1], positions[pos+2]-10); + glVertex3f(positions[pos], positions[pos+1], positions[pos+2]+10); + glEnd(); +#endif /* DEBUG */ + + glTranslatef(spx, spy, spz); + +#ifdef DEBUG /* ball origin */ + glBegin(GL_LINE_LOOP); glVertex3f(0,-2,0); glVertex3f(0,2,0); glEnd(); + glBegin(GL_LINE_LOOP); glVertex3f(-2,0,0); glVertex3f(2,0,0); glEnd(); + glBegin(GL_LINE_LOOP); glVertex3f(0,0,-2); glVertex3f(0,0,2); glEnd(); +#endif /* DEBUG */ + } + if (sp->sphere_position == 0) /* FUDGE soo its not so obvious */ mySphere(0.48); else mySphere(0.5); glPopMatrix(); - sp->sphere_position += 3; + + if (++sp->sphere_tick >= SPHERE_TICKS-1) + { + sp->sphere_tick = -(SPHERE_TICKS-2); + sp->sphere_position += 3; + sp->sphere_position += 3; + } + if (sp->sphere_position >= NPOSITIONS) sp->sphere_position = 0; } -static void -reshape(ModeInfo * mi, int width, int height) +void +reshape_stairs(ModeInfo * mi, int width, int height) { stairsstruct *sp = &stairs[MI_SCREEN(mi)]; @@ -353,6 +440,7 @@ reshape(ModeInfo * mi, int width, int height) static void pinit(void) { + int status; glClearDepth(1.0); glClearColor(0.0, 0.0, 0.0, 1.0); @@ -378,8 +466,21 @@ pinit(void) glEnable(GL_CULL_FACE); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - gluBuild2DMipmaps(GL_TEXTURE_2D, 3, WoodTextureWidth, WoodTextureHeight, - GL_RGB, GL_UNSIGNED_BYTE, WoodTextureData); + + clear_gl_error(); + status = gluBuild2DMipmaps(GL_TEXTURE_2D, 3, + WoodTextureWidth, WoodTextureHeight, + GL_RGB, GL_UNSIGNED_BYTE, WoodTextureData); + if (status) + { + const char *s = (char *) gluErrorString (status); + fprintf (stderr, "%s: error mipmapping %dx%d texture: %s\n", + progname, WoodTextureWidth, WoodTextureHeight, + (s ? s : "(unknown)")); + exit (1); + } + check_gl_error("mipmapping"); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); @@ -405,10 +506,11 @@ init_stairs(ModeInfo * mi) sp->step = 0.0; sp->direction = LRAND() & 1; sp->sphere_position = NRAND(NPOSITIONS / 3) * 3; + sp->sphere_tick = 0; if ((sp->glx_context = init_GL(mi)) != NULL) { - reshape(mi, MI_WIDTH(mi), MI_HEIGHT(mi)); + reshape_stairs(mi, MI_WIDTH(mi), MI_HEIGHT(mi)); glDrawBuffer(GL_BACK); if (!glIsList(objects)) objects = glGenLists(1); @@ -454,6 +556,7 @@ draw_stairs(ModeInfo * mi) glPopMatrix(); + if (mi->fps_p) do_fps (mi); glFlush(); glXSwapBuffers(display, window);