1 /* -*- Mode: C; tab-width: 4 -*- */
2 /* pipes --- 3D selfbuiding pipe system */
5 static const char sccsid[] = "@(#)pipes.c 4.07 97/11/24 xlockmore";
9 * Permission to use, copy, modify, and distribute this software and its
10 * documentation for any purpose and without fee is hereby granted,
11 * provided that the above copyright notice appear in all copies and that
12 * both that copyright notice and this permission notice appear in
13 * supporting documentation.
15 * This file is provided AS IS with no warranties of any kind. The author
16 * shall have no liability with respect to the infringement of copyrights,
17 * trade secrets or any patents by this file or any part thereof. In no
18 * event will the author be liable for any lost revenue or profits or
19 * other special, indirect and consequential damages.
21 * This program was inspired on a WindowsNT(R)'s screen saver. It was written
22 * from scratch and it was not based on any other source code.
24 * ==========================================================================
25 * The routine myElbow is derivated from the doughnut routine from the MesaGL
26 * library (more especifically the Mesaaux library) written by Brian Paul.
27 * ==========================================================================
29 * Thanks goes to Brian Paul for making it possible and inexpensive to use
32 * Since I'm not a native English speaker, my apologies for any grammatical
35 * My e-mail address is
37 * Marcelo F. Vianna (Apr-09-1997)
40 * 29-Apr-97: Factory equipment by Ed Mackey. Productive day today, eh?
41 * 29-Apr-97: Less tight turns Jeff Epler <jepler@inetnebr.com>
42 * 29-Apr-97: Efficiency speed-ups by Marcelo F. Vianna
46 # define DEFAULTS "*delay: 10000 \n" \
50 "*showFPS: False \n" \
53 # define refresh_pipes 0
54 # define pipes_handle_event 0
55 # include "xlockmore.h" /* from the xscreensaver distribution */
56 #else /* !STANDALONE */
57 # include "xlock.h" /* from the xlockmore distribution */
58 #endif /* !STANDALONE */
65 #define DEF_FACTORY "2"
66 #define DEF_FISHEYE "True"
67 #define DEF_TIGHTTURNS "False"
68 #define DEF_ROTATEPIPES "True"
69 #define DEF_DBUF "False"
73 static Bool fisheye, tightturns, rotatepipes;
76 static XrmOptionDescRec opts[] =
78 {"-factory", ".pipes.factory", XrmoptionSepArg, 0},
79 {"-fisheye", ".pipes.fisheye", XrmoptionNoArg, "on"},
80 {"+fisheye", ".pipes.fisheye", XrmoptionNoArg, "off"},
81 {"-tightturns", ".pipes.tightturns", XrmoptionNoArg, "on"},
82 {"+tightturns", ".pipes.tightturns", XrmoptionNoArg, "off"},
83 {"-rotatepipes", ".pipes.rotatepipes", XrmoptionNoArg, "on"},
84 {"+rotatepipes", ".pipes.rotatepipes", XrmoptionNoArg, "off"},
85 {"-db", ".pipes.doubleBuffer", XrmoptionNoArg, "on"},
86 {"+db", ".pipes.doubleBuffer", XrmoptionNoArg, "off"},
88 static argtype vars[] =
90 {&factory, "factory", "Factory", DEF_FACTORY, t_Int},
91 {&fisheye, "fisheye", "Fisheye", DEF_FISHEYE, t_Bool},
92 {&tightturns, "tightturns", "Tightturns", DEF_TIGHTTURNS, t_Bool},
93 {&rotatepipes, "rotatepipes", "Rotatepipes", DEF_ROTATEPIPES, t_Bool},
94 {&dbuf_p, "doubleBuffer", "DoubleBuffer", DEF_DBUF, t_Bool}
96 static OptionStruct desc[] =
98 {"-factory num", "how much extra equipment in pipes (0 for none)"},
99 {"-/+fisheye", "turn on/off zoomed-in view of pipes"},
100 {"-/+tightturns", "turn on/off tight turns"},
101 {"-/+rotatepipes", "turn on/off pipe system rotation per screenful"},
102 {"-/+db", "turn on/off double buffering"}
105 ENTRYPOINT ModeSpecOpt pipes_opts =
106 {sizeof opts / sizeof opts[0], opts, sizeof vars / sizeof vars[0], vars, desc};
109 ModStruct pipes_description =
110 {"pipes", "init_pipes", "draw_pipes", "release_pipes",
112 "change_pipes", NULL, &pipes_opts,
113 1000, 2, 5, 500, 4, 1.0, "",
114 "Shows a selfbuilding pipe system", 0, NULL};
118 #define Scale4Window 0.1
119 #define Scale4Iconic 0.07
121 #define one_third 0.3333333333333333333
133 #define DEFINEDCOLORS 7
134 #define elbowradius 0.5
136 /*************************************************************************/
142 int Cells[HCELLS][VCELLS][HCELLS];
143 int usedcolors[DEFINEDCOLORS];
150 int number_of_systems;
155 const float *system_color;
156 GLfloat initial_rotation;
157 GLuint valve, bolts, betweenbolts, elbowbolts, elbowcoins;
158 GLuint guagehead, guageface, guagedial, guageconnector, teapot;
161 GLXContext *glx_context;
164 extern struct lwo LWO_BigValve, LWO_PipeBetweenBolts, LWO_Bolts3D;
165 extern struct lwo LWO_GuageHead, LWO_GuageFace, LWO_GuageDial, LWO_GuageConnector;
166 extern struct lwo LWO_ElbowBolts, LWO_ElbowCoins;
168 static const float front_shininess[] = {60.0};
169 static const float front_specular[] = {0.7, 0.7, 0.7, 1.0};
170 static const float ambient0[] = {0.4, 0.4, 0.4, 1.0};
171 static const float diffuse0[] = {1.0, 1.0, 1.0, 1.0};
172 static const float ambient1[] = {0.2, 0.2, 0.2, 1.0};
173 static const float diffuse1[] = {0.5, 0.5, 0.5, 1.0};
174 static const float position0[] = {1.0, 1.0, 1.0, 0.0};
175 static const float position1[] = {-1.0, -1.0, 1.0, 0.0};
176 static const float lmodel_ambient[] = {0.5, 0.5, 0.5, 1.0};
177 static const float lmodel_twoside[] = {GL_TRUE};
179 static const float MaterialRed[] = {0.7, 0.0, 0.0, 1.0};
180 static const float MaterialGreen[] = {0.1, 0.5, 0.2, 1.0};
181 static const float MaterialBlue[] = {0.0, 0.0, 0.7, 1.0};
182 static const float MaterialCyan[] = {0.2, 0.5, 0.7, 1.0};
183 static const float MaterialYellow[] = {0.7, 0.7, 0.0, 1.0};
184 static const float MaterialMagenta[] = {0.6, 0.2, 0.5, 1.0};
185 static const float MaterialWhite[] = {0.7, 0.7, 0.7, 1.0};
186 static const float MaterialGray[] = {0.2, 0.2, 0.2, 1.0};
188 static pipesstruct *pipes = NULL;
192 MakeTube(ModeInfo *mi, int direction)
195 float SINan_3, COSan_3;
197 /*dirUP = 00000000 */
198 /*dirDOWN = 00000001 */
199 /*dirLEFT = 00000010 */
200 /*dirRIGHT = 00000011 */
201 /*dirNEAR = 00000100 */
202 /*dirFAR = 00000101 */
204 if (!(direction & 4)) {
205 glRotatef(90.0, (direction & 2) ? 0.0 : 1.0,
206 (direction & 2) ? 1.0 : 0.0, 0.0);
208 glBegin(GL_QUAD_STRIP);
209 for (an = 0.0; an <= 2.0 * M_PI; an += M_PI / 12.0) {
210 glNormal3f((COSan_3 = cos(an) / 3.0), (SINan_3 = sin(an) / 3.0), 0.0);
211 glVertex3f(COSan_3, SINan_3, one_third);
212 glVertex3f(COSan_3, SINan_3, -one_third);
219 mySphere(float radius)
221 GLUquadricObj *quadObj;
223 quadObj = gluNewQuadric();
224 gluQuadricDrawStyle(quadObj, (GLenum) GLU_FILL);
225 gluSphere(quadObj, radius, 16, 16);
226 gluDeleteQuadric(quadObj);
230 myElbow(ModeInfo * mi, int bolted)
237 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
240 GLfloat p0[3], p1[3], p2[3], p3[3];
241 GLfloat n0[3], n1[3], n2[3], n3[3];
242 GLfloat COSphi, COSphi1, COStheta, COStheta1;
243 GLfloat _SINtheta, _SINtheta1;
245 for (i = 0; i <= rings / 4; i++) {
246 GLfloat theta, theta1;
248 theta = (GLfloat) i *2.0 * M_PI / rings;
250 theta1 = (GLfloat) (i + 1) * 2.0 * M_PI / rings;
251 for (j = 0; j < nsides; j++) {
254 phi = (GLfloat) j *2.0 * M_PI / nsides;
256 phi1 = (GLfloat) (j + 1) * 2.0 * M_PI / nsides;
258 p0[0] = (COStheta = cos(theta)) * (R + r * (COSphi = cos(phi)));
259 p0[1] = (_SINtheta = -sin(theta)) * (R + r * COSphi);
261 p1[0] = (COStheta1 = cos(theta1)) * (R + r * COSphi);
262 p1[1] = (_SINtheta1 = -sin(theta1)) * (R + r * COSphi);
264 p2[0] = COStheta1 * (R + r * (COSphi1 = cos(phi1)));
265 p2[1] = _SINtheta1 * (R + r * COSphi1);
267 p3[0] = COStheta * (R + r * COSphi1);
268 p3[1] = _SINtheta * (R + r * COSphi1);
270 n0[0] = COStheta * COSphi;
271 n0[1] = _SINtheta * COSphi;
273 n1[0] = COStheta1 * COSphi;
274 n1[1] = _SINtheta1 * COSphi;
276 n2[0] = COStheta1 * COSphi1;
277 n2[1] = _SINtheta1 * COSphi1;
279 n3[0] = COStheta * COSphi1;
280 n3[1] = _SINtheta * COSphi1;
282 p0[2] = p1[2] = r * (n0[2] = n1[2] = sin(phi));
283 p2[2] = p3[2] = r * (n2[2] = n3[2] = sin(phi1));
299 if (factory > 0 && bolted) {
300 /* Bolt the elbow onto the pipe system */
303 glRotatef(90.0, 0.0, 0.0, -1.0);
304 glRotatef(90.0, 0.0, 1.0, 0.0);
305 glTranslatef(0.0, one_third, one_third);
306 glCallList(pp->elbowcoins);
307 mi->polygon_count += LWO_ElbowCoins.num_pnts/3;
308 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray);
309 glCallList(pp->elbowbolts);
310 mi->polygon_count += LWO_ElbowBolts.num_pnts/3;
311 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color);
322 FindNeighbors(ModeInfo * mi)
324 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
327 pp->directions[dirUP] = (!pp->Cells[pp->PX][pp->PY + 1][pp->PZ]) ? 1 : 0;
328 pp->ndirections += pp->directions[dirUP];
329 pp->directions[dirDOWN] = (!pp->Cells[pp->PX][pp->PY - 1][pp->PZ]) ? 1 : 0;
330 pp->ndirections += pp->directions[dirDOWN];
331 pp->directions[dirLEFT] = (!pp->Cells[pp->PX - 1][pp->PY][pp->PZ]) ? 1 : 0;
332 pp->ndirections += pp->directions[dirLEFT];
333 pp->directions[dirRIGHT] = (!pp->Cells[pp->PX + 1][pp->PY][pp->PZ]) ? 1 : 0;
334 pp->ndirections += pp->directions[dirRIGHT];
335 pp->directions[dirFAR] = (!pp->Cells[pp->PX][pp->PY][pp->PZ - 1]) ? 1 : 0;
336 pp->ndirections += pp->directions[dirFAR];
337 pp->directions[dirNEAR] = (!pp->Cells[pp->PX][pp->PY][pp->PZ + 1]) ? 1 : 0;
338 pp->ndirections += pp->directions[dirNEAR];
342 SelectNeighbor(ModeInfo * mi)
344 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
348 for (i = 0, j = 0; i < 6; i++) {
349 if (pp->directions[i]) {
355 return dirlist[NRAND(pp->ndirections)];
359 MakeValve(ModeInfo * mi, int newdir)
361 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
363 /* There is a glPopMatrix() right after this subroutine returns. */
367 glRotatef(90.0, 1.0, 0.0, 0.0);
368 glRotatef(NRAND(3) * 90.0, 0.0, 0.0, 1.0);
372 glRotatef(90.0, 0.0, -1.0, 0.0);
373 glRotatef((NRAND(3) * 90.0) - 90.0, 0.0, 0.0, 1.0);
377 glRotatef(NRAND(4) * 90.0, 0.0, 0.0, 1.0);
381 glCallList(pp->betweenbolts);
382 mi->polygon_count += LWO_PipeBetweenBolts.num_pnts/3;
383 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray);
384 glCallList(pp->bolts);
385 mi->polygon_count += LWO_Bolts3D.num_pnts/3;
386 if (!MI_IS_MONO(mi)) {
387 if (pp->system_color == MaterialRed) {
388 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, NRAND(2) ? MaterialYellow : MaterialBlue);
389 } else if (pp->system_color == MaterialBlue) {
390 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, NRAND(2) ? MaterialRed : MaterialYellow);
391 } else if (pp->system_color == MaterialYellow) {
392 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, NRAND(2) ? MaterialBlue : MaterialRed);
394 switch ((NRAND(3))) {
396 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialRed);
399 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialBlue);
402 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialYellow);
406 glRotatef((GLfloat) (NRAND(90)), 1.0, 0.0, 0.0);
407 glCallList(pp->valve);
408 mi->polygon_count += LWO_BigValve.num_pnts/3;
409 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color);
414 MakeGuage(ModeInfo * mi, int newdir)
416 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
418 /* Can't have a guage on a vertical pipe. */
419 if ((newdir == dirUP) || (newdir == dirDOWN))
422 /* Is there space above this pipe for a guage? */
423 if (!pp->directions[dirUP])
426 /* Yes! Mark the space as used. */
427 pp->Cells[pp->PX][pp->PY + 1][pp->PZ] = 1;
431 if ((newdir == dirLEFT) || (newdir == dirRIGHT))
432 glRotatef(90.0, 0.0, 1.0, 0.0);
433 glCallList(pp->betweenbolts);
434 mi->polygon_count += LWO_PipeBetweenBolts.num_pnts/3;
435 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray);
436 glCallList(pp->bolts);
437 mi->polygon_count += LWO_Bolts3D.num_pnts/3;
440 glCallList(pp->guageconnector);
441 mi->polygon_count += LWO_GuageConnector.num_pnts/3;
443 glTranslatef(0.0, 1.33333, 0.0);
444 /* Do not change the above to 1 + ONE_THIRD, because */
445 /* the object really is centered on 1.3333300000. */
446 glRotatef(NRAND(270) + 45.0, 0.0, 0.0, -1.0);
447 /* Random rotation for the dial. I love it. */
448 glCallList(pp->guagedial);
449 mi->polygon_count += LWO_GuageDial.num_pnts/3;
452 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color);
453 glCallList(pp->guagehead);
454 mi->polygon_count += LWO_GuageHead.num_pnts/3;
456 /* GuageFace is drawn last, in case of low-res depth buffers. */
457 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialWhite);
458 glCallList(pp->guageface);
459 mi->polygon_count += LWO_GuageFace.num_pnts/3;
461 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color);
469 build_teapot(ModeInfo *mi)
471 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
472 GLuint list = glGenLists(1);
474 glNewList(list, GL_COMPILE);
475 pp->teapot_polys = unit_teapot (12, MI_IS_WIREFRAME(mi));
482 MakeTeapot(ModeInfo * mi, int newdir)
484 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
489 glRotatef(90.0, 1.0, 0.0, 0.0);
490 glRotatef(NRAND(3) * 90.0, 0.0, 0.0, 1.0);
494 glRotatef(90.0, 0.0, -1.0, 0.0);
495 glRotatef((NRAND(3) * 90.0) - 90.0, 0.0, 0.0, 1.0);
499 glRotatef(NRAND(4) * 90.0, 0.0, 0.0, 1.0);
503 glCallList(pp->teapot);
504 mi->polygon_count += pp->teapot_polys;
510 MakeShape(ModeInfo * mi, int newdir)
514 if (!MakeGuage(mi, newdir))
515 MakeTube(mi, newdir);
517 MakeValve(mi, newdir);
519 MakeTeapot(mi,newdir);
524 pinit(ModeInfo * mi, int zera)
526 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
530 mi->polygon_count = 0;
533 glClearColor(0.0, 0.0, 0.0, 1.0);
534 glColor3f(1.0, 1.0, 1.0);
536 glLightfv(GL_LIGHT0, GL_AMBIENT, ambient0);
537 glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse0);
538 glLightfv(GL_LIGHT0, GL_POSITION, position0);
539 glLightfv(GL_LIGHT1, GL_AMBIENT, ambient1);
540 glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse1);
541 glLightfv(GL_LIGHT1, GL_POSITION, position1);
542 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
543 glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside);
544 glEnable(GL_LIGHTING);
547 glEnable(GL_DEPTH_TEST);
548 glEnable(GL_NORMALIZE);
549 glEnable(GL_CULL_FACE);
551 glShadeModel(GL_SMOOTH);
552 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, front_shininess);
553 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, front_specular);
556 pp->system_number = 1;
557 glDrawBuffer(dbuf_p ? GL_BACK : GL_FRONT);
558 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
559 (void) memset(pp->Cells, 0, sizeof (pp->Cells));
560 for (X = 0; X < HCELLS; X++) {
561 for (Y = 0; Y < VCELLS; Y++) {
562 pp->Cells[X][Y][0] = 1;
563 pp->Cells[X][Y][HCELLS - 1] = 1;
564 pp->Cells[0][Y][X] = 1;
565 pp->Cells[HCELLS - 1][Y][X] = 1;
568 for (X = 0; X < HCELLS; X++) {
569 for (Z = 0; Z < HCELLS; Z++) {
570 pp->Cells[X][0][Z] = 1;
571 pp->Cells[X][VCELLS - 1][Z] = 1;
574 (void) memset(pp->usedcolors, 0, sizeof (pp->usedcolors));
575 if ((pp->initial_rotation += 10.0) > 45.0) {
576 pp->initial_rotation -= 90.0;
582 if (!MI_IS_MONO(mi)) {
583 int collist[DEFINEDCOLORS];
584 int i, j, lower = 1000;
586 /* Avoid repeating colors on the same screen unless necessary */
587 for (i = 0; i < DEFINEDCOLORS; i++) {
588 if (lower > pp->usedcolors[i])
589 lower = pp->usedcolors[i];
591 for (i = 0, j = 0; i < DEFINEDCOLORS; i++) {
592 if (pp->usedcolors[i] == lower) {
597 i = collist[NRAND(j)];
601 pp->system_color = MaterialRed;
604 pp->system_color = MaterialGreen;
607 pp->system_color = MaterialBlue;
610 pp->system_color = MaterialCyan;
613 pp->system_color = MaterialYellow;
616 pp->system_color = MaterialMagenta;
619 pp->system_color = MaterialWhite;
623 pp->system_color = MaterialGray;
627 pp->PX = NRAND((HCELLS - 1)) + 1;
628 pp->PY = NRAND((VCELLS - 1)) + 1;
629 pp->PZ = NRAND((HCELLS - 1)) + 1;
630 } while (pp->Cells[pp->PX][pp->PY][pp->PZ] ||
631 (pp->Cells[pp->PX + 1][pp->PY][pp->PZ] && pp->Cells[pp->PX - 1][pp->PY][pp->PZ] &&
632 pp->Cells[pp->PX][pp->PY + 1][pp->PZ] && pp->Cells[pp->PX][pp->PY - 1][pp->PZ] &&
633 pp->Cells[pp->PX][pp->PY][pp->PZ + 1] && pp->Cells[pp->PX][pp->PY][pp->PZ - 1]));
634 pp->Cells[pp->PX][pp->PY][pp->PZ] = 1;
635 pp->olddir = dirNone;
639 pp->nowdir = SelectNeighbor(mi);
643 reshape_pipes(ModeInfo * mi, int width, int height)
645 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
648 glViewport(0, 0, pp->WindW = (GLint) width, pp->WindH = (GLint) height);
649 glMatrixMode(GL_PROJECTION);
651 /*glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 15.0); */
652 gluPerspective(65.0, (GLfloat) width / (GLfloat) height, 0.1, 20.0);
653 glMatrixMode(GL_MODELVIEW);
655 glClear(GL_COLOR_BUFFER_BIT);
659 init_pipes (ModeInfo * mi)
661 int screen = MI_SCREEN(mi);
665 if ((pipes = (pipesstruct *) calloc(MI_NUM_SCREENS(mi),
666 sizeof (pipesstruct))) == NULL)
671 pp->window = MI_WINDOW(mi);
672 if ((pp->glx_context = init_GL(mi)) != NULL) {
674 reshape_pipes(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
676 pp->initial_rotation = NRAND(180); /* jwz */
678 pp->initial_rotation = -10.0;
682 pp->valve = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_BigValve);
683 pp->bolts = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_Bolts3D);
684 pp->betweenbolts = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_PipeBetweenBolts);
686 pp->elbowbolts = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_ElbowBolts);
687 pp->elbowcoins = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_ElbowCoins);
689 pp->guagehead = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_GuageHead);
690 pp->guageface = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_GuageFace);
691 pp->guagedial = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_GuageDial);
692 pp->guageconnector = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_GuageConnector);
693 pp->teapot = build_teapot(mi);
695 /* else they are all 0, thanks to calloc(). */
697 if (MI_COUNT(mi) < 1 || MI_COUNT(mi) > NofSysTypes + 1) {
698 pp->system_type = NRAND(NofSysTypes) + 1;
700 pp->system_type = MI_COUNT(mi);
703 if (MI_CYCLES(mi) > 0 && MI_CYCLES(mi) < 11) {
704 pp->number_of_systems = MI_CYCLES(mi);
706 pp->number_of_systems = 5;
709 if (MI_SIZE(mi) < 10) {
710 pp->system_length = 10;
711 } else if (MI_SIZE(mi) > 1000) {
712 pp->system_length = 1000;
714 pp->system_length = MI_SIZE(mi);
722 draw_pipes (ModeInfo * mi)
724 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
726 Display *display = MI_DISPLAY(mi);
727 Window window = MI_WINDOW(mi);
732 if (!pp->glx_context)
735 glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(pp->glx_context));
739 /* Would be nice to fade to black here, by drawing successive quads
740 over the whole scene with gamma. */
748 glTranslatef(0.0, 0.0, fisheye ? -3.8 : -4.8);
750 glRotatef(pp->initial_rotation, 0.0, 1.0, 0.0);
752 if (!MI_IS_ICONIC(mi)) {
753 /* Width/height ratio handled by gluPerspective() now. */
754 glScalef(Scale4Window, Scale4Window, Scale4Window);
756 glScalef(Scale4Iconic, Scale4Iconic, Scale4Iconic);
761 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color);
763 /* If it's the begining of a system, draw a sphere */
764 if (pp->olddir == dirNone) {
766 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0);
770 /* Check for stop conditions */
771 if (pp->ndirections == 0 || pp->counter > pp->system_length) {
773 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0);
774 /* Finish the system with another sphere */
779 /* If the maximum number of system was drawn, restart (clearing the screen), */
780 /* else start a new system. */
781 if (++pp->system_number > pp->number_of_systems) {
782 /* pause doing nothing for N seconds before clearing the screen. */
784 pp->reset = secs * 1000000 / (MI_PAUSE(mi) ? MI_PAUSE(mi) : 100);
795 /* Do will the direction change? if so, determine the new one */
797 if (!pp->directions[newdir]) { /* cannot proceed in the current direction */
798 newdir = SelectNeighbor(mi);
801 /* random change (20% chance) */
802 if ((pp->counter > 1) && (NRAND(100) < 20)) {
803 newdir = SelectNeighbor(mi);
806 /* Chance to turn increases after each length of pipe drawn */
807 if ((pp->counter > 1) && NRAND(50) < NRAND(pp->turncounter + 1)) {
808 newdir = SelectNeighbor(mi);
814 /* Has the direction changed? */
815 if (newdir == pp->nowdir) {
816 /* If not, draw the cell's center pipe */
818 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0);
819 /* Chance of factory shape here, if enabled. */
820 if ((pp->counter > 1) && (NRAND(100) < factory)) {
821 MakeShape(mi, newdir);
823 MakeTube(mi, newdir);
827 /* If so, draw the cell's center elbow/sphere */
828 int sysT = pp->system_type;
830 if (sysT == NofSysTypes + 1) {
831 sysT = ((pp->system_number - 1) % NofSysTypes) + 1;
837 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0);
838 mySphere(elbowradius);
842 switch (pp->nowdir) {
846 glTranslatef((pp->PX - 16) / 3.0 * 4.0 - (one_third), (pp->PY - 12) / 3.0 * 4.0 - (one_third), (pp->PZ - 16) / 3.0 * 4.0);
847 glRotatef(180.0, 1.0, 0.0, 0.0);
850 glTranslatef((pp->PX - 16) / 3.0 * 4.0 + (one_third), (pp->PY - 12) / 3.0 * 4.0 - (one_third), (pp->PZ - 16) / 3.0 * 4.0);
851 glRotatef(180.0, 1.0, 0.0, 0.0);
852 glRotatef(180.0, 0.0, 1.0, 0.0);
855 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0 - (one_third), (pp->PZ - 16) / 3.0 * 4.0 - (one_third));
856 glRotatef(90.0, 0.0, 1.0, 0.0);
857 glRotatef(180.0, 0.0, 0.0, 1.0);
860 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0 - (one_third), (pp->PZ - 16) / 3.0 * 4.0 + (one_third));
861 glRotatef(90.0, 0.0, 1.0, 0.0);
862 glRotatef(180.0, 1.0, 0.0, 0.0);
869 glTranslatef((pp->PX - 16) / 3.0 * 4.0 - (one_third), (pp->PY - 12) / 3.0 * 4.0 + (one_third), (pp->PZ - 16) / 3.0 * 4.0);
872 glTranslatef((pp->PX - 16) / 3.0 * 4.0 + (one_third), (pp->PY - 12) / 3.0 * 4.0 + (one_third), (pp->PZ - 16) / 3.0 * 4.0);
873 glRotatef(180.0, 0.0, 1.0, 0.0);
876 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0 + (one_third), (pp->PZ - 16) / 3.0 * 4.0 - (one_third));
877 glRotatef(270.0, 0.0, 1.0, 0.0);
880 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0 + (one_third), (pp->PZ - 16) / 3.0 * 4.0 + (one_third));
881 glRotatef(90.0, 0.0, 1.0, 0.0);
888 glTranslatef((pp->PX - 16) / 3.0 * 4.0 + (one_third), (pp->PY - 12) / 3.0 * 4.0 + (one_third), (pp->PZ - 16) / 3.0 * 4.0);
889 glRotatef(180.0, 0.0, 1.0, 0.0);
892 glTranslatef((pp->PX - 16) / 3.0 * 4.0 + (one_third), (pp->PY - 12) / 3.0 * 4.0 - (one_third), (pp->PZ - 16) / 3.0 * 4.0);
893 glRotatef(180.0, 1.0, 0.0, 0.0);
894 glRotatef(180.0, 0.0, 1.0, 0.0);
897 glTranslatef((pp->PX - 16) / 3.0 * 4.0 + (one_third), (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0 - (one_third));
898 glRotatef(270.0, 1.0, 0.0, 0.0);
899 glRotatef(180.0, 0.0, 1.0, 0.0);
902 glTranslatef((pp->PX - 16) / 3.0 * 4.0 + (one_third), (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0 + (one_third));
903 glRotatef(270.0, 1.0, 0.0, 0.0);
904 glRotatef(180.0, 0.0, 0.0, 1.0);
911 glTranslatef((pp->PX - 16) / 3.0 * 4.0 - (one_third), (pp->PY - 12) / 3.0 * 4.0 + (one_third), (pp->PZ - 16) / 3.0 * 4.0);
914 glTranslatef((pp->PX - 16) / 3.0 * 4.0 - (one_third), (pp->PY - 12) / 3.0 * 4.0 - (one_third), (pp->PZ - 16) / 3.0 * 4.0);
915 glRotatef(180.0, 1.0, 0.0, 0.0);
918 glTranslatef((pp->PX - 16) / 3.0 * 4.0 - (one_third), (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0 - (one_third));
919 glRotatef(270.0, 1.0, 0.0, 0.0);
922 glTranslatef((pp->PX - 16) / 3.0 * 4.0 - (one_third), (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0 + (one_third));
923 glRotatef(90.0, 1.0, 0.0, 0.0);
930 glTranslatef((pp->PX - 16) / 3.0 * 4.0 - (one_third), (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0 - (one_third));
931 glRotatef(270.0, 1.0, 0.0, 0.0);
934 glTranslatef((pp->PX - 16) / 3.0 * 4.0 + (one_third), (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0 - (one_third));
935 glRotatef(270.0, 1.0, 0.0, 0.0);
936 glRotatef(180.0, 0.0, 1.0, 0.0);
939 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0 + (one_third), (pp->PZ - 16) / 3.0 * 4.0 - (one_third));
940 glRotatef(270.0, 0.0, 1.0, 0.0);
943 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0 - (one_third), (pp->PZ - 16) / 3.0 * 4.0 - (one_third));
944 glRotatef(90.0, 0.0, 1.0, 0.0);
945 glRotatef(180.0, 0.0, 0.0, 1.0);
952 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0 + (one_third), (pp->PZ - 16) / 3.0 * 4.0 + (one_third));
953 glRotatef(90.0, 0.0, 1.0, 0.0);
956 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0 - (one_third), (pp->PZ - 16) / 3.0 * 4.0 + (one_third));
957 glRotatef(90.0, 0.0, 1.0, 0.0);
958 glRotatef(180.0, 1.0, 0.0, 0.0);
961 glTranslatef((pp->PX - 16) / 3.0 * 4.0 - (one_third), (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0 + (one_third));
962 glRotatef(90.0, 1.0, 0.0, 0.0);
965 glTranslatef((pp->PX - 16) / 3.0 * 4.0 + (one_third), (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0 + (one_third));
966 glRotatef(270.0, 1.0, 0.0, 0.0);
967 glRotatef(180.0, 0.0, 0.0, 1.0);
972 myElbow(mi, (sysT == 2));
981 pp->olddir = pp->nowdir;
983 switch (pp->nowdir) {
1003 pp->Cells[pp->PX][pp->PY][pp->PZ] = 1;
1005 /* Cells'face pipe */
1006 glTranslatef(((pp->PX + OPX) / 2.0 - 16) / 3.0 * 4.0, ((pp->PY + OPY) / 2.0 - 12) / 3.0 * 4.0, ((pp->PZ + OPZ) / 2.0 - 16) / 3.0 * 4.0);
1007 MakeTube(mi, newdir);
1013 if (mi->fps_p) do_fps (mi);
1016 glXSwapBuffers(display, window);
1021 change_pipes (ModeInfo * mi)
1023 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
1025 if (!pp->glx_context)
1028 glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(pp->glx_context));
1031 #endif /* !STANDALONE */
1035 release_pipes (ModeInfo * mi)
1037 if (pipes != NULL) {
1040 for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) {
1041 pipesstruct *pp = &pipes[screen];
1043 if (pp->glx_context) {
1045 /* Display lists MUST be freed while their glXContext is current. */
1046 glXMakeCurrent(MI_DISPLAY(mi), pp->window, *(pp->glx_context));
1049 glDeleteLists(pp->valve, 1);
1051 glDeleteLists(pp->bolts, 1);
1052 if (pp->betweenbolts)
1053 glDeleteLists(pp->betweenbolts, 1);
1056 glDeleteLists(pp->elbowbolts, 1);
1058 glDeleteLists(pp->elbowcoins, 1);
1061 glDeleteLists(pp->guagehead, 1);
1063 glDeleteLists(pp->guageface, 1);
1065 glDeleteLists(pp->guagedial, 1);
1066 if (pp->guageconnector)
1067 glDeleteLists(pp->guageconnector, 1);
1069 glDeleteLists(pp->teapot, 1);
1073 (void) free((void *) pipes);
1079 XSCREENSAVER_MODULE ("Pipes", pipes)