# define DEFAULTS "*delay: 20000 \n" \
"*showFPS: False \n" \
"*wireframe: False \n" \
+ "*suppressRotationAnimation: True\n" \
# define refresh_gasket 0
+# define release_gasket 0
# include "xlockmore.h" /* from the xscreensaver distribution */
#else /* !STANDALONE */
# include "xlock.h" /* from the xlockmore distribution */
#ifdef USE_MODULES
ModStruct gasket_description =
-{"gasket", "init_gasket", "draw_gasket", "release_gasket",
+{"gasket", "init_gasket", "draw_gasket", NULL,
"draw_gasket", "init_gasket", NULL, &gasket_opts,
1000, 1, 2, 1, 4, 1.0, "",
"Shows GL's Sierpinski gasket", 0, NULL};
#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;
int tick;
- GLfloat normals[4][3];
-
} gasketstruct;
static gasketstruct *gasket = NULL;
static void
four_tetras (gasketstruct *gp,
- GL_VECTOR *outer, Bool wireframe_p, int countdown, int which,
+ XYZ *outer, XYZ *normals,
+ Bool wireframe_p, int countdown, int which,
int *countP)
{
if (countdown <= 0)
(*countP)++;
if (which == 0)
{
- glNormal3f (gp->normals[0][0], gp->normals[0][1], gp->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,
}
else if (which == 1)
{
- glNormal3f (gp->normals[1][0], gp->normals[1][1], gp->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,
}
else if (which == 2)
{
- glNormal3f (gp->normals[2][0], gp->normals[2][1], gp->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,
}
else
{
- glNormal3f (gp->normals[3][0], gp->normals[3][1], gp->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,
# 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;
corner[1] = inner[M01];
corner[2] = inner[M02];
corner[3] = inner[M03];
- four_tetras (gp, 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 (gp, 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 (gp, 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 (gp, corner, wireframe_p, countdown, which, countP);
+ four_tetras (gp, corner, normals, wireframe_p, countdown, which, countP);
}
}
{
Bool wireframe_p = MI_IS_WIREFRAME(mi);
gasketstruct *gp = &gasket[MI_SCREEN(mi)];
- int count;
-
- GL_VECTOR vertex[5];
-
- gp->normals[0][0] = 0;
- gp->normals[0][1] = 0;
- gp->normals[0][2] = -sqrt(2.0 / 3.0);
-
- gp->normals[1][0] = 0;
- gp->normals[1][1] = -sqrt(0.75);
- gp->normals[1][2] = sqrt(2.0 / 3.0) / 3.0;
-
- gp->normals[2][0] = sqrt (0.5);
- gp->normals[2][1] = sqrt(0.75) / 2.0;
- gp->normals[2][2] = gp->normals[1][2];
-
- gp->normals[3][0] = -gp->normals[2][0];
- gp->normals[3][1] = gp->normals[2][1];
- gp->normals[3][2] = gp->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 (gp, 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
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);
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);
}
}
0.0, 0.0, 0.0,
0.0, 1.0, 0.0);
+# ifdef HAVE_MOBILE /* Keep it the same relative size when rotated. */
+ {
+ int o = (int) current_device_rotation();
+ if (o != 0 && o != 180 && o != -180)
+ glScalef (1/h, 1/h, 1/h);
+ }
+# endif
+
glClear(GL_COLOR_BUFFER_BIT);
}
{
gasketstruct *gp = &gasket[MI_SCREEN(mi)];
- if (event->xany.type == ButtonPress &&
- event->xbutton.button == Button1)
- {
- gp->button_down_p = True;
- gltrackball_start (gp->trackball,
- event->xbutton.x, event->xbutton.y,
- MI_WIDTH (mi), MI_HEIGHT (mi));
- return True;
- }
- else if (event->xany.type == ButtonRelease &&
- event->xbutton.button == Button1)
+ if (gltrackball_event_handler (event, gp->trackball,
+ MI_WIDTH (mi), MI_HEIGHT (mi),
+ &gp->button_down_p))
+ return True;
+ else if (event->xany.type == KeyPress)
{
- gp->button_down_p = False;
- return True;
- }
- else if (event->xany.type == ButtonPress &&
- (event->xbutton.button == Button4 ||
- event->xbutton.button == Button5 ||
- event->xbutton.button == Button6 ||
- event->xbutton.button == Button7))
- {
- gltrackball_mousewheel (gp->trackball, event->xbutton.button, 10,
- !!event->xbutton.state);
- return True;
+ KeySym keysym;
+ char c = 0;
+ XLookupString (&event->xkey, &c, 1, &keysym, 0);
+ if (c == '+' || c == '=' ||
+ keysym == XK_Up || keysym == XK_Right || keysym == XK_Next)
+ {
+ gp->tick = speed;
+ gp->current_depth += (gp->current_depth > 0 ? 1 : -1);
+ gp->current_depth--;
+ return True;
+ }
+ else if (c == '-' || c == '_' ||
+ keysym == XK_Down || keysym == XK_Left || keysym == XK_Prior)
+ {
+ gp->tick = speed;
+ gp->current_depth -= (gp->current_depth > 0 ? 1 : -1);
+ gp->current_depth--;
+ return True;
+ }
+ else if (screenhack_event_helper (MI_DISPLAY(mi), MI_WINDOW(mi), event))
+ goto DEF;
}
- else if (event->xany.type == MotionNotify &&
- gp->button_down_p)
+ else if (screenhack_event_helper (MI_DISPLAY(mi), MI_WINDOW(mi), event))
{
- gltrackball_track (gp->trackball,
- event->xmotion.x, event->xmotion.y,
- MI_WIDTH (mi), MI_HEIGHT (mi));
+ DEF:
+ gp->tick = speed;
return True;
}
}
+static void free_gasket(ModeInfo * mi);
+
+
ENTRYPOINT void
init_gasket(ModeInfo *mi)
{
int screen = MI_SCREEN(mi);
gasketstruct *gp;
- if (gasket == NULL)
- {
- if ((gasket = (gasketstruct *) calloc(MI_NUM_SCREENS(mi),
- sizeof (gasketstruct))) == NULL)
- return;
- }
+ MI_INIT (mi, gasket, free_gasket);
gp = &gasket[screen];
gp->window = MI_WINDOW(mi);
1.0,
do_wander ? wander_speed : 0,
True);
- gp->trackball = gltrackball_init ();
+ gp->trackball = gltrackball_init (True);
}
gp->ncolors = 255;
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;
}
ENTRYPOINT void
-release_gasket(ModeInfo * mi)
+free_gasket(ModeInfo * mi)
{
- if (gasket != NULL)
- {
- int screen;
-
- for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++)
- {
- gasketstruct *gp = &gasket[screen];
+ gasketstruct *gp = &gasket[MI_SCREEN(mi)];
- if (gp->glx_context)
- {
+ if (gp->glx_context)
+ {
/* Display lists MUST be freed while their glXContext is current. */
- glXMakeCurrent(MI_DISPLAY(mi), gp->window, *(gp->glx_context));
+ glXMakeCurrent(MI_DISPLAY(mi), gp->window, *(gp->glx_context));
- if (glIsList(gp->gasket0)) glDeleteLists(gp->gasket0, 1);
- if (glIsList(gp->gasket1)) glDeleteLists(gp->gasket1, 1);
- if (glIsList(gp->gasket2)) glDeleteLists(gp->gasket2, 1);
- if (glIsList(gp->gasket3)) glDeleteLists(gp->gasket3, 1);
- }
- }
- (void) free((void *) gasket);
- gasket = NULL;
+ if (glIsList(gp->gasket0)) glDeleteLists(gp->gasket0, 1);
+ if (glIsList(gp->gasket1)) glDeleteLists(gp->gasket1, 1);
+ if (glIsList(gp->gasket2)) glDeleteLists(gp->gasket2, 1);
+ if (glIsList(gp->gasket3)) glDeleteLists(gp->gasket3, 1);
}
- FreeAllGL(mi);
}
XSCREENSAVER_MODULE_2 ("Sierpinski3D", sierpinski3d, gasket)