X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fglx%2Fsierpinski3d.c;h=7bcefcf2c4a447837af5dcd5ce62389033292ecc;hb=6f5482d73adb0165c0130bb47d852644ab0c4869;hp=aee66bb12d77fcbb844f03f12ae413f400cbf1ac;hpb=2d04c4f22466851aedb6ed0f2919d148f726b889;p=xscreensaver diff --git a/hacks/glx/sierpinski3d.c b/hacks/glx/sierpinski3d.c index aee66bb1..7bcefcf2 100644 --- a/hacks/glx/sierpinski3d.c +++ b/hacks/glx/sierpinski3d.c @@ -27,28 +27,11 @@ static const char sccsid[] = "@(#)sierpinski3D.c 00.01 99/11/04 xlockmore"; */ #ifdef STANDALONE -# define PROGCLASS "Sierpinski3D" -# define HACK_INIT init_gasket -# define HACK_DRAW draw_gasket -# define HACK_RESHAPE reshape_gasket -# define HACK_HANDLE_EVENT gasket_handle_event -# define EVENT_MASK PointerMotionMask -# define gasket_opts xlockmore_opts - - -#define DEF_SPIN "True" -#define DEF_WANDER "True" -#define DEF_SPEED "150" -#define DEF_MAXDEPTH "5" - # define DEFAULTS "*delay: 20000 \n" \ "*showFPS: False \n" \ "*wireframe: False \n" \ - "*maxDepth: " DEF_MAXDEPTH "\n" \ - "*speed: " DEF_SPEED "\n" \ - "*spin: " DEF_SPIN "\n" \ - "*wander: " DEF_WANDER "\n" \ +# define refresh_gasket 0 # include "xlockmore.h" /* from the xscreensaver distribution */ #else /* !STANDALONE */ # include "xlock.h" /* from the xlockmore distribution */ @@ -56,7 +39,11 @@ static const char sccsid[] = "@(#)sierpinski3D.c 00.01 99/11/04 xlockmore"; #ifdef USE_GL -#include +#define DEF_SPIN "True" +#define DEF_WANDER "True" +#define DEF_SPEED "150" +#define DEF_MAX_DEPTH "5" + #include "rotator.h" #include "gltrackball.h" @@ -78,14 +65,14 @@ static XrmOptionDescRec opts[] = { }; static argtype vars[] = { - {&do_spin, "spin", "Spin", DEF_SPIN, t_Bool}, - {&do_wander, "wander", "Wander", DEF_WANDER, t_Bool}, - {&speed, "speed", "Speed", DEF_SPEED, t_Int}, - {&max_depth, "maxDepth", "MaxDepth", DEF_MAXDEPTH, t_Int}, + {&do_spin, "spin", "Spin", DEF_SPIN, t_Bool}, + {&do_wander, "wander", "Wander", DEF_WANDER, t_Bool}, + {&speed, "speed", "Speed", DEF_SPEED, t_Int}, + {&max_depth, "maxDepth", "MaxDepth", DEF_MAX_DEPTH, t_Int}, }; -ModeSpecOpt gasket_opts = {countof(opts), opts, countof(vars), vars, NULL}; +ENTRYPOINT ModeSpecOpt gasket_opts = {countof(opts), opts, countof(vars), vars, NULL}; #ifdef USE_MODULES ModStruct gasket_description = @@ -96,11 +83,9 @@ ModStruct gasket_description = #endif -typedef struct{ - GLfloat x; - GLfloat y; - GLfloat z; -} GL_VECTOR; +typedef struct { + double x,y,z; +} XYZ; typedef struct { GLuint gasket0, gasket1, gasket2, gasket3; @@ -119,13 +104,12 @@ typedef struct { int ccolor2; int ccolor3; + int tick; + } gasketstruct; static gasketstruct *gasket = NULL; -static GLfloat normals[4][3]; - - static void triangle (GLfloat x1, GLfloat y1, GLfloat z1, @@ -144,7 +128,9 @@ triangle (GLfloat x1, GLfloat y1, GLfloat z1, } static void -four_tetras (GL_VECTOR *outer, Bool wireframe_p, int countdown, int which, +four_tetras (gasketstruct *gp, + XYZ *outer, XYZ *normals, + Bool wireframe_p, int countdown, int which, int *countP) { if (countdown <= 0) @@ -152,7 +138,7 @@ four_tetras (GL_VECTOR *outer, Bool wireframe_p, int countdown, int which, (*countP)++; if (which == 0) { - glNormal3f (normals[0][0], normals[0][1], normals[0][2]); + glNormal3f (normals[0].x, normals[0].y, normals[0].z); triangle (outer[0].x, outer[0].y, outer[0].z, outer[1].x, outer[1].y, outer[1].z, outer[2].x, outer[2].y, outer[2].z, @@ -160,7 +146,7 @@ four_tetras (GL_VECTOR *outer, Bool wireframe_p, int countdown, int which, } else if (which == 1) { - glNormal3f (normals[1][0], normals[1][1], normals[1][2]); + glNormal3f (normals[1].x, normals[1].y, normals[1].z); triangle (outer[0].x, outer[0].y, outer[0].z, outer[3].x, outer[3].y, outer[3].z, outer[1].x, outer[1].y, outer[1].z, @@ -168,7 +154,7 @@ four_tetras (GL_VECTOR *outer, Bool wireframe_p, int countdown, int which, } else if (which == 2) { - glNormal3f (normals[2][0], normals[2][1], normals[2][2]); + glNormal3f (normals[2].x, normals[2].y, normals[2].z); triangle (outer[0].x, outer[0].y, outer[0].z, outer[2].x, outer[2].y, outer[2].z, outer[3].x, outer[3].y, outer[3].z, @@ -176,7 +162,7 @@ four_tetras (GL_VECTOR *outer, Bool wireframe_p, int countdown, int which, } else { - glNormal3f (normals[3][0], normals[3][1], normals[3][2]); + glNormal3f (normals[3].x, normals[3].y, normals[3].z); triangle (outer[1].x, outer[1].y, outer[1].z, outer[3].x, outer[3].y, outer[3].z, outer[2].x, outer[2].y, outer[2].z, @@ -191,8 +177,8 @@ four_tetras (GL_VECTOR *outer, Bool wireframe_p, int countdown, int which, # define M12 3 # define M13 4 # define M23 5 - GL_VECTOR inner[M23+1]; - GL_VECTOR corner[4]; + XYZ inner[M23+1]; + XYZ corner[4]; inner[M01].x = (outer[0].x + outer[1].x) / 2.0; inner[M01].y = (outer[0].y + outer[1].y) / 2.0; @@ -224,25 +210,25 @@ four_tetras (GL_VECTOR *outer, Bool wireframe_p, int countdown, int which, corner[1] = inner[M01]; corner[2] = inner[M02]; corner[3] = inner[M03]; - four_tetras (corner, wireframe_p, countdown, which, countP); + four_tetras (gp, corner, normals, wireframe_p, countdown, which, countP); corner[0] = inner[M01]; corner[1] = outer[1]; corner[2] = inner[M12]; corner[3] = inner[M13]; - four_tetras (corner, wireframe_p, countdown, which, countP); + four_tetras (gp, corner, normals, wireframe_p, countdown, which, countP); corner[0] = inner[M02]; corner[1] = inner[M12]; corner[2] = outer[2]; corner[3] = inner[M23]; - four_tetras (corner, wireframe_p, countdown, which, countP); + four_tetras (gp, corner, normals, wireframe_p, countdown, which, countP); corner[0] = inner[M03]; corner[1] = inner[M13]; corner[2] = inner[M23]; corner[3] = outer[3]; - four_tetras (corner, wireframe_p, countdown, which, countP); + four_tetras (gp, corner, normals, wireframe_p, countdown, which, countP); } } @@ -252,55 +238,27 @@ compile_gasket(ModeInfo *mi, int which) { Bool wireframe_p = MI_IS_WIREFRAME(mi); gasketstruct *gp = &gasket[MI_SCREEN(mi)]; - int count; - - GL_VECTOR vertex[5]; - - normals[0][0] = 0; - normals[0][1] = 0; - normals[0][2] = -sqrt(2.0 / 3.0); - - normals[1][0] = 0; - normals[1][1] = -sqrt(0.75); - normals[1][2] = sqrt(2.0 / 3.0) / 3.0; - - normals[2][0] = sqrt (0.5); - normals[2][1] = sqrt(0.75) / 2.0; - normals[2][2] = normals[1][2]; - - normals[3][0] = -normals[2][0]; - normals[3][1] = normals[2][1]; - normals[3][2] = normals[1][2]; - - - /* define verticies */ - vertex[0].x = 0.5; - vertex[0].y = -(1.0/3.0)*sqrt((2.0/3.0)); - vertex[0].z = -sqrt(3.0)/6.0; - - vertex[1].x = -0.5; - vertex[1].y = -(1.0/3.0)*sqrt((2.0/3.0)); - vertex[1].z = -sqrt(3.0)/6.0; - - vertex[2].x = 0.0; - vertex[2].y = (2.0/3.0)*sqrt((2.0/3.0)); - vertex[2].z = -sqrt(3.0)/6.0; - - vertex[3].x = 0.0; - vertex[3].y = 0.0; - vertex[3].z = sqrt(3.0)/3.0; - - vertex[4].x = 0.0; - vertex[4].y = 0.0; - vertex[4].z = 0.0; - - count = 0; - four_tetras (vertex, wireframe_p, + int count = 0; + XYZ vertex[5]; + XYZ normal[4]; + + vertex[0].x = -1; vertex[0].y = -1; vertex[0].z = -1; + vertex[1].x = 1; vertex[1].y = 1; vertex[1].z = -1; + vertex[2].x = 1; vertex[2].y = -1; vertex[2].z = 1; + vertex[3].x = -1; vertex[3].y = 1; vertex[3].z = 1; + vertex[4].x = 0; vertex[4].y = 0; vertex[4].z = 0; /* center */ + + normal[0].x = 1; normal[0].y = -1; normal[0].z = -1; + normal[1].x = -1; normal[1].y = 1; normal[1].z = -1; + normal[2].x = -1; normal[2].y = -1; normal[2].z = 1; + normal[3].x = 1; normal[3].y = 1; normal[3].z = 1; + + four_tetras (gp, vertex, normal, wireframe_p, (gp->current_depth < 0 ? -gp->current_depth : gp->current_depth), which, &count); - mi->polygon_count = count; + mi->polygon_count += count; } static void @@ -308,14 +266,14 @@ draw(ModeInfo *mi) { Bool wireframe_p = MI_IS_WIREFRAME(mi); gasketstruct *gp = &gasket[MI_SCREEN(mi)]; - static int tick = 999999; - static GLfloat pos[4] = {-4.0, 3.0, 10.0, 1.0}; - static float white[] = {1.0, 1.0, 1.0, 1.0}; - static float color0[] = {0.0, 0.0, 0.0, 1.0}; - static float color1[] = {0.0, 0.0, 0.0, 1.0}; - static float color2[] = {0.0, 0.0, 0.0, 1.0}; - static float color3[] = {0.0, 0.0, 0.0, 1.0}; + static const GLfloat pos[] = {-4.0, 3.0, 10.0, 1.0}; + static const GLfloat white[] = {1.0, 1.0, 1.0, 1.0}; + + GLfloat color0[] = {0.0, 0.0, 0.0, 1.0}; + GLfloat color1[] = {0.0, 0.0, 0.0, 1.0}; + GLfloat color2[] = {0.0, 0.0, 0.0, 1.0}; + GLfloat color3[] = {0.0, 0.0, 0.0, 1.0}; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -369,7 +327,10 @@ draw(ModeInfo *mi) (y - 0.5) * 10, (z - 0.5) * 20); + /* Do it twice because we don't track the device's orientation. */ + glRotatef( current_device_rotation(), 0, 0, 1); gltrackball_rotate (gp->trackball); + glRotatef(-current_device_rotation(), 0, 0, 1); get_rotation (gp->rot, &x, &y, &z, !gp->button_down_p); glRotatef (x * 360, 1.0, 0.0, 0.0); @@ -377,7 +338,7 @@ draw(ModeInfo *mi) glRotatef (z * 360, 0.0, 0.0, 1.0); } - glScalef( 8.0, 8.0, 8.0 ); + glScalef (4, 4, 4); glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color0); glCallList(gp->gasket0); @@ -391,9 +352,9 @@ draw(ModeInfo *mi) glPopMatrix(); - if (tick++ >= speed) + if (gp->tick++ >= speed) { - tick = 0; + gp->tick = 0; if (gp->current_depth >= max_depth) gp->current_depth = -max_depth; gp->current_depth++; @@ -414,12 +375,15 @@ draw(ModeInfo *mi) glNewList (gp->gasket2, GL_COMPILE); compile_gasket (mi, 2); glEndList(); glNewList (gp->gasket3, GL_COMPILE); compile_gasket (mi, 3); glEndList(); + mi->recursion_depth = (gp->current_depth > 0 + ? gp->current_depth + : -gp->current_depth); } } /* new window size or exposure */ -void +ENTRYPOINT void reshape_gasket(ModeInfo *mi, int width, int height) { GLfloat h = (GLfloat) height / (GLfloat) width; @@ -452,7 +416,7 @@ pinit(ModeInfo *mi) } -Bool +ENTRYPOINT Bool gasket_handle_event (ModeInfo *mi, XEvent *event) { gasketstruct *gp = &gasket[MI_SCREEN(mi)]; @@ -474,7 +438,9 @@ gasket_handle_event (ModeInfo *mi, XEvent *event) } else if (event->xany.type == ButtonPress && (event->xbutton.button == Button4 || - event->xbutton.button == Button5)) + event->xbutton.button == Button5 || + event->xbutton.button == Button6 || + event->xbutton.button == Button7)) { gltrackball_mousewheel (gp->trackball, event->xbutton.button, 10, !!event->xbutton.state); @@ -493,7 +459,7 @@ gasket_handle_event (ModeInfo *mi, XEvent *event) } -void +ENTRYPOINT void init_gasket(ModeInfo *mi) { int screen = MI_SCREEN(mi); @@ -530,6 +496,7 @@ init_gasket(ModeInfo *mi) gp->ccolor1 = gp->ncolors * 0.25; gp->ccolor2 = gp->ncolors * 0.5; gp->ccolor3 = gp->ncolors * 0.75; + gp->tick = 999999; if ((gp->glx_context = init_GL(mi)) != NULL) { @@ -542,7 +509,7 @@ init_gasket(ModeInfo *mi) } } -void +ENTRYPOINT void draw_gasket(ModeInfo * mi) { gasketstruct *gp = &gasket[MI_SCREEN(mi)]; @@ -553,6 +520,24 @@ draw_gasket(ModeInfo * mi) glDrawBuffer(GL_BACK); + /* 0 = 4 polygons + 1 = 16 polygons + 2 = 64 polygons + 3 = 256 polygons + 4 = 1,024 polygons + 5 = 4,096 polygons + 6 = 16,384 polygons + 7 = 65,536 polygons, 30 fps (3GHz Core 2 Duo, GeForce 8800 GS) + 8 = 262,144 polygons, 12 fps + 9 = 1,048,576 polygons, 4 fps + 10 = 4,194,304 polygons, 1 fps + 11 = 16,777,216 polygons, 0.3 fps + 12 = 67,108,864 polygons, OOM! + 13 = 268,435,456 polygons + 14 = 1,073,741,824 polygons, 31 bits + 15 = 4,294,967,296 polygons, 33 bits + 16 = 17,179,869,184 polygons, 35 bits + */ if (max_depth > 10) max_depth = 10; @@ -563,7 +548,7 @@ draw_gasket(ModeInfo * mi) glXSwapBuffers(display, window); } -void +ENTRYPOINT void release_gasket(ModeInfo * mi) { if (gasket != NULL) @@ -591,6 +576,7 @@ release_gasket(ModeInfo * mi) FreeAllGL(mi); } +XSCREENSAVER_MODULE_2 ("Sierpinski3D", sierpinski3d, gasket) /*********************************************************/